From 8e50c188d9299e73cc49afa3621097fb59d4c96d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20Sch=C3=A4fer?= Date: Sat, 11 Aug 2018 18:18:32 +0200 Subject: [PATCH 01/12] Setup docker for local development and debugging Write README --- Dockerfile | 34 +++++++++-------------- README.md | 40 ++++++++++++++++++++++++++-- config/docker/local-development.json | 7 +++++ config/docker/local-test.json | 3 +++ config/docker/local.json | 8 ++++++ docker-compose.yml | 21 +++++++++------ 6 files changed, 81 insertions(+), 32 deletions(-) create mode 100644 config/docker/local-development.json create mode 100644 config/docker/local-test.json create mode 100644 config/docker/local.json diff --git a/Dockerfile b/Dockerfile index b27d4d3..d8e85fd 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,31 +6,21 @@ RUN apk update && apk upgrade RUN rm -rf /var/cache/apk/* RUN yarn global add pm2 -# expose the app port -EXPOSE 3030 - -# set environment variables -# ENV NPM_CONFIG_PRODUCTION=false -# ENV HOST=0.0.0.0 -ENV NODE_ENV=production -ENV API_PORT=3030 - -# start the application in a autohealing cluster -# NOTE: quick fix for server issues, restart api when reaching max of 300 MB Memory Usage (happens in conjunction with 100% CPU Usage) -# TODO: find better way of dealing with that issue -CMD NODE_ENV=production pm2 start server/index.js -n api --attach --max-memory-restart 1024M -# CMD NODE_ENV=production pm2 start server/index.js -n api -i 2 --attach -# as we have issues with pm2 currently in conjunction with nuxt, we use the standard approach here -# CMD NODE_ENV=production node server/index.js - # create working directory -RUN mkdir -p /var/www/ -WORKDIR /var/www/ +RUN mkdir -p /API +WORKDIR /API # install app dependencies -COPY package.json /var/www/ -COPY yarn.lock /var/www/ +COPY package.json /API +COPY yarn.lock /API RUN yarn install --frozen-lockfile --non-interactive # copy the code to the docker image -COPY . /var/www/ +COPY . /API + +# setup local configuration +COPY ./config/docker/* /API/config/ + +# expose the app port +EXPOSE 3030 +EXPOSE 9229 diff --git a/README.md b/README.md index deffa7a..910e081 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,42 @@ The API for a better world. More information under [human-connection.org](https: > **Note:** This is only the API part of Human-Connection, you have to also checkout the [WebApp](https://github.com/Human-Connection/WebApp) which uses this API. +## Installation via docker + +Make sure you have a recent version of [docker](https://www.docker.com/) and [docker-compose](https://docs.docker.com/compose/). + +Run: +```bash +$ docker-compose up --build +``` +Now, your API should be running at [http://localhost:3030](http://localhost:3030) +and you can see some contributions at [http://localhost:3030/contributions](http://localhost:3030/contributions). + +For debugging you can run: +```bash +$ docker-compose run --rm --service-ports api yarn run dev:debug +``` +And debug your app with [Chrome Dev Tools](chrome://inspect). + +### Configuration in Docker + +Change configuration in `config/docker/local-development.json` or +`config/docker/local.json` and rerun `docker-compose up --build`. + +### Testing in Docker + +Run the entire test suite with: +```bash +$ docker-compose run --rm api yarn run test +``` + +If you want you can run specific tests: +```bash +$ docker-compose run --rm api yarn run mocha +$ docker-compose run --rm api yarn run cucumber +``` + + ## Local installation > we recommand to install the project locally for the best development ease and performance @@ -103,7 +139,7 @@ Getting up and running is as easy as 1, 2, 3, 4 ... 5. > Do not forget to always start it if you choose that setup or otherwise you will not see any pictures at all. -### Local configuration +### Local Configuration You can override any default configuration in `config/local.json`. You can find a list of availabe defaults in `config/default.json`. @@ -121,7 +157,7 @@ replace `localhost` in your settings with your IP address in the local network: ``` -## Testing +### Local Testing Run the entire test suite with: ```bash diff --git a/config/docker/local-development.json b/config/docker/local-development.json new file mode 100644 index 0000000..1593a1d --- /dev/null +++ b/config/docker/local-development.json @@ -0,0 +1,7 @@ +{ + "mongodb": "mongodb://mongo:27017/hc_api", + "seeder": { + "runOnInit": true, + "dropDatabase": false + } +} diff --git a/config/docker/local-test.json b/config/docker/local-test.json new file mode 100644 index 0000000..c40c94e --- /dev/null +++ b/config/docker/local-test.json @@ -0,0 +1,3 @@ +{ + "mongodb": "mongodb://mongo:27017/hc_api_test" +} diff --git a/config/docker/local.json b/config/docker/local.json new file mode 100644 index 0000000..87ac8c3 --- /dev/null +++ b/config/docker/local.json @@ -0,0 +1,8 @@ +{ + "host": "0.0.0.0", + "smtpConfig": { + "host": "maildev", + "port": 25, + "ignoreTLS": true + } +} diff --git a/docker-compose.yml b/docker-compose.yml index dafd68d..d4bff2d 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,16 +1,21 @@ -version: '2' +version: '3' services: - mongo-cluster: - image: mongo - ports: - - "27017:27017" - command: "--smallfiles --logpath=/dev/null" api: build: . ports: - "3030:3030" + - "9229:9229" # node inspect links: - - mongo-cluster + - mongo environment: - PORT: 3030 \ No newline at end of file + - NODE_ENV=development + command: yarn run dev + mongo: + image: mongo + command: "--smallfiles --logpath=/dev/null" + maildev: + image: djfarrelly/maildev + ports: + - "1080:80" + - "1025:25" From 1ee92349a17545592a4154ee0af76b96916ac275 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20Sch=C3=A4fer?= Date: Sun, 12 Aug 2018 00:14:10 +0200 Subject: [PATCH 02/12] Have config in docker persisted but not synced --- docker-compose.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/docker-compose.yml b/docker-compose.yml index d4bff2d..48fc828 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -8,9 +8,13 @@ services: - "9229:9229" # node inspect links: - mongo + - maildev environment: - NODE_ENV=development command: yarn run dev + volumes: + - .:/API + - docker_config:/API/config mongo: image: mongo command: "--smallfiles --logpath=/dev/null" @@ -19,3 +23,5 @@ services: ports: - "1080:80" - "1025:25" +volumes: + docker_config: From 2d31149079c7c34c82ab4b3ba6fd693d060f8304 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20Sch=C3=A4fer?= Date: Sun, 12 Aug 2018 11:10:20 +0200 Subject: [PATCH 03/12] Set pm2 as default command in docker build .. and overwrite in docker-compose. Move layer COPY as far as possible to the end for faster rebuild. --- Dockerfile | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index d8e85fd..2cbb751 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,11 @@ FROM node:8.9-alpine LABEL Description="This image is used to start the hc-api-feathers" Vendor="Human-Connection gGmbH" Version="1.0" Maintainer="Human-Connection gGmbH (developer@human-connection.org)" +# expose the app port +EXPOSE 3030 +# chrome debugging +EXPOSE 9229 + # update unix packages RUN apk update && apk upgrade RUN rm -rf /var/cache/apk/* @@ -17,10 +22,10 @@ RUN yarn install --frozen-lockfile --non-interactive # copy the code to the docker image COPY . /API - # setup local configuration COPY ./config/docker/* /API/config/ -# expose the app port -EXPOSE 3030 -EXPOSE 9229 +# start the application in a autohealing cluster +# NOTE: quick fix for server issues, restart api when reaching max of 300 MB Memory Usage (happens in conjunction with 100% CPU Usage) +# TODO: find better way of dealing with that issue +CMD ["pm2", "start", "server/index.js", "-n", "api", "--attach", "--max-memory-restart", "1024M"] From 9f2e9a5e311190d553b220699ba9119adfa16dfe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20Sch=C3=A4fer?= Date: Sun, 12 Aug 2018 11:27:15 +0200 Subject: [PATCH 04/12] Replace copy of config files for docker at runtime Reason: I might want to set database cleaner configs withouth rebuilding the docker container. So, syncing the config/ folder would be desired. But then we don't want the configuration for the host system to get in conflict with the docker settings. Solution: Set node instance environment variable to `docker`. --- Dockerfile | 5 +++-- config/default-docker.json | 4 ++++ config/docker/local-development.json | 7 ------- config/docker/local.json | 8 -------- config/{docker/local-test.json => test-docker.json} | 0 docker-compose.yml | 5 ----- 6 files changed, 7 insertions(+), 22 deletions(-) create mode 100644 config/default-docker.json delete mode 100644 config/docker/local-development.json delete mode 100644 config/docker/local.json rename config/{docker/local-test.json => test-docker.json} (100%) diff --git a/Dockerfile b/Dockerfile index 2cbb751..672a668 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,6 +6,9 @@ EXPOSE 3030 # chrome debugging EXPOSE 9229 +# override configuration by instance name in docker container +ENV NODE_APP_INSTANCE=docker + # update unix packages RUN apk update && apk upgrade RUN rm -rf /var/cache/apk/* @@ -22,8 +25,6 @@ RUN yarn install --frozen-lockfile --non-interactive # copy the code to the docker image COPY . /API -# setup local configuration -COPY ./config/docker/* /API/config/ # start the application in a autohealing cluster # NOTE: quick fix for server issues, restart api when reaching max of 300 MB Memory Usage (happens in conjunction with 100% CPU Usage) diff --git a/config/default-docker.json b/config/default-docker.json new file mode 100644 index 0000000..3db818c --- /dev/null +++ b/config/default-docker.json @@ -0,0 +1,4 @@ +{ + "mongodb": "mongodb://mongo:27017/hc_api", + "host": "0.0.0.0" +} diff --git a/config/docker/local-development.json b/config/docker/local-development.json deleted file mode 100644 index 1593a1d..0000000 --- a/config/docker/local-development.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "mongodb": "mongodb://mongo:27017/hc_api", - "seeder": { - "runOnInit": true, - "dropDatabase": false - } -} diff --git a/config/docker/local.json b/config/docker/local.json deleted file mode 100644 index 87ac8c3..0000000 --- a/config/docker/local.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "host": "0.0.0.0", - "smtpConfig": { - "host": "maildev", - "port": 25, - "ignoreTLS": true - } -} diff --git a/config/docker/local-test.json b/config/test-docker.json similarity index 100% rename from config/docker/local-test.json rename to config/test-docker.json diff --git a/docker-compose.yml b/docker-compose.yml index 48fc828..fa76d56 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -9,12 +9,9 @@ services: links: - mongo - maildev - environment: - - NODE_ENV=development command: yarn run dev volumes: - .:/API - - docker_config:/API/config mongo: image: mongo command: "--smallfiles --logpath=/dev/null" @@ -23,5 +20,3 @@ services: ports: - "1080:80" - "1025:25" -volumes: - docker_config: From 6ab9b0e57702c1a69727de2b92431c6eaa77540e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20Sch=C3=A4fer?= Date: Sun, 12 Aug 2018 11:56:22 +0200 Subject: [PATCH 05/12] Setup thumbor with docker-compose.yml Problem: Although thumbor is reachable from within the container, I cannot see any thumbnails in development environment. Maybe the seeder does not create thumbnails? --- README.md | 14 ++++++-------- docker-compose.yml | 2 ++ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 910e081..673588f 100644 --- a/README.md +++ b/README.md @@ -129,14 +129,12 @@ Getting up and running is as easy as 1, 2, 3, 4 ... 5. 7. Setup and Start Thumbnail Service (optional) - We are using [Thumbor](https://github.com/thumbor/thumbor) as a Thumbnail Microservice. - You can install it locally if you like but this is totally optional. - - **Install OR use docker** - - - At first you have to [install](http://thumbor.readthedocs.io/en/latest/installing.html) it locally and start it in the console with `thumbor` **OR** run it with docker `docker run -p 8000:8000 apsl/thumbor` - - Set the `thumbor.url` in `config/local.json` to `http://localhost:8888` (with docker `http://localhost:8000`) if not defined differently. The `thumbor.key` does not necessarily have to be defined, it just makes the URL more secure. - + Install [Thumbor](https://github.com/thumbor/thumbor) locally on your machine according to the [documentation](http://thumbor.readthedocs.io/en/latest/installing.html) and start it with: + ```sh + $ thumbor + ``` + Set the `thumbor.url` in `config/local.json` to `http://localhost:8888`. + The `thumbor.key` does not necessarily have to be defined, it just makes the URL more secure. > Do not forget to always start it if you choose that setup or otherwise you will not see any pictures at all. ### Local Configuration diff --git a/docker-compose.yml b/docker-compose.yml index fa76d56..e4e56c5 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -20,3 +20,5 @@ services: ports: - "1080:80" - "1025:25" + thumbor: + image: apsl/thumbor From d1f0c7ba9335031593a8c38638a60e6fa68ba4e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20Sch=C3=A4fer?= Date: Sun, 12 Aug 2018 13:27:48 +0200 Subject: [PATCH 06/12] Provide a staging environment with bridget network --- docker-compose.override.yml | 7 +++++++ docker-compose.staging.yml | 27 +++++++++++++++++++++++++++ docker-compose.yml | 3 --- 3 files changed, 34 insertions(+), 3 deletions(-) create mode 100644 docker-compose.override.yml create mode 100644 docker-compose.staging.yml diff --git a/docker-compose.override.yml b/docker-compose.override.yml new file mode 100644 index 0000000..449322f --- /dev/null +++ b/docker-compose.override.yml @@ -0,0 +1,7 @@ +version: '3' + +services: + api: + ports: + - "3030:3030" + - "9229:9229" # node inspect diff --git a/docker-compose.staging.yml b/docker-compose.staging.yml new file mode 100644 index 0000000..da6a1bc --- /dev/null +++ b/docker-compose.staging.yml @@ -0,0 +1,27 @@ +version: '3' + +services: + mongo: + networks: + hc-network: + ipv4_address: 172.25.0.10 + api: + networks: + hc-network: + ipv4_address: 172.25.0.11 + maildev: + networks: + hc-network: + ipv4_address: 172.25.0.12 + thumbor: + networks: + hc-network: + ipv4_address: 172.25.0.13 +networks: + hc-network: + driver: bridge + ipam: + driver: default + config: + - + subnet: 172.25.0.0/16 diff --git a/docker-compose.yml b/docker-compose.yml index e4e56c5..b6e6292 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -3,9 +3,6 @@ version: '3' services: api: build: . - ports: - - "3030:3030" - - "9229:9229" # node inspect links: - mongo - maildev From 1071aee62ba29f00cf23fb77dd56083c5ddf4142 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20Sch=C3=A4fer?= Date: Tue, 14 Aug 2018 14:08:41 +0200 Subject: [PATCH 07/12] Don't expose port 9229 by default (e.g. in prod) --- Dockerfile | 3 +-- docker-compose.override.yml | 3 +++ docker-compose.staging.yml | 2 ++ 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 672a668..b9623c0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,11 +3,10 @@ LABEL Description="This image is used to start the hc-api-feathers" Vendor="Huma # expose the app port EXPOSE 3030 -# chrome debugging -EXPOSE 9229 # override configuration by instance name in docker container ENV NODE_APP_INSTANCE=docker +ENV NODE_ENV=production # update unix packages RUN apk update && apk upgrade diff --git a/docker-compose.override.yml b/docker-compose.override.yml index 449322f..1eabb8c 100644 --- a/docker-compose.override.yml +++ b/docker-compose.override.yml @@ -2,6 +2,9 @@ version: '3' services: api: + environment: + - NODE_ENV=development ports: - "3030:3030" - "9229:9229" # node inspect + command: yarn run dev diff --git a/docker-compose.staging.yml b/docker-compose.staging.yml index da6a1bc..3d1e442 100644 --- a/docker-compose.staging.yml +++ b/docker-compose.staging.yml @@ -6,6 +6,8 @@ services: hc-network: ipv4_address: 172.25.0.10 api: + environment: + - NODE_ENV=development networks: hc-network: ipv4_address: 172.25.0.11 From 0f41e14bed1488bcdc5acd610b4dd06267f7edc0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20Sch=C3=A4fer?= Date: Tue, 14 Aug 2018 14:40:19 +0200 Subject: [PATCH 08/12] Replace deprecated `links` with docker-compose net --- docker-compose.staging.yml | 11 +---------- docker-compose.yml | 17 +++++++++++++++-- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/docker-compose.staging.yml b/docker-compose.staging.yml index 3d1e442..d510ce0 100644 --- a/docker-compose.staging.yml +++ b/docker-compose.staging.yml @@ -1,24 +1,15 @@ version: '3' services: - mongo: - networks: - hc-network: - ipv4_address: 172.25.0.10 api: - environment: - - NODE_ENV=development networks: hc-network: ipv4_address: 172.25.0.11 - maildev: - networks: - hc-network: - ipv4_address: 172.25.0.12 thumbor: networks: hc-network: ipv4_address: 172.25.0.13 + networks: hc-network: driver: bridge diff --git a/docker-compose.yml b/docker-compose.yml index b6e6292..4cde078 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -3,19 +3,32 @@ version: '3' services: api: build: . - links: + depends_on: - mongo - maildev - command: yarn run dev + - thumbor + networks: + - hc-network volumes: - .:/API mongo: image: mongo + networks: + - hc-network command: "--smallfiles --logpath=/dev/null" maildev: image: djfarrelly/maildev + networks: + - hc-network ports: - "1080:80" - "1025:25" thumbor: image: apsl/thumbor + networks: + - hc-network + ports: + - "8000:8000" + +networks: + hc-network: From f4f0163d6f947eb90388ea37558c4c6b286f5f7e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20Sch=C3=A4fer?= Date: Tue, 14 Aug 2018 16:15:37 +0200 Subject: [PATCH 09/12] Finish documentation for local staging environment --- README.md | 16 +++++++--------- config/local-staging-docker.json | 16 ++++++++++++++++ docker-compose.staging.yml | 23 +++++++++++++++++++++++ docker-compose.yml | 15 --------------- 4 files changed, 46 insertions(+), 24 deletions(-) create mode 100644 config/local-staging-docker.json diff --git a/README.md b/README.md index 673588f..12f238e 100644 --- a/README.md +++ b/README.md @@ -39,6 +39,13 @@ And debug your app with [Chrome Dev Tools](chrome://inspect). Change configuration in `config/docker/local-development.json` or `config/docker/local.json` and rerun `docker-compose up --build`. +#### Local Staging Environment + +To get an environment which is close to production, run the following: +```sh +$ docker-compose -f docker-compose.yml -f docker-compose.staging.yml up --build +``` + ### Testing in Docker Run the entire test suite with: @@ -127,15 +134,6 @@ Getting up and running is as easy as 1, 2, 3, 4 ... 5. Now, your API should be running at [http://localhost:3030](http://localhost:3030). If you seeded your database, you will see some contributions at [http://localhost:3030/contributions](http://localhost:3030/contributions). -7. Setup and Start Thumbnail Service (optional) - - Install [Thumbor](https://github.com/thumbor/thumbor) locally on your machine according to the [documentation](http://thumbor.readthedocs.io/en/latest/installing.html) and start it with: - ```sh - $ thumbor - ``` - Set the `thumbor.url` in `config/local.json` to `http://localhost:8888`. - The `thumbor.key` does not necessarily have to be defined, it just makes the URL more secure. - > Do not forget to always start it if you choose that setup or otherwise you will not see any pictures at all. ### Local Configuration diff --git a/config/local-staging-docker.json b/config/local-staging-docker.json new file mode 100644 index 0000000..3c81e30 --- /dev/null +++ b/config/local-staging-docker.json @@ -0,0 +1,16 @@ +{ + "baseURL": "http://172.25.0.11:3030", + "seeder": { + "runOnInit": true, + "dropDatabase": true + }, + "smtpConfig": { + "host": "maildev", + "port": 25, + "ignoreTLS": true + }, + "thumbor": { + "url": "http://localhost:8000", + "key": "" + } +} diff --git a/docker-compose.staging.yml b/docker-compose.staging.yml index d510ce0..52222f2 100644 --- a/docker-compose.staging.yml +++ b/docker-compose.staging.yml @@ -2,6 +2,16 @@ version: '3' services: api: + image: humanconnection/api-feathers + build: + context: . + environment: + - NODE_ENV=staging + depends_on: + - maildev + - thumbor + ports: + - "3030:3030" networks: hc-network: ipv4_address: 172.25.0.11 @@ -9,6 +19,19 @@ services: networks: hc-network: ipv4_address: 172.25.0.13 + maildev: + image: djfarrelly/maildev + networks: + - hc-network + ports: + - "1080:80" + - "1025:25" + thumbor: + image: apsl/thumbor + networks: + - hc-network + ports: + - "8000:8000" networks: hc-network: diff --git a/docker-compose.yml b/docker-compose.yml index 4cde078..29b3f33 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -5,8 +5,6 @@ services: build: . depends_on: - mongo - - maildev - - thumbor networks: - hc-network volumes: @@ -16,19 +14,6 @@ services: networks: - hc-network command: "--smallfiles --logpath=/dev/null" - maildev: - image: djfarrelly/maildev - networks: - - hc-network - ports: - - "1080:80" - - "1025:25" - thumbor: - image: apsl/thumbor - networks: - - hc-network - ports: - - "8000:8000" networks: hc-network: From be4d44e93da1fdd722cf839c8a2f1392727b8372 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20Sch=C3=A4fer?= Date: Tue, 14 Aug 2018 19:49:38 +0200 Subject: [PATCH 10/12] "Clean" is so much better than "clear" --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index d9094f5..d2d4b6a 100644 --- a/package.json +++ b/package.json @@ -34,7 +34,7 @@ }, "scripts": { "ci": "yarn run eslint && yarn run test:coverage", - "clear": "rm -Rf tmp", + "clean": "rm -Rf tmp", "mongo": "mongod --dbpath data --quiet", "mongo:win": "mongod --dbpath /data/db --quiet", "test": "yarn run mocha && yarn run cucumber", @@ -43,7 +43,7 @@ "start": "node server/", "dev": "cross-env DEBUG=feathers* nodemon server/", "dev:debug": "cross-env DEBUG=feathers* nodemon --inspect=0.0.0.0:9229 server/", - "mocha": "yarn run clear && cross-env NODE_ENV=test mocha --recursive --timeout 10000 --exit", + "mocha": "yarn run clean && cross-env NODE_ENV=test mocha --recursive --timeout 10000 --exit", "cucumber": "concurrently --kill-others --success first 'cross-env NODE_ENV=test node server/' 'wait-on tcp:3031 && cross-env NODE_ENV=test cucumber-js'" }, "dependencies": { From 03a0c1976a4ab3d1779b27dfafeda0b59606dd32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20Sch=C3=A4fer?= Date: Wed, 15 Aug 2018 00:30:21 +0200 Subject: [PATCH 11/12] Update base image of Dockerfile --- Dockerfile | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/Dockerfile b/Dockerfile index b9623c0..0c755d9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,27 +1,31 @@ -FROM node:8.9-alpine +FROM node:alpine LABEL Description="This image is used to start the hc-api-feathers" Vendor="Human-Connection gGmbH" Version="1.0" Maintainer="Human-Connection gGmbH (developer@human-connection.org)" # expose the app port EXPOSE 3030 -# override configuration by instance name in docker container -ENV NODE_APP_INSTANCE=docker -ENV NODE_ENV=production - -# update unix packages -RUN apk update && apk upgrade -RUN rm -rf /var/cache/apk/* -RUN yarn global add pm2 - # create working directory RUN mkdir -p /API WORKDIR /API +# --no-cache: download package index on-the-fly, no need to cleanup afterwards +# --virtual: bundle packages, remove whole bundle at once, when done +RUN apk --no-cache --virtual build-dependencies add python make g++ + +RUN yarn global add pm2 + # install app dependencies COPY package.json /API COPY yarn.lock /API RUN yarn install --frozen-lockfile --non-interactive +RUN apk del build-dependencies + +# override configuration by instance name in docker container +ENV NODE_APP_INSTANCE=docker +# must be after `yarn install` +ENV NODE_ENV=production + # copy the code to the docker image COPY . /API From 7cabe76fea22faad3116f5d65c25f4ab20df8544 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20Sch=C3=A4fer?= Date: Sun, 19 Aug 2018 14:34:29 +0200 Subject: [PATCH 12/12] Fix issue with dev dependencies --- Dockerfile | 10 +++++----- docker-compose.override.yml | 3 +++ docker-compose.yml | 2 -- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/Dockerfile b/Dockerfile index 0c755d9..7b14ec2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,6 +4,10 @@ LABEL Description="This image is used to start the hc-api-feathers" Vendor="Huma # expose the app port EXPOSE 3030 +# override configuration by instance name in docker container +ENV NODE_APP_INSTANCE=docker +ENV NODE_ENV=production + # create working directory RUN mkdir -p /API WORKDIR /API @@ -17,14 +21,10 @@ RUN yarn global add pm2 # install app dependencies COPY package.json /API COPY yarn.lock /API -RUN yarn install --frozen-lockfile --non-interactive +RUN yarn install --production=false --frozen-lockfile --non-interactive RUN apk del build-dependencies -# override configuration by instance name in docker container -ENV NODE_APP_INSTANCE=docker -# must be after `yarn install` -ENV NODE_ENV=production # copy the code to the docker image COPY . /API diff --git a/docker-compose.override.yml b/docker-compose.override.yml index 1eabb8c..f86475e 100644 --- a/docker-compose.override.yml +++ b/docker-compose.override.yml @@ -7,4 +7,7 @@ services: ports: - "3030:3030" - "9229:9229" # node inspect + volumes: + - .:/API + - /API/node_modules command: yarn run dev diff --git a/docker-compose.yml b/docker-compose.yml index 29b3f33..d928c5a 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -7,8 +7,6 @@ services: - mongo networks: - hc-network - volumes: - - .:/API mongo: image: mongo networks: