Skip to content

Instantly share code, notes, and snippets.

@puppybits
Created September 25, 2015 18:10
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save puppybits/8c518c4e8964f18cea93 to your computer and use it in GitHub Desktop.
Save puppybits/8c518c4e8964f18cea93 to your computer and use it in GitHub Desktop.
Super fast JS Docker images by caching NPM modules that haven't changed
FROM library/node
MAINTAINER bobby@levelmoney.com
RUN mkdir /.npm
RUN mkdir /app
# cache (and skip if no changes) to the node_modules
WORKDIR /.npm
ADD package.json /.npm/package.json
# Set the version in the cache folder to 0.
# This is so that Docker will skip downloading node_modules when the version of the app increments but the node_modules do not.
RUN npm version 0.0.0
# npm takes a while and we should see progress. This should only happen with a library module changes
RUN npm install --production --loglevel verbose
# Copy over the app and build with Webpack
WORKDIR /app
ADD package.json /app/package.json
ADD src /app/src
ADD server /app/server
ADD webpack.config.js /app/webpack.config.js
# React/Webpack is based off of Megatome (https://github.com/Levelmoney/generator-megatome)
ADD webpack.dist.config.js /app/webpack.dist.config.js
RUN npm run build
COPY server /app/server
EXPOSE 8080
CMD PORT=8080 node --harmony server/server.js
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment