Skip to content

Instantly share code, notes, and snippets.

@omerxx
Created March 18, 2018 12:24
Show Gist options
  • Save omerxx/fd6a308e6a31f3fa79a7d9edae05bfb8 to your computer and use it in GitHub Desktop.
Save omerxx/fd6a308e6a31f3fa79a7d9edae05bfb8 to your computer and use it in GitHub Desktop.
# uses Docker Multi-Stage Build
# https://docs.docker.com/v17.09/engine/userguide/eng-image/multistage-build/
# -- builder container
FROM node:9-alpine as builder
# download Yelp/dumb-init
RUN apk add --no-cache curl
RUN curl -sL https://github.com/Yelp/dumb-init/releases/download/v1.2.1/dumb-init_1.2.1_amd64 -o /sbin/dumb-init \
&& chmod +x /sbin/dumb-init
WORKDIR /opt/app
# only run `yarn install` when package.json changed, otherwise use cache
COPY package.json /opt/app/
# install all dependencies in packages.json, including devDependencies
RUN yarn install
# copy the code before a babel build
COPY . /opt/app/
RUN yarn run -s build
# -- runtime container
FROM node:9-alpine
WORKDIR /opt/app
COPY --from=builder /sbin/dumb-init /sbin/dumb-init
# only run `yarn install` when package.json changed, otherwise use cache
COPY --from=builder /opt/app/package.json .
# do not install devDependencies, only "dependencies" from package.json
RUN yarn install --production
# copy the compiled code from builder
COPY --from=builder /opt/app/dist dist/
CMD [""]
ENTRYPOINT [ "/sbin/dumb-init", "/usr/local/bin/node", "dist/index.js" ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment