Last active
May 28, 2020 19:38
-
-
Save lopezjurip/a3f370add3f9ed0b317db3439c4d3731 to your computer and use it in GitHub Desktop.
A great Dockerfile for Node.js with Typescript and Yarn (multi-step build) and NPM Token for private modules
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
## | |
# First stage: prepare image | |
FROM node:12-alpine AS base | |
ARG NPM_TOKEN | |
ARG WORKDIR=/usr/src/app | |
WORKDIR ${WORKDIR} | |
# Install container build dependencies | |
RUN apk --no-cache add g++ ca-certificates lz4-dev musl-dev openssl-dev \ | |
make python gcc zlib-dev libc-dev bsd-compat-headers py-setuptools git bash | |
# Install npm build dependencies | |
COPY package.json yarn.lock ./ | |
RUN echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" > .npmrc | |
RUN yarn install --frozen-lockfile | |
## | |
# Second stage: build app | |
FROM base AS build | |
ARG WORKDIR=/usr/src/app | |
WORKDIR ${WORKDIR} | |
# Build | |
COPY . ./ | |
ENV NODE_ENV=production | |
RUN yarn build | |
## | |
# Third stage: run app | |
FROM base AS release | |
ARG WORKDIR=/usr/src/app | |
WORKDIR ${WORKDIR} | |
# Get "compiled" files | |
COPY --from=build ${WORKDIR} ./ | |
EXPOSE 4000 | |
ENV NODE_ENV=production | |
CMD [ "yarn", "start" ] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment