Skip to content

Instantly share code, notes, and snippets.

@Ethaan
Created January 21, 2025 04:52
Show Gist options
  • Save Ethaan/b995215dd44d745e780f13c90b723ef0 to your computer and use it in GitHub Desktop.
Save Ethaan/b995215dd44d745e780f13c90b723ef0 to your computer and use it in GitHub Desktop.
PNPM Workspaces with NextJS
## Assuming you want to build ./services/app that also depends on something like ./packages/ui
FROM node:22.12.0-alpine3.21 AS base
ENV PNPM_HOME="/pnpm"
ENV PATH="$PNPM_HOME:$PATH"
RUN corepack enable
COPY . /app
WORKDIR /app
FROM base AS prod-deps
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --filter=app... --frozen-lockfile --ignore-scripts
FROM base AS builder
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --workspace-root --frozen-lockfile --ignore-scripts
RUN pnpm --filter=app... run build
FROM base AS production_server
ENV NODE_ENV=production
ENV NEXT_TELEMETRY_DISABLED=1
RUN addgroup --system --gid 1001 nodejs && adduser --system --uid 1001 nextjs
COPY --from=builder /app/services/app/public ./public
COPY --from=builder --chown=nextjs:nodejs /app/services/app/.next/standalone ./
COPY --from=builder --chown=nextjs:nodejs /app/services/app/.next/static ./.next/static
USER nextjs
EXPOSE 3000
ENV PORT=3000
ENV HOSTNAME="0.0.0.0"
CMD ["node", "services/app/server.js"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment