Created
April 2, 2025 15:22
-
-
Save titouancreach/823e3eaf3045afd151e0ca10d7488f89 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
FROM node:22-alpine as base | |
# Install pnpm with corepack | |
RUN corepack enable && corepack prepare pnpm@latest --activate | |
# Enable `pnpm add --global` on Alpine Linux by setting | |
# home location environment variable to a location already in $PATH | |
# https://github.com/pnpm/pnpm/issues/784#issuecomment-1518582235 | |
ENV PNPM_HOME=/usr/local/bin | |
ENV COREPACK_ENABLE_DOWNLOAD_PROMPT=0 | |
RUN pnpm add -g dotenv-cli | |
FROM base as builder | |
WORKDIR /app | |
COPY . . | |
# Installation des dépendances et génération Prisma | |
RUN pnpm install --frozen-lockfile | |
# Build de l'application Next.js | |
WORKDIR /app/apps/app | |
RUN pnpm add sharp | |
ARG APP_ENV | |
RUN if [ "$APP_ENV" = "staging" ]; then \ | |
pnpm run build:staging; \ | |
else \ | |
pnpm run build; \ | |
fi | |
# Build du service Node.js | |
WORKDIR /app/apps/services | |
RUN pnpm run build | |
FROM base as runner | |
# Configuration de la sécurité | |
RUN addgroup -g 1001 -S nodejs | |
RUN adduser -S nextjs -u 1001 | |
WORKDIR /app | |
# Copie des fichiers nécessaires depuis l'étape de build | |
COPY --from=builder --chown=nextjs:nodejs /app/apps/services/dist ./services/dist | |
COPY --from=builder --chown=nextjs:nodejs /app/apps/services/package.json ./services/package.json | |
COPY --from=builder --chown=nextjs:nodejs /app/apps/services/config ./services/config | |
# Copie du binaire prisma pour services | |
COPY --from=builder --chown=nextjs:nodejs /app/apps/services/libquery_engine-linux-musl-openssl-3.0.x.so.node ./services/ | |
COPY --from=builder --chown=nextjs:nodejs /app/apps/app/package.json ./app/package.json | |
COPY --from=builder --chown=nextjs:nodejs /app/apps/app/config ./app/config | |
RUN mkdir ./app/.next | |
COPY --from=builder --chown=nextjs:nodejs /app/apps/app/.next/standalone ./app/standalone | |
COPY --from=builder --chown=nextjs:nodejs /app/apps/app/.next/static ./app/standalone/apps/app/.next/static | |
COPY --from=builder --chown=nextjs:nodejs /app/apps/app/public ./app/standalone/apps/app/public | |
ENV NODE_ENV=production | |
ENV NODE_OPTIONS="--max-old-space-size=8192" | |
USER nextjs | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment