Repository navigation
Expand file tree
/
Copy pathDockerfile
More file actions
118 lines (93 loc) · 3.21 KB
/
Copy pathDockerfile
File metadata and controls
118 lines (93 loc) · 3.21 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# # Base node image
# FROM node:18-alpine AS base
# RUN apk add --no-cache libc6-compat openssl
# WORKDIR /app
# # Dependencies stage
# FROM base AS deps
# # Copy package files
# COPY package.json package-lock.json* ./
# # Install dependencies
# RUN npm ci
# # Builder stage
# FROM base AS builder
# WORKDIR /app
# COPY --from=deps /app/node_modules ./node_modules
# COPY . .
# # Set up environment variables for build
# ARG DATABASE_URL
# ENV DATABASE_URL=$DATABASE_URL
# ARG NEXT_PUBLIC_BASE_URL
# ENV NEXT_PUBLIC_BASE_URL=$NEXT_PUBLIC_BASE_URL
# # Generate Prisma Client
# RUN npx prisma generate
# # Build application
# RUN npm run build
# # Runner stage
# FROM base AS runner
# WORKDIR /app
# # Set environment variables
# ENV NODE_ENV=production
# ENV NEXT_TELEMETRY_DISABLED 1
# # Create non-root user
# RUN addgroup --system --gid 1001 nodejs && \
# adduser --system --uid 1001 nextjs
# # Create start script first
# RUN echo '#!/bin/sh\nnpx prisma migrate deploy\nnode server.js' > start.sh && \
# chmod +x start.sh
# # Copy necessary files from builder and set ownership
# COPY --from=builder --chown=nextjs:nodejs /app/next.config.js ./
# COPY --from=builder --chown=nextjs:nodejs /app/public ./public
# COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
# COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
# COPY --from=builder --chown=nextjs:nodejs /app/prisma ./prisma
# COPY --from=builder --chown=nextjs:nodejs /app/node_modules/.prisma ./node_modules/.prisma
# COPY --from=builder --chown=nextjs:nodejs /app/node_modules/@prisma ./node_modules/@prisma
# # Set ownership of start script after creation
# RUN chown nextjs:nodejs start.sh
# # Switch to non-root user after all operations requiring root are done
# USER nextjs
# # Expose port
# EXPOSE 3000
# # Set the entrypoint
# ENTRYPOINT ["./start.sh"]
# Base node image
FROM node:18-alpine AS base
RUN apk add --no-cache libc6-compat openssl
WORKDIR /app
# Dependencies stage
FROM base AS deps
COPY package.json package-lock.json* ./
RUN npm ci
# Builder stage
FROM base AS builder
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY . .
# Set up environment variables for build
ARG DATABASE_URL
ENV DATABASE_URL=$DATABASE_URL
ARG NEXT_PUBLIC_BASE_URL
ENV NEXT_PUBLIC_BASE_URL=$NEXT_PUBLIC_BASE_URL
# Generate Prisma Client and build
RUN npx prisma generate
RUN npm run build
# Runner stage
FROM base AS runner
WORKDIR /app
ENV NODE_ENV=production
ENV NEXT_TELEMETRY_DISABLED 1
# Create non-root user
RUN addgroup --system --gid 1001 nodejs && \
adduser --system --uid 1001 nextjs
# Copy necessary files
COPY --from=builder --chown=nextjs:nodejs /app/next.config.js ./
COPY --from=builder --chown=nextjs:nodejs /app/public ./public
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
COPY --from=builder --chown=nextjs:nodejs /app/prisma ./prisma
COPY --from=builder --chown=nextjs:nodejs /app/node_modules/.prisma ./node_modules/.prisma
COPY --from=builder --chown=nextjs:nodejs /app/node_modules/@prisma ./node_modules/@prisma
USER nextjs
EXPOSE 3000
# Run migrations and start server
CMD npx prisma migrate deploy && node server.js