Last active
October 18, 2019 21:44
-
-
Save Cretezy/24eb198fe07be2b11ab1f387cc420628 to your computer and use it in GitHub Desktop.
Node + Docker with proper caching
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Dockerfile | |
node_modules |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Specify Node version | |
FROM node:latest | |
WORKDIR /tmp/build | |
ENV NODE_ENV=production | |
# Copy only required files for fetching dependencies | |
COPY package.json yarn.lock /tmp/build/ | |
RUN yarn --prod | |
# Move node_modules outside (to avoid overriding) | |
RUN mv /tmp/build/node_modules /tmp/node_modules | |
# Copy the whole app in | |
COPY . /tmp/build | |
# Replace node_modules | |
RUN rm -rf /tmp/build/node_modules && cp -a /tmp/node_modules /tmp/build/node_modules | |
# Build the app | |
RUN yarn build | |
WORKDIR /usr/src/app | |
# Copy only app runtime (required files for app to run) | |
RUN cp -a /tmp/build/node_modules /tmp/build/dist /tmp/build/package.json /tmp/build/config /usr/src/app/ && rm -rf /tmp/build | |
# Set environment variables | |
ENV PORT=80 | |
# Start app | |
CMD yarn start | |
EXPOSE 80 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment