-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile.prod
More file actions
72 lines (53 loc) · 1.9 KB
/
Dockerfile.prod
File metadata and controls
72 lines (53 loc) · 1.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# Production Dockerfile for CITZ SBC Queue Management
# Multi-stage build for optimal production image size
# Build stage
ARG NODE_TAG=22-bullseye-slim
FROM node:${NODE_TAG} AS builder
# Set working directory
WORKDIR /workspace
# Set environment for build
ENV NODE_ENV=production
ENV NEXT_TELEMETRY_DISABLED=1
# Copy package files for dependency installation
COPY package.json ./
# Install only production dependencies needed for build
RUN npm i && npm cache clean --force
# Copy all source files
COPY . .
# Generate prisma (with dummy DATABASE_URL for CI build)
RUN DATABASE_URL="postgresql://dummy:dummy@localhost:5432/dummy" npx prisma generate
# Build the application
RUN npm run build
# Production stage
FROM node:${NODE_TAG} AS production
# Install security updates and dumb-init for proper signal handling
RUN apt-get update && apt-get install -y \
dumb-init \
&& apt-get upgrade -y \
&& rm -rf /var/lib/apt/lists/* \
&& apt-get clean
# Create non-root user for security
RUN groupadd --gid 1001 nodejs \
&& useradd --uid 1001 --gid nodejs --shell /bin/bash --create-home nextjs
# Set working directory
WORKDIR /workspace
# Set production environment
ENV NODE_ENV=production
ENV NEXT_TELEMETRY_DISABLED=1
ENV PORT=3000
# Copy built application and dependencies from builder stage
COPY --from=builder --chown=nextjs:nodejs /workspace/.next ./.next
COPY --from=builder --chown=nextjs:nodejs /workspace/public ./public
COPY --from=builder --chown=nextjs:nodejs /workspace/node_modules ./node_modules
# Copy necessary configuration files
COPY --chown=nextjs:nodejs package.json ./
COPY --chown=nextjs:nodejs next.config.ts ./
COPY --from=builder --chown=nextjs:nodejs /workspace/postcss.config.mjs ./postcss.config.mjs
# Switch to non-root user
USER nextjs
# Expose port
EXPOSE 3000
# Use dumb-init to handle signals properly
ENTRYPOINT ["dumb-init", "--"]
# Start the application
CMD ["npm", "start"]