-
-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathDockerfile
More file actions
82 lines (63 loc) · 2.85 KB
/
Dockerfile
File metadata and controls
82 lines (63 loc) · 2.85 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
FROM node:24-alpine AS base
# ---- deps for build (includes dev deps) ----
FROM base AS deps
RUN apk add --no-cache libc6-compat
WORKDIR /app
COPY package.json package-lock.json* ./
RUN npm ci
# ---- build ----
FROM base AS builder
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY . .
# Create data directory for build time so database connection doesn't fail
RUN mkdir -p /app/data
ARG APP_VERSION
ENV APP_VERSION=$APP_VERSION
ENV NEXT_TELEMETRY_DISABLED=1
# URL_BASE_PATH must be provided at BUILD TIME so that Next.js can bake the
# correct prefix into asset URLs (/_next/static/...). Pass it via:
# docker build --build-arg URL_BASE_PATH=/swipe .
# The default is empty (app served at the root path).
ARG URL_BASE_PATH=""
ENV URL_BASE_PATH=$URL_BASE_PATH
RUN npm run build
# ---- runtime ----
FROM base AS runner
WORKDIR /app
ENV NODE_ENV=production
ENV NEXT_TELEMETRY_DISABLED=1
ENV PORT=4321
ENV HOSTNAME="0.0.0.0"
# Carry the base path into the runner so the healthcheck resolves correctly.
# This is set at build time and baked into Next.js asset URLs.
ARG URL_BASE_PATH=""
ENV URL_BASE_PATH=$URL_BASE_PATH
RUN apk add --no-cache libc6-compat curl su-exec
RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs
# sqlite volume dir
RUN mkdir -p /app/data && chown nextjs:nodejs /app/data
# Next standalone output
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
# Drizzle files needed at runtime for migrations
COPY --from=builder --chown=nextjs:nodejs /app/src/db/migrations ./src/db/migrations
COPY --from=builder --chown=nextjs:nodejs /app/src/db/migrate.js ./src/db/migrate.js
COPY --from=builder --chown=nextjs:nodejs /app/scripts/ensure-auth-secret.cjs ./scripts/ensure-auth-secret.cjs
# Note: drizzle-orm and @libsql/client are needed by migrate.js.
# Next.js standalone usually bundles deps, but migrate.js is run outside that bundle.
# We copy them from the builder to ensure they are available for the migration script.
COPY --from=builder --chown=nextjs:nodejs /app/node_modules/drizzle-orm ./node_modules/drizzle-orm
COPY --from=builder --chown=nextjs:nodejs /app/node_modules/@libsql ./node_modules/@libsql
COPY --from=builder --chown=nextjs:nodejs /app/node_modules/dotenv ./node_modules/dotenv
COPY docker-entrypoint.sh /usr/local/bin/
RUN chmod +x /usr/local/bin/docker-entrypoint.sh
ENTRYPOINT ["docker-entrypoint.sh"]
EXPOSE 4321
# Healthcheck to verify the app is running
HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=3 \
CMD curl -f http://localhost:4321${URL_BASE_PATH:-}/api/health || exit 1
# Ensure auth secret, run migrations, then start Next standalone server
CMD ["sh", "-c", "node src/db/migrate.js && node scripts/ensure-auth-secret.cjs && node server.js"]