From edee57a799cdaf6bcff77358f99e9c551da7c428 Mon Sep 17 00:00:00 2001 From: HutchGrant Date: Wed, 9 Jan 2019 18:38:03 -0500 Subject: [PATCH 1/6] Adding Dockerfile, closes #68 --- Dockerfile | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..3d4f148 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,37 @@ +# Modified Brett Fisher's node-docker-good-defaults https://github.com/BretFisher/node-docker-good-defaults/blob/master/Dockerfile +FROM node:10 + +# set our node environment, either development or production +# defaults to production, compose overrides this to development on build and run +ARG NODE_ENV=production +ENV NODE_ENV $NODE_ENV + +# default to port 8000 for node, and 9229 and 9230 (tests) for debug +ARG PORT=8000 +ENV PORT $PORT +EXPOSE $PORT 9229 9230 + +RUN npm i npm@latest -g + +# install dependencies first, in a different location for easier app bind mounting for local development +WORKDIR /opt +COPY package.json package-lock.json* ./ +RUN npm install && \ + npm install --only=dev && \ + npm cache clean --force +ENV PATH /opt/node_modules/.bin:$PATH + +WORKDIR /opt/app +COPY . /opt/app +RUN echo "node_modules" > .eslintignore + +# the official node image provides an unprivileged user as a security best practice +# https://github.com/nodejs/docker-node/blob/master/docs/BestPractices.md#non-root-user +RUN chown -R node /opt/app +USER node + +RUN npm run build + +# use `docker run --init in production` +# so that signals are passed properly. +CMD [ "ws" ] \ No newline at end of file From 800fe1d7f234a88e7e05c581b725de1b75926835 Mon Sep 17 00:00:00 2001 From: HutchGrant Date: Wed, 9 Jan 2019 18:39:35 -0500 Subject: [PATCH 2/6] Adding Dockerfile to package.json --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index 7a044a3..45858fb 100644 --- a/package.json +++ b/package.json @@ -22,6 +22,7 @@ ".editorconfig", ".eslintrc", ".gitattributes", + "Dockerfile", "yarn.lock", "package-lock.json", "babel.config.js", From f17baa75ad8a53c9e2a5c66c5607670639329eea Mon Sep 17 00:00:00 2001 From: HutchGrant Date: Thu, 10 Jan 2019 02:37:01 -0500 Subject: [PATCH 3/6] Adjusting for puppeteer --- Dockerfile | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/Dockerfile b/Dockerfile index 3d4f148..bae3ad4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,5 @@ # Modified Brett Fisher's node-docker-good-defaults https://github.com/BretFisher/node-docker-good-defaults/blob/master/Dockerfile -FROM node:10 +FROM thegreenhouse/nodejs-dev:0.4.0 # set our node environment, either development or production # defaults to production, compose overrides this to development on build and run @@ -25,11 +25,6 @@ WORKDIR /opt/app COPY . /opt/app RUN echo "node_modules" > .eslintignore -# the official node image provides an unprivileged user as a security best practice -# https://github.com/nodejs/docker-node/blob/master/docs/BestPractices.md#non-root-user -RUN chown -R node /opt/app -USER node - RUN npm run build # use `docker run --init in production` From b17c0aef3e2d7ebf750603ddbd36c8f35d88fec9 Mon Sep 17 00:00:00 2001 From: HutchGrant Date: Tue, 22 Jan 2019 22:00:44 -0500 Subject: [PATCH 4/6] Adding Docker guide to readme --- README.md | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index dd3b01b..9e2bc30 100644 --- a/README.md +++ b/README.md @@ -128,4 +128,28 @@ For convenience, Create Evergreen App comes with the dependencies needed to run - For information on adding more browsers, see [the Karma docs](http://karma-runner.github.io/3.0/config/browsers.html). - For more information on testing in general, see [our wiki!](https://github.com/ProjectEvergreen/create-evergreen-app/wiki). -> Chrome headless is enabled by default since it is the most portable between local and continuous integration environments. \ No newline at end of file +> Chrome headless is enabled by default since it is the most portable between local and continuous integration environments. + +#### Docker + +Create Evergreen App comes Docker-ready with a built in Dockerfile + +To build and tag a docker image with any image/release name for your app: + +```bash +$ docker build -t imagename:releasename . +``` + +To run the docker image: + +```bash +$ docker run imagename:releasename +``` + +You can access the app in your browser at http://172.17.0.2:8000 (your container's IP at port 8000) + +To test the docker image: + +```bash +$ docker run --init imagename:releasename npm run test +``` \ No newline at end of file From 1b7cdd6dc2509ed3949aec621d7395b1f79df2d8 Mon Sep 17 00:00:00 2001 From: HutchGrant Date: Tue, 22 Jan 2019 22:04:01 -0500 Subject: [PATCH 5/6] Adding Docker init flag note --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 9e2bc30..3ec4715 100644 --- a/README.md +++ b/README.md @@ -143,11 +143,13 @@ $ docker build -t imagename:releasename . To run the docker image: ```bash -$ docker run imagename:releasename +$ docker run --init imagename:releasename ``` You can access the app in your browser at http://172.17.0.2:8000 (your container's IP at port 8000) +**Note** Use the `--init` flag so that the signals are passed correctly. + To test the docker image: ```bash From bfb998c245b249e7f9597d20d3587a82d7943222 Mon Sep 17 00:00:00 2001 From: HutchGrant Date: Wed, 30 Jan 2019 20:27:30 -0500 Subject: [PATCH 6/6] Updating README and Dockerfile for development/testing --- Dockerfile | 4 ++-- README.md | 38 +++++++++++++++++++++++++++++++++----- 2 files changed, 35 insertions(+), 7 deletions(-) diff --git a/Dockerfile b/Dockerfile index bae3ad4..57366d8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,10 +6,10 @@ FROM thegreenhouse/nodejs-dev:0.4.0 ARG NODE_ENV=production ENV NODE_ENV $NODE_ENV -# default to port 8000 for node, and 9229 and 9230 (tests) for debug +# default to port 8000 for prod, 1981 for dev, and 9876 for testing ARG PORT=8000 ENV PORT $PORT -EXPOSE $PORT 9229 9230 +EXPOSE $PORT 1981 9876 RUN npm i npm@latest -g diff --git a/README.md b/README.md index 3ec4715..8591670 100644 --- a/README.md +++ b/README.md @@ -140,18 +140,46 @@ To build and tag a docker image with any image/release name for your app: $ docker build -t imagename:releasename . ``` -To run the docker image: +To run the docker image in production: ```bash -$ docker run --init imagename:releasename +$ docker run --init --name mycontainer imagename:releasename ``` -You can access the app in your browser at http://172.17.0.2:8000 (your container's IP at port 8000) +**Note** Use the `--init` flag so that the exit signals are passed correctly. -**Note** Use the `--init` flag so that the signals are passed correctly. +Which should display something like: + +``` +Serving at http://e899fd0ef42c:8000, http://127.0.0.1:8000, http://172.17.0.2:8000 +``` + +You will need to access your app using the container's IP and port(yours will be different, but it's the third URL shown above). + +Otherwise, you can get your container `IPAddress` with: + +``` +docker inspect mycontainer +``` + +#### Docker Development + +You can run your application's webpack-dev-server within a container by modifiying the webpack.config.develop.js with your container's IP address(yours will be different, see above) + +``` +host: '172.17.0.2', +``` + +You can mount and run your application's `src` folder so that your changes are immediately reflected within a running container with: + +``` +docker run --init --name mycontainer -v "$(pwd)"/src:/opt/app/src imagename:releasename npm run develop +``` + +#### Docker Testing To test the docker image: ```bash -$ docker run --init imagename:releasename npm run test +$ docker run --init imagename:releasename npm test ``` \ No newline at end of file