Skip to content

Commit

Permalink
updated dockerfile
Browse files Browse the repository at this point in the history
  • Loading branch information
gnehs committed May 13, 2024
1 parent acae905 commit bd0fef3
Showing 1 changed file with 23 additions and 6 deletions.
29 changes: 23 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,42 @@ FROM node:22-alpine as base

ENV PNPM_HOME="/var/lib/pnpm"
ENV PATH="$PNPM_HOME:$PATH"

RUN corepack enable
RUN apk add --no-cache tzdata
ENV TZ=Asia/Taipei
WORKDIR /app

# Install dependencies based on the preferred package manager
FROM base AS deps
COPY package.json pnpm-lock.yaml ./
RUN pnpm i --frozen-lockfile

RUN pnpm install --frozen-lockfile
# Rebuild the source code only when needed
FROM base AS builder
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY . .
RUN pnpm run build
RUN pnpm dlx prisma generate

RUN npx prisma generate
RUN pnpm build

RUN addgroup --system --gid 1001 nodejs && \
adduser --system --uid 1001 nextjs
# Production image, copy all the files and run next
FROM base AS runner
WORKDIR /app
ENV NODE_ENV production
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
USER nextjs

EXPOSE 3000
ENV PORT 3000
ENV HOSTNAME "0.0.0.0"

CMD pnpm start
CMD ["node", "server.js"]

0 comments on commit bd0fef3

Please sign in to comment.