Skip to content

Instantly share code, notes, and snippets.

@thmsobrmlr
Created December 14, 2022 14:14
Show Gist options
  • Save thmsobrmlr/e3c00338c4b6e9fd5ddef4ba5c53db48 to your computer and use it in GitHub Desktop.
Save thmsobrmlr/e3c00338c4b6e9fd5ddef4ba5c53db48 to your computer and use it in GitHub Desktop.
Only prod node dependencies in docker image
FROM node:16-alpine AS deps
RUN apk --no-cache add curl
RUN curl -sf https://gobinaries.com/tj/node-prune | sh
WORKDIR /usr/src/app
COPY ["package.json", "yarn.lock", "./"]
# build-dependencies are required for bcrypt on m1 macs
RUN apk --no-cache --virtual build-dependencies add python3 make g++ \
&& yarn install --production \
&& apk del build-dependencies
RUN /usr/local/bin/node-prune
FROM node:16-alpine AS build
WORKDIR /usr/src/app
COPY ["package.json", "yarn.lock", "./"]
# build-dependencies are required for bcrypt on m1 macs
RUN apk --no-cache --virtual build-dependencies add python3 make g++ \
&& yarn install \
&& apk del build-dependencies
COPY ["tsconfig.json", "tsconfig-build.json", "server.ts", "worker.ts", "./"]
COPY ["app/", "./app/"]
COPY ["lib/", "./lib/"]
COPY ["types/", "./types/"]
COPY ["db/", "./db/"]
RUN yarn build
FROM node:16-alpine
ARG VERSION
ENV VERSION=${VERSION}
ENV NODE_ENV=production
USER node
WORKDIR /usr/src/app
COPY --from=deps ["/usr/src/app/node_modules", "./node_modules/"]
COPY --from=build ["/usr/src/app/dist", "./dist/"]
EXPOSE 4000
WORKDIR /usr/src/app/dist
ENTRYPOINT ["node", "server.js"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment