Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: update Dockerfile #1372

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 30 additions & 26 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
FROM node:18-alpine AS build
FROM node:18-alpine AS base

FROM base AS deps
RUN apk add --no-cache libc6-compat

ARG REDIS_URL
ARG NEXT_PUBLIC_SEGMENT_WRITE_KEY
Expand All @@ -9,26 +12,6 @@ ARG NODE_ENV=production
ARG X_API_KEY
ARG RELEASE_TAG_NAME

WORKDIR /app

COPY . .

RUN npm install -g [email protected]
RUN npm install [email protected]
RUN pnpm i
RUN pnpm build

FROM node:18-alpine

ARG REDIS_URL
ARG NEXT_PUBLIC_SEGMENT_WRITE_KEY
ARG SENTRY_AUTH_TOKEN
ARG SENTRY_DSN
ARG SENTRY_LOG_LEVEL=warn
ARG NODE_ENV=production

# Set ENVs so they persist after image is built
ENV NEXT_SHARP_PATH=/tmp/node_modules/sharp
ENV REDIS_URL=${REDIS_URL}
ENV NEXT_PUBLIC_SEGMENT_WRITE_KEY=${SEGMENT_WRITE_KEY}
ENV SENTRY_AUTH_TOKEN=${SENTRY_AUTH_TOKEN}
Expand All @@ -40,11 +23,32 @@ ENV RELEASE_TAG_NAME=${RELEASE_TAG_NAME}

WORKDIR /app

COPY --from=build /app/next.config.js /app/next.config.js
COPY --from=build /app/public /app/public
COPY --from=build /app/.next/static /app/.next/static
COPY --from=build /app/.next/standalone /app
COPY package.json pnpm-lock.yaml* ./
RUN npm install -g [email protected] && pnpm i


FROM base AS builder
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY . .
RUN pnpm build

FROM base AS runner
WORKDIR /app

RUN addgroup -g 1001 -S nodejs
RUN adduser -S nextjs -u 1001

COPY --from=builder /app/public ./public

COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static

USER nextjs

EXPOSE 3000
CMD [ "node", "server.js" ]

ENV PORT 3000
ENV HOSTNAME localhost

CMD ["node", "server.js"]
Loading