Created
February 26, 2019 17:27
-
-
Save ryanhanwu/d4aa5cb3aee7bec14128615609c1779c to your computer and use it in GitHub Desktop.
muti-stage build for node+babel+docker
This file contains 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
# common base image for development and production | |
FROM node:10.11.0-alpine AS base | |
WORKDIR /app | |
# dev image contains everything needed for testing, development and building | |
FROM base AS development | |
COPY package.json yarn.lock ./ | |
# first set aside prod dependencies so we can copy in to the prod image | |
RUN yarn install --pure-lockfile --production | |
RUN cp -R node_modules /tmp/node_modules | |
# install all dependencies and add source code | |
RUN yarn install --pure-lockfile | |
COPY . . | |
# builder runs unit tests and linter, then builds production code | |
FROM development as builder | |
RUN yarn lint | |
RUN yarn test:unit --colors | |
RUN yarn babel ./src --out-dir ./dist --copy-files | |
# release includes bare minimum required to run the app, copied from builder | |
FROM base AS release | |
COPY --from=builder /tmp/node_modules ./node_modules | |
COPY --from=builder /app/dist ./dist | |
COPY --from=builder /app/package.json ./ | |
CMD ["yarn", "pm2-runtime", "dist/index.js"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment