forked from credebl/studio
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
57 lines (42 loc) · 1.25 KB
/
Dockerfile
File metadata and controls
57 lines (42 loc) · 1.25 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
# ---------------------
# Build stage
# ---------------------
FROM node:22-alpine AS build
# Enable corepack and install a specific pnpm version securely
RUN corepack enable && corepack prepare pnpm@10.3.0 --activate
# Set working directory
WORKDIR /app
# Copy only necessary files
COPY package.json pnpm-lock.yaml ./
# Install dependencies
# sonarcloud: disable=ShellScriptExecutionRisk
RUN pnpm install
# Copy the rest of the source code
COPY . .
# COPY .next ./.next
# COPY public ./public
# COPY node_modules ./node_modules
# Build the Next.js application
RUN pnpm run build
# ---------------------
# Production stage
# ---------------------
FROM node:22-alpine AS production
# Create a non-root user
# RUN groupadd -r appgroup && useradd -r -g appgroup appuser
RUN addgroup -S appgroup && adduser -S appuser -G appgroup
# Set working directory
WORKDIR /app
# Copy necessary build artifacts from build stage
COPY --from=build /app/package.json ./
COPY --from=build /app/.next ./.next
COPY --from=build /app/public ./public
COPY --from=build /app/node_modules ./node_modules
# Change ownership to non-root user
RUN chown -R appuser:appgroup /app
# Switch to non-root user
USER appuser
# Expose port
EXPOSE 3000
# Start the Next.js application
CMD ["npm", "start"]