2024-10-04 19:35:44 +00:00
|
|
|
# Base image with Node.js 20 and pnpm
|
|
|
|
FROM fascinated/docker-images:nodejs_20_with_pnpm AS base
|
|
|
|
|
|
|
|
# Install build tools for canvas (Python, GCC, etc.)
|
|
|
|
FROM base AS deps
|
|
|
|
RUN apk add --no-cache python3 make g++ gcc pkgconfig pixman cairo-dev libjpeg-turbo-dev pango-dev giflib-dev
|
|
|
|
WORKDIR /app
|
|
|
|
|
2024-10-04 19:38:36 +00:00
|
|
|
# Copy website package and lock files only
|
2024-10-04 19:42:29 +00:00
|
|
|
COPY package.json* /pnpm-lock.yaml* ./
|
|
|
|
RUN pnpm install --frozen-lockfile --quiet --filter website
|
2024-10-04 19:35:44 +00:00
|
|
|
|
|
|
|
# Build stage
|
|
|
|
FROM base AS builder
|
|
|
|
WORKDIR /app
|
|
|
|
|
|
|
|
# Copy node_modules from deps stage
|
|
|
|
COPY --from=deps /app/node_modules ./node_modules
|
|
|
|
|
2024-10-04 19:38:36 +00:00
|
|
|
COPY ./website ./website
|
2024-10-04 19:35:44 +00:00
|
|
|
|
|
|
|
# Install runtime dependencies
|
|
|
|
RUN apk add --no-cache cairo pango libjpeg-turbo giflib
|
|
|
|
|
2024-10-04 19:38:36 +00:00
|
|
|
# Build the website app
|
|
|
|
WORKDIR /app/website
|
2024-10-04 19:35:44 +00:00
|
|
|
RUN pnpm run build
|
|
|
|
|
|
|
|
# Final stage for running the app
|
|
|
|
FROM base AS runner
|
|
|
|
WORKDIR /app
|
|
|
|
|
|
|
|
# Install runtime dependencies
|
|
|
|
RUN apk add --no-cache cairo pango libjpeg-turbo giflib
|
|
|
|
|
|
|
|
# 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 19:38:36 +00:00
|
|
|
RUN mkdir /app/website/.next
|
|
|
|
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/node_modules ./website/node_modules
|
|
|
|
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
|
|
|
|
|
|
|
|
CMD ["pnpm", "start"]
|