-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
86 lines (63 loc) · 2.38 KB
/
Copy pathDockerfile
File metadata and controls
86 lines (63 loc) · 2.38 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
# Stage 1: deps
FROM node:22-bookworm-slim AS deps
# Native module build dependencies
RUN apt-get update \
&& apt-get install -y --no-install-recommends python3 make g++ \
&& rm -rf /var/lib/apt/lists/*
WORKDIR /app
COPY package.json package-lock.json ./
ENV npm_config_build_from_source=true
RUN npm ci
RUN npm rebuild sqlite3 --build-from-source
# Stage 2: builder
FROM node:22-bookworm-slim AS builder
WORKDIR /app
ARG APP_VERSION=dev
ARG APP_COMMIT_SHA=local
COPY --from=deps /app/node_modules ./node_modules
COPY . .
ENV NEXT_TELEMETRY_DISABLED=1
ENV APP_VERSION=$APP_VERSION
ENV APP_COMMIT_SHA=$APP_COMMIT_SHA
ENV NEXT_PUBLIC_APP_VERSION=$APP_VERSION
ENV NEXT_PUBLIC_APP_COMMIT_SHA=$APP_COMMIT_SHA
RUN npm run build
# Stage 3: runner
FROM node:22-bookworm-slim AS runner
WORKDIR /app
ENV NODE_ENV=production
ENV NEXT_TELEMETRY_DISABLED=1
ARG APP_VERSION=dev
ARG APP_COMMIT_SHA=local
ENV APP_VERSION=$APP_VERSION
ENV APP_COMMIT_SHA=$APP_COMMIT_SHA
ENV NEXT_PUBLIC_APP_VERSION=$APP_VERSION
ENV NEXT_PUBLIC_APP_COMMIT_SHA=$APP_COMMIT_SHA
# iputils-ping is required for ping-type monitors. Debian's package grants
# the binary cap_net_raw via setcap, so it works for the non-root nextjs user.
RUN apt-get update \
&& apt-get install -y --no-install-recommends iputils-ping \
&& rm -rf /var/lib/apt/lists/*
RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs
# Copy standalone build
COPY --from=builder /app/public ./public
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
# Migration SQL files are read from disk at runtime (not bundled by the
# Next.js tracer), so they must be copied explicitly. The migrate CLI is
# included too, so `docker exec` can run status/up/down inside the container.
COPY --from=builder --chown=nextjs:nodejs /app/migrations ./migrations
COPY --from=builder --chown=nextjs:nodejs /app/scripts ./scripts
# The Next standalone output already includes the sqlite/sqlite3 runtime modules
# required by the app, so no extra native dependency copies are needed here.
# Data directory for SQLite
RUN mkdir -p /data && chown nextjs:nodejs /data
USER nextjs
# Environment variables (override at runtime)
ENV PORT=4000
ENV HOSTNAME=0.0.0.0
ENV DATABASE_PATH=/data/logs.db
EXPOSE 4000
VOLUME ["/data"]
CMD ["node", "server.js"]