Skip to content
Snippets Groups Projects
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
Dockerfile 3.06 KiB
# Base
FROM node:20 AS base

ARG APP_HOME=/home/node/app
ARG SERVICE

WORKDIR ${APP_HOME}

RUN corepack enable

# Dependencies
FROM base AS dependencies

COPY package.json pnpm-lock.yaml pnpm-workspace.yaml tsconfig*.json .swcrc ./
COPY patches ./patches
COPY apps/shared/package.json ./apps/shared/
COPY devtools/package.json ./devtools/
RUN pnpm install --frozen-lockfile

# Build shared
FROM base AS build-shared

COPY apps/shared ./apps/shared
COPY --from=dependencies ${APP_HOME}/package.json ${APP_HOME}/pnpm-lock.yaml ${APP_HOME}/pnpm-workspace.yaml ${APP_HOME}/tsconfig*.json ${APP_HOME}/.swcrc ./
COPY --from=dependencies ${APP_HOME}/node_modules ./node_modules
COPY --from=dependencies ${APP_HOME}/apps/shared/node_modules ./apps/shared/node_modules
COPY --from=dependencies ${APP_HOME}/patches ./patches
RUN pnpm --filter shared build

# Build DevTools
FROM base AS build-devtools

COPY --from=dependencies ${APP_HOME}/package.json ${APP_HOME}/pnpm-lock.yaml ${APP_HOME}/pnpm-workspace.yaml ${APP_HOME}/tsconfig*.json ${APP_HOME}/.swcrc ./
COPY --from=dependencies ${APP_HOME}/node_modules ./node_modules
COPY --from=dependencies ${APP_HOME}/devtools/node_modules ./devtools/node_modules
COPY --from=dependencies ${APP_HOME}/patches ./patches
COPY --from=build-shared ${APP_HOME}/apps/shared ./apps/shared
COPY devtools ./devtools
RUN pnpm --filter devtools build && pnpm --filter devtools --prod deploy build

# Final devtools
FROM node:20-slim AS devtools

ARG APP_HOME=/home/node/app
ARG NODE_ENV=production
ENV NODE_ENV=${NODE_ENV}

WORKDIR ${APP_HOME}
CMD ["node", "dist/server.js"]

COPY --from=build-devtools --chown=node:node ${APP_HOME}/build/dist ./dist
COPY --from=build-devtools --chown=node:node ${APP_HOME}/build/node_modules ./node_modules
COPY --from=build-devtools --chown=node:node ${APP_HOME}/build/package.json .

USER node

# Build service
FROM base AS build-service

COPY --from=dependencies ${APP_HOME}/package.json ${APP_HOME}/pnpm-lock.yaml ${APP_HOME}/pnpm-workspace.yaml ${APP_HOME}/tsconfig*.json ${APP_HOME}/.swcrc ./
COPY --from=dependencies ${APP_HOME}/node_modules ./node_modules
COPY --from=dependencies ${APP_HOME}/patches ./patches
COPY --from=build-shared ${APP_HOME}/apps/shared ./apps/shared
COPY apps/${SERVICE} ./apps/${SERVICE}
RUN pnpm install --frozen-lockfile && pnpm --filter ${SERVICE} build && pnpm --filter ${SERVICE} --prod deploy build

# Final
FROM node:20-slim AS final

ARG APP_HOME=/home/node/app