Skip to content

Instantly share code, notes, and snippets.

@lamngockhuong
Last active August 7, 2024 05:15
Show Gist options
  • Save lamngockhuong/bed618b8d4ece47099a27648fde52448 to your computer and use it in GitHub Desktop.
Save lamngockhuong/bed618b8d4ece47099a27648fde52448 to your computer and use it in GitHub Desktop.
Dockerfile for nodejs 20 alpine, yarn 4.x and puppeteer. Tested on Local development, Cloud Run
##################
# BUILD BASE IMAGE
##################
FROM node:20-alpine AS base
ENV YARN_VERSION=4.1.1
# Install and use yarn 4.x
RUN corepack enable && corepack prepare yarn@${YARN_VERSION} --activate
#####################
# BUILD BUILDER IMAGE
#####################
FROM base AS builder
WORKDIR /app
COPY . .
COPY package*.json yarn.lock .yarnrc.yml ./
RUN yarn workspaces focus --production
RUN yarn build
#####################
# BUILD PUPPETEER IMAGE
#####################
FROM node:20-alpine AS puppeteer
WORKDIR /app
RUN apk add --no-cache \
chromium \
nss \
freetype \
harfbuzz \
ca-certificates \
ttf-freefont
ENV PUPPETEER_EXECUTABLE_PATH=/usr/bin/chromium-browser
######################
# BUILD FOR PRODUCTION
######################
FROM puppeteer AS production
WORKDIR /app
COPY --chown=node:node --from=builder /app/node_modules ./node_modules
COPY --chown=node:node --from=builder /app/dist ./dist
COPY --chown=node:node --from=builder /app/package.json ./
USER node
CMD [ "node", "dist/main.js" ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment