-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
59 lines (40 loc) · 1.33 KB
/
Copy pathDockerfile
File metadata and controls
59 lines (40 loc) · 1.33 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
# Stage 1: Install dependencies
FROM node:26-alpine AS deps
RUN npm install -g pnpm
WORKDIR /app
# Copy package files for dependency installation
COPY package.json pnpm-lock.yaml ./
# Install all dependencies (including devDependencies for build)
RUN --mount=type=cache,id=pnpm,target=/root/.local/share/pnpm/store \
pnpm install --frozen-lockfile
# Stage 2: Build the application
FROM node:26-alpine AS build
RUN npm install -g pnpm
WORKDIR /app
# Copy dependencies from deps stage
COPY --from=deps /app/node_modules ./node_modules
# Copy source files
COPY . .
# Build the application
RUN pnpm build
# Prune dev dependencies for production
RUN --mount=type=cache,id=pnpm,target=/root/.local/share/pnpm/store \
pnpm prune --prod
# Stage 3: Production runtime
FROM node:26-alpine AS runtime
# Create non-root user for security
RUN addgroup --system --gid 1001 nodejs && \
adduser --system --uid 1001 sveltekit
WORKDIR /app
# Copy built application and production dependencies
COPY --from=build --chown=sveltekit:nodejs /app/build ./build
COPY --from=build --chown=sveltekit:nodejs /app/node_modules ./node_modules
COPY --from=build --chown=sveltekit:nodejs /app/package.json ./
# Set environment variables
ENV NODE_ENV=production
ENV PORT=3000
ENV HOST=0.0.0.0
# Switch to non-root user
USER sveltekit
EXPOSE 3000
CMD ["node", "build"]