-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathDockerfile
More file actions
72 lines (61 loc) · 2.85 KB
/
Copy pathDockerfile
File metadata and controls
72 lines (61 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
# syntax=docker/dockerfile:1
# ---------------------------------------------------------------------------
# MonMap webapp — self-hosted image (Oracle Cloud + Dokploy).
#
# Build context is the MONOREPO ROOT (not packages/webapp) so pnpm can
# resolve the workspace deps `@monmap/db` and `@monmap/scraper`, which the
# webapp imports as raw TS and Next compiles via `transpilePackages`.
#
# Only NEXT_PUBLIC_* vars are needed at build time (they get baked into the
# client bundle). The DB is NOT touched during `next build` — no SSG/sitemap
# query — so DATABASE_URL is a *runtime*-only var, set in Dokploy.
# ---------------------------------------------------------------------------
FROM node:22-slim AS base
ENV PNPM_HOME="/pnpm"
ENV PATH="$PNPM_HOME:$PATH"
# Corepack reads the `packageManager` field in package.json to pin the exact
# pnpm version (must match the lockfile-generating version, else frozen
# installs fail on config mismatch). Auto-download it without prompting.
ENV COREPACK_ENABLE_DOWNLOAD_PROMPT=0
RUN corepack enable
WORKDIR /app
# ---- deps + build -------------------------------------------------------
FROM base AS build
# The root `prepare` script runs husky, which needs a .git dir we don't
# ship. HUSKY=0 makes it a no-op during the image build.
ENV HUSKY=0
# Copy the whole workspace and install with a cached pnpm store.
COPY . .
RUN --mount=type=cache,id=pnpm,target=/pnpm/store \
pnpm install --frozen-lockfile
# NEXT_PUBLIC_* must exist at build time — they're inlined into the client
# bundle. Pass them via --build-arg (Dokploy: Build → Build Args).
ARG NEXT_PUBLIC_SITE_URL
ARG NEXT_PUBLIC_AUTH_URL
ARG NEXT_PUBLIC_POSTHOG_PROJECT_TOKEN
ARG NEXT_PUBLIC_POSTHOG_HOST
ENV NEXT_PUBLIC_SITE_URL=$NEXT_PUBLIC_SITE_URL \
NEXT_PUBLIC_AUTH_URL=$NEXT_PUBLIC_AUTH_URL \
NEXT_PUBLIC_POSTHOG_PROJECT_TOKEN=$NEXT_PUBLIC_POSTHOG_PROJECT_TOKEN \
NEXT_PUBLIC_POSTHOG_HOST=$NEXT_PUBLIC_POSTHOG_HOST \
NEXT_TELEMETRY_DISABLED=1
RUN pnpm --filter webapp build
# ---- runtime ------------------------------------------------------------
FROM node:22-slim AS runner
WORKDIR /app
ENV NODE_ENV=production \
NEXT_TELEMETRY_DISABLED=1 \
PORT=3000 \
HOSTNAME=0.0.0.0
# Run as a non-root user.
RUN groupadd --system --gid 1001 nodejs \
&& useradd --system --uid 1001 --gid nodejs nextjs
# `output: "standalone"` + `outputFileTracingRoot` = repo root means the
# standalone tree mirrors the monorepo layout: server.js sits under
# packages/webapp/. Static assets and public/ aren't traced, so copy them.
COPY --from=build --chown=nextjs:nodejs /app/packages/webapp/.next/standalone ./
COPY --from=build --chown=nextjs:nodejs /app/packages/webapp/.next/static ./packages/webapp/.next/static
COPY --from=build --chown=nextjs:nodejs /app/packages/webapp/public ./packages/webapp/public
USER nextjs
EXPOSE 3000
CMD ["node", "packages/webapp/server.js"]