diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..57366d8 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,32 @@ +# Modified Brett Fisher's node-docker-good-defaults https://github.com/BretFisher/node-docker-good-defaults/blob/master/Dockerfile +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 +ARG NODE_ENV=production +ENV NODE_ENV $NODE_ENV + +# default to port 8000 for prod, 1981 for dev, and 9876 for testing +ARG PORT=8000 +ENV PORT $PORT +EXPOSE $PORT 1981 9876 + +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 + +RUN npm run build + +# use `docker run --init in production` +# so that signals are passed properly. +CMD [ "ws" ] \ No newline at end of file diff --git a/README.md b/README.md index dd3b01b..8591670 100644 --- a/README.md +++ b/README.md @@ -128,4 +128,58 @@ 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 in production: + +```bash +$ docker run --init --name mycontainer imagename:releasename +``` + +**Note** Use the `--init` flag so that the exit 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 test +``` \ No newline at end of file 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",