-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
116 lines (87 loc) · 2.42 KB
/
Dockerfile
File metadata and controls
116 lines (87 loc) · 2.42 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
ARG BASE_IMAGE=node:25-alpine
##
# builder
##
FROM ${BASE_IMAGE} AS builder
# dependencies for native modules (better-sqlite3)
RUN apk add --no-cache \
python3 \
make \
g++ \
cairo-dev \
jpeg-dev \
pango-dev \
giflib-dev
WORKDIR /app
ENV NEXT_TELEMETRY_DISABLED=1
RUN mkdir -p /app/data
# dependency files
COPY package*.json ./
COPY tsconfig.json ./
# dependencies
RUN npm ci --prefer-offline --no-audit
# source code
COPY src ./src
COPY scripts ./scripts
COPY next.config.ts ./
COPY postcss.config.mjs ./
COPY drizzle.config.ts ./
# build app
RUN npm run build
# compile seed script to CJS for Docker runtime (no tsx needed)
RUN npx esbuild src/lib/db/seed.ts \
--bundle \
--platform=node \
--outfile=scripts/docker-seed.cjs \
--external:better-sqlite3 \
--external:argon2 \
--format=cjs
##
# database
##
FROM ${BASE_IMAGE} AS db-init
RUN apk add --no-cache \
python3 \
make \
g++
WORKDIR /app
COPY package*.json ./
RUN npm ci --prefer-offline --no-audit --only=production
COPY src/lib/db ./src/lib/db
COPY drizzle.config.ts ./
RUN mkdir -p /app/data
##
# runtime
##
FROM ${BASE_IMAGE} AS runner
# runtime dependencies only
RUN apk add --no-cache dumb-init
WORKDIR /app
ENV NODE_ENV=production
ENV PORT=3000
ENV HOST=0.0.0.0
# non-root
RUN addgroup -g 1001 -S nodejs && \
adduser -S nextjs -u 1001
# copy built application from builder
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
# copy database initialization from db-init stage
COPY --from=db-init --chown=nextjs:nodejs /app/node_modules ./node_modules
COPY --from=db-init --chown=nextjs:nodejs /app/src/lib/db ./src/lib/db
COPY --from=builder --chown=nextjs:nodejs /app/scripts ./scripts
COPY --from=db-init --chown=nextjs:nodejs /app/drizzle.config.ts ./
# create data directory for SQLite database
RUN mkdir -p /app/data && \
chown -R nextjs:nodejs /app/data
# healthcheck
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
CMD wget --quiet --tries=1 --spider http://localhost:${PORT}/ || exit 1
EXPOSE ${PORT}
# dumb-init to handle signals properly
ENTRYPOINT ["/usr/bin/dumb-init", "--"]
# non-root user
USER nextjs
# start the Next.js application
# wrapper script to ensure binding to HOST:PORT
CMD ["sh", "-c", "node ./scripts/docker-seed.cjs 2>/dev/null || true && node ./scripts/start-server.js"]