GraphQL 介紹

The power of Graphql
The power of GraphQL, from https://www.graphql.com/

專案目錄架構

db\  資料庫目錄
   Dockfile
docker-compose.yml

資料庫(db目錄下)

  • Dockfile
FROM postgres:10
COPY ./setup-db.sh /docker-entrypoint-initdb.d/setup-db.sh
  • serup-db.sh
#!/bin/bash
set -e

POSTGRES="psql --username ${POSTGRES_USER}"
DATABASES=($POSTGRES_DEV_DB $POSTGRES_TEST_DB $POSTGRES_PROD_DB)

for i in ${DATABASES[@]}; do
  echo "Creating database: ${i}"
  psql -U postgres -tc "SELECT 1 FROM pg_database WHERE datname = '${i}'" | grep -q 1 || psql -U postgres -c "CREATE DATABASE \"${i}\""
done

建立測試環境

  • Dockerfile
FROM mhart/alpine-node:9
RUN mkdir www/
WORKDIR www/
ADD . .
RUN npm install && npm run build
CMD npm run start
  • docker-compose.yml
version: “3”
services:
  api:
    build: ./api
    image: crypto-dca-api:latest
    container_name: crypto-dca-api
    env_file: config/.env
    environment:
      - NODE_ENV=production
    ports:
      - 8088:8088
  db:
    build: ./db
    image: crypto-dca-db:latest
    container_name: crypto-dca-db
    env_file: config/.env
    volumes:
      - crypto-dca-db:/var/lib/postgresql/data
    ports:
      - 5432:5432
volumes:
  crypto-dca-db:
    driver: local
  • 執行
docker-compose up -d

參考資訊