2024-10-04 20:11:55 +00:00
|
|
|
FROM node:20-alpine3.17 AS base
|
2024-10-04 20:07:09 +00:00
|
|
|
|
|
|
|
# Install pnpm
|
|
|
|
RUN npm install -g pnpm
|
|
|
|
ENV PNPM_HOME=/usr/local/bin
|
2024-10-04 19:35:44 +00:00
|
|
|
|
2024-10-04 20:21:08 +00:00
|
|
|
FROM base AS builder
|
2024-10-04 19:35:44 +00:00
|
|
|
WORKDIR /app
|
|
|
|
|
2024-10-04 19:38:36 +00:00
|
|
|
# Copy website package and lock files only
|
2024-10-04 20:07:09 +00:00
|
|
|
COPY package.json* pnpm-lock.yaml* pnpm-workspace.yaml* ./
|
2024-10-04 20:21:57 +00:00
|
|
|
COPY website ./website
|
2024-10-04 19:35:44 +00:00
|
|
|
|
2024-10-04 20:23:47 +00:00
|
|
|
ARG GIT_REV
|
|
|
|
ENV GIT_REV=${GIT_REV}
|
|
|
|
|
2024-10-04 20:21:08 +00:00
|
|
|
RUN pnpm install --filter website
|
|
|
|
RUN pnpm run build:website
|
2024-10-04 19:35:44 +00:00
|
|
|
|
|
|
|
# Final stage for running the app
|
|
|
|
FROM base AS runner
|
|
|
|
WORKDIR /app
|
|
|
|
|
|
|
|
# Set environment variables for production
|
|
|
|
ENV NODE_ENV=production
|
|
|
|
ENV NEXT_TELEMETRY_DISABLED=1
|
|
|
|
|
|
|
|
# Create system user and group for running the app
|
|
|
|
RUN addgroup --system --gid 1001 nodejs
|
|
|
|
RUN adduser --system --uid 1001 nextjs
|
|
|
|
|
|
|
|
# Ensure necessary directories exist and are writable
|
2024-10-04 20:13:15 +00:00
|
|
|
RUN mkdir -p /app/website/.next
|
2024-10-04 19:38:36 +00:00
|
|
|
RUN chown nextjs:nodejs /app/website/.next
|
2024-10-04 19:35:44 +00:00
|
|
|
|
|
|
|
# Copy built files from the builder stage
|
2024-10-04 19:38:36 +00:00
|
|
|
COPY --from=builder --chown=nextjs:nodejs /app/website/.next ./website/.next
|
|
|
|
COPY --from=builder --chown=nextjs:nodejs /app/website/public ./website/public
|
|
|
|
COPY --from=builder --chown=nextjs:nodejs /app/website/package.json ./website/package.json
|
|
|
|
COPY --from=builder --chown=nextjs:nodejs /app/website/next.config.mjs ./website/next.config.mjs
|
2024-10-04 19:35:44 +00:00
|
|
|
|
|
|
|
# Switch to non-root user
|
|
|
|
USER nextjs
|
|
|
|
|
|
|
|
# Expose the app port and start it
|
|
|
|
EXPOSE 3000
|
|
|
|
ENV HOSTNAME="0.0.0.0"
|
|
|
|
ENV PORT=3000
|
|
|
|
|
2024-10-04 20:21:08 +00:00
|
|
|
CMD ["pnpm", "start:website"]
|