diff --git a/.dockerignore b/.dockerignore index e24bcb7..9b6194b 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,13 +1,49 @@ +Procfile +makefile + +# git .git +.gitattributes +.gitignore +.github + +# docker +docker-compose.yml +docker-compose.* +Dockerfile .dockerignore +environment/ + +# environment and secretsss .env -.vscode + +# Common +README.md +CHANGELOG.md + +# logs +logs +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* +/log/* +!/log/.keep + +# tmp +/tmp/* +!/tmp/.keep +*.swp +*~ +.DS_Store + +# Dependencies and dependency managers node_modules/ -bundle/ -tmp/ -environment/ -docker-compose* -Dockerfile -Procfile -makefile -.DS_Store \ No newline at end of file +# Ignore yarn files +/yarn-error.log +yarn-debug.log* +.yarn-integrity + +# ides +.idea +.vscode diff --git a/.github/workflows/ghcr.yml b/.github/workflows/ghcr.yml new file mode 100644 index 0000000..0d745b3 --- /dev/null +++ b/.github/workflows/ghcr.yml @@ -0,0 +1,28 @@ +name: Deploy Images to GHCR + +# temporarily run on push for this branch +on: [push] +# on: +# push: +# branches: +# - main +# workflow_dispatch: + +jobs: + push-store-image: + runs-on: ubuntu-latest + steps: + - name: "Checkout GitHub Action" + uses: actions/checkout@main + + - name: "Login to GitHub Container Registry" + uses: docker/login-action@v1 + with: + registry: ghcr.io + username: ${{github.actor}} + password: ${{secrets.GITHUB_TOKEN}} + + - name: "Build Inventory Image" + run: | + docker build . --tag ghcr.io/wearefuturegov/outpost-api-service:latest + docker push ghcr.io/wearefuturegov/outpost-api-service:latest diff --git a/docker-compose.development.yml b/docker-compose.development.yml deleted file mode 100644 index 99e2a93..0000000 --- a/docker-compose.development.yml +++ /dev/null @@ -1,48 +0,0 @@ -version: "3.7" -services: - outpost-api-dev: - stdin_open: true - image: "outpost-api:development" - container_name: outpost-api-dev - restart: unless-stopped - healthcheck: - test: ["CMD", "curl", "-f", "http://localhost:3001/health"] - interval: 1m30s - timeout: 10s - retries: 3 - start_period: 40s - depends_on: - - mongo - build: - target: development - ports: - - 3001:3001 - volumes: - - ./:/usr/src/app:cached - environment: - NODE_ENV: development - DB_URI: mongodb://mongo:27017/outpost_api_development - networks: - - outpost_api_dev_external_network - - outpost_api_dev_internal_network - mongo: - image: mongo:6 - container_name: outpost-api-mongo - restart: unless-stopped - ports: - - 27017:27017 - volumes: - - outpost-api-dev-mongo-volume:/data/db - - ./environment/containers/mongo/setup-mongodb-development.js:/docker-entrypoint-initdb.d/mongo-init.js:ro - environment: - MONGO_INITDB_DATABASE: outpost_api_development - networks: - - outpost_api_dev_external_network - -volumes: - outpost-api-dev-mongo-volume: - -networks: - outpost_api_dev_external_network: - outpost_api_dev_internal_network: - internal: true diff --git a/docker-compose.production.yml b/docker-compose.production.yml new file mode 100644 index 0000000..ab9dc13 --- /dev/null +++ b/docker-compose.production.yml @@ -0,0 +1,46 @@ +version: "3.7" +services: + outpost-api: + image: "outpost-api:production" + container_name: outpost-api + restart: unless-stopped + healthcheck: + test: ["CMD", "curl", "-f", "http://localhost:3001/health"] + interval: 1m30s + timeout: 10s + retries: 3 + start_period: 40s + depends_on: + - mongo + build: + target: production + ports: + - 3001:3001 + volumes: + - ./:/usr/src/app + environment: + NODE_ENV: production + DB_URI: mongodb://mongo:27017/outpost_api + networks: + - outpost_api_internal_network + - outpost_api_external_network + + mongo: + image: mongo:6 + container_name: outpost-api-mongo + restart: unless-stopped + ports: + - 27017:27017 + volumes: + - outpost-api-mongo-volume:/data/db + - ./environment/containers/mongo/setup-mongodb-production.js:/docker-entrypoint-initdb.d/mongo-init.js:ro + networks: + - outpost_api_external_network + +volumes: + outpost-api-mongo-volume: + +networks: + outpost_api_external_network: + outpost_api_internal_network: + internal: true diff --git a/docker-compose.yml b/docker-compose.yml index ab9dc13..99e2a93 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,8 +1,9 @@ version: "3.7" services: - outpost-api: - image: "outpost-api:production" - container_name: outpost-api + outpost-api-dev: + stdin_open: true + image: "outpost-api:development" + container_name: outpost-api-dev restart: unless-stopped healthcheck: test: ["CMD", "curl", "-f", "http://localhost:3001/health"] @@ -13,18 +14,17 @@ services: depends_on: - mongo build: - target: production + target: development ports: - 3001:3001 volumes: - - ./:/usr/src/app + - ./:/usr/src/app:cached environment: - NODE_ENV: production - DB_URI: mongodb://mongo:27017/outpost_api + NODE_ENV: development + DB_URI: mongodb://mongo:27017/outpost_api_development networks: - - outpost_api_internal_network - - outpost_api_external_network - + - outpost_api_dev_external_network + - outpost_api_dev_internal_network mongo: image: mongo:6 container_name: outpost-api-mongo @@ -32,15 +32,17 @@ services: ports: - 27017:27017 volumes: - - outpost-api-mongo-volume:/data/db - - ./environment/containers/mongo/setup-mongodb-production.js:/docker-entrypoint-initdb.d/mongo-init.js:ro + - outpost-api-dev-mongo-volume:/data/db + - ./environment/containers/mongo/setup-mongodb-development.js:/docker-entrypoint-initdb.d/mongo-init.js:ro + environment: + MONGO_INITDB_DATABASE: outpost_api_development networks: - - outpost_api_external_network + - outpost_api_dev_external_network volumes: - outpost-api-mongo-volume: + outpost-api-dev-mongo-volume: networks: - outpost_api_external_network: - outpost_api_internal_network: + outpost_api_dev_external_network: + outpost_api_dev_internal_network: internal: true diff --git a/readme.md b/readme.md index 7b5f2f4..1d050e0 100644 --- a/readme.md +++ b/readme.md @@ -59,19 +59,19 @@ To get up and running quickly with some data use docker compose. git clone git@github.com:wearefuturegov/outpost-api-service.git && cd outpost-api-service # build the image -docker compose -f docker-compose.development.yml build +docker compose build # run the container -docker compose -f docker-compose.development.yml up -d +docker compose up -d # open shell in container -docker compose -f docker-compose.development.yml exec outpost-api-dev /bin/ash; +docker compose exec outpost-api-dev /bin/ash; # run the tests -docker compose -f docker-compose.development.yml exec outpost-api-dev npm run test +docker compose exec outpost-api-dev npm run test # stop the container -docker compose -f docker-compose.development.yml stop +docker compose stop ``` If you want to use it in conjunction with a local mongodb database, for example you are using [Outpost](https://github.com/wearefuturegov/outpost/) you could also run it using just docker.