Created
May 21, 2024 15:43
-
-
Save dalechyn/2b25548348a2e8430322d277a16f5185 to your computer and use it in GitHub Desktop.
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
FROM node:20-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 | |
# Add a global package | |
RUN pnpm add --global @upleveled/preflight@latest | |
RUN pnpm -g add turbo | |
FROM base AS builder | |
RUN apk add --no-cache libc6-compat | |
RUN apk update | |
# Set working directory | |
WORKDIR /app | |
COPY . . | |
RUN turbo prune --scope=APP_PACKAGE_NAME --docker | |
# Add lockfile and package.json's of isolated subworkspace | |
FROM base AS installer | |
WORKDIR /app | |
# First install the dependencies (as they change less often) | |
COPY .gitignore .gitignore | |
COPY tsconfig.json tsconfig.json | |
COPY --from=builder /app/out/json/ . | |
COPY --from=builder /app/out/pnpm-lock.yaml ./pnpm-lock.yaml | |
# Copy turbo.json as we have some postinstall dependencies for it | |
COPY turbo.json . | |
COPY --from=builder /usr/local/bin/pnpm /usr/local/bin/pnpm | |
# Drop husky install | |
RUN pnpm pkg delete scripts.prepare | |
# Drop postinstall script | |
RUN pnpm pkg delete scripts.postinstall | |
## Install python | |
# RUN apk add g++ make py3-pip | |
# RUN pnpm install | |
# Build the project | |
COPY --from=builder /app/out/full/ . | |
ENV NODE_OPTIONS=--max-old-space-size=8192 | |
RUN turbo run build --filter=APP_PACKAGE_NAME | |
FROM base AS runner | |
WORKDIR /app | |
# Don't run production as root | |
RUN addgroup --system --gid 1001 nodejs | |
RUN adduser --system --uid 1001 nextjs | |
COPY --from=installer /app . | |
# Set the correct permission for prerender cache | |
RUN mkdir .next | |
RUN chown nextjs:nodejs .next | |
# Automatically leverage output traces to reduce image size | |
# https://nextjs.org/docs/advanced-features/output-file-tracing | |
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./ | |
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static | |
# Expose port | |
EXPOSE 3000 | |
WORKDIR apps/APP_PACKAGE_FOLDER_FROM_ROOT | |
CMD ["pnpm", "start"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment