-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
75 lines (56 loc) · 2.12 KB
/
Copy pathDockerfile
File metadata and controls
75 lines (56 loc) · 2.12 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
FROM node:24.17.0-alpine AS dependencies
# Set working directory
WORKDIR /app
# Copy package-related files first to leverage Docker's caching mechanism
COPY package.json package-lock.json* ./
# Install project dependencies with frozen lockfile for reproducible builds
RUN --mount=type=cache,target=/root/.npm \
npm ci --prefer-offline --no-audit --no-fund;
FROM node:24.17.0-alpine AS builder
# Set working directory
WORKDIR /app
# Copy project dependencies from dependencies stage
COPY --from=dependencies /app/node_modules ./node_modules
# Copy application source code
COPY . .
# Accept NEXT_PUBLIC_ env vars as build args so they are baked in at build time
ARG NEXT_PUBLIC_APP_URL \
NEXT_PUBLIC_BETTER_AUTH_URL \
NEXT_PUBLIC_INFINITY_API_URL \
NEXT_PUBLIC_INFINITY_API_TIMEOUT
# Set build stage environment variables
ENV NODE_ENV=production \
CI=1 \
# Disable telemetry during the build.
NEXT_TELEMETRY_DISABLED=1 \
NEXT_PUBLIC_APP_URL=${NEXT_PUBLIC_APP_URL} \
NEXT_PUBLIC_BETTER_AUTH_URL=${NEXT_PUBLIC_BETTER_AUTH_URL} \
NEXT_PUBLIC_INFINITY_API_URL=${NEXT_PUBLIC_INFINITY_API_URL} \
NEXT_PUBLIC_INFINITY_API_TIMEOUT=${NEXT_PUBLIC_INFINITY_API_TIMEOUT}
# Build Next.js application
RUN --mount=type=cache,target=/app/.next/cache \
npm run build
FROM oven/bun:1.3.13 AS runner
# Set working directory
WORKDIR /app
# Set production environment variables
ENV NODE_ENV=production \
PORT=3000 \
HOSTNAME="[::]" \
# Disable telemetry during the run time.
NEXT_TELEMETRY_DISABLED=1
# Copy production assets
COPY --from=builder --chown=bun:bun /app/public ./public
# Set the correct permission for prerender cache
RUN mkdir .next && \
chown bun:bun .next
# Automatically leverage output traces to reduce image size
# https://nextjs.org/docs/advanced-features/output-file-tracing
COPY --from=builder --chown=bun:bun /app/.next/standalone ./
COPY --from=builder --chown=bun:bun /app/.next/static ./.next/static
# Switch to non-root user for security best practices
USER bun
# Expose port 3000 to allow HTTP traffic
EXPOSE 3000
# Start Next.js standalone server with Bun
CMD ["bun", "server.js"]