Repository navigation
Expand file tree
/
Copy pathDockerfile
More file actions
117 lines (107 loc) · 5.99 KB
/
Copy pathDockerfile
File metadata and controls
117 lines (107 loc) · 5.99 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
117
# syntax=docker/dockerfile:1.7
FROM oven/bun:1.4.4-slim@sha256:1846adf22496bd711036aae8be147e57bdebbaea2e5264e3e0b5af1db187d9a4 AS base
# Build context is the monorepo root (see deploy-kit.yml + scripts/deploy-prod.sh).
# This is required because the workspace lockfile lives at the root, not under
# packages/kit/, and Bun resolves workspace deps (`@hyodotdev/openiap-client-protocol` etc.)
# via the root `package.json` `workspaces` field.
# --- Install deps --------------------------------------------------------
FROM base AS deps
WORKDIR /app
# Copy only what bun install needs to maximize layer caching: root manifest +
# lockfile + every workspace package.json (so Bun can plan the install graph).
COPY package.json bun.lock ./
COPY packages/kit/package.json ./packages/kit/
COPY specs/client/package.json ./specs/client/
COPY packages/apple/package.json ./packages/apple/
COPY packages/google/package.json ./packages/google/
COPY packages/docs/package.json ./packages/docs/
# `mcp-server` is a workspace member (added in PR #124 (https://github.com/hyodotdev/openiap/pull/124)). Without
# its package.json bun's workspace resolver disagrees with the
# root lockfile and `--frozen-lockfile` rejects the install with
# "lockfile had changes, but lockfile is frozen".
COPY packages/mcp-server/package.json ./packages/mcp-server/
COPY packages/conformance/package.json ./packages/conformance/
COPY packages/cli/package.json ./packages/cli/
COPY specs/commerce-protocol/package.json ./specs/commerce-protocol/
RUN bun install --frozen-lockfile --filter @hyodotdev/openiap-kit
# --- Build the unified app (Vite SPA + compiled Bun server) --------------
FROM base AS builder
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY package.json bun.lock ./
COPY packages/kit ./packages/kit
COPY packages/mcp-server ./packages/mcp-server
COPY packages/cli ./packages/cli
# The MCP client imports the client specification's public kit-api subpath.
COPY specs/client ./specs/client
# Kit runtime code imports @hyodotdev/openiap-commerce-protocol (generated schemas,
# binding manifest, capability descriptor); without the sources the workspace
# symlink dangles inside the image and only inside the image.
COPY specs/commerce-protocol ./specs/commerce-protocol
# Bun workspaces install some deps under each package's
# local node_modules (e.g. `vite`, `@vitejs/plugin-react`) instead of
# fully hoisting. Pull kit's local node_modules from the deps stage
# AFTER the source COPY so it isn't clobbered. Without this the
# build fails with `vite: command not found` (PR #124 (https://github.com/hyodotdev/openiap/pull/124) review
# fallout).
COPY --from=deps /app/packages/kit/node_modules ./packages/kit/node_modules
COPY --from=deps /app/packages/mcp-server/node_modules ./packages/mcp-server/node_modules
WORKDIR /app/packages/kit
ARG VITE_KIT_CONVEX_URL
ENV VITE_KIT_CONVEX_URL=${VITE_KIT_CONVEX_URL}
# Client-side Sentry DSN baked into the SPA bundle. Technically public
# (any visitor can read it out of the JS), but we still route it through
# a build arg instead of committing to the repo so it rotates cleanly.
ARG VITE_KIT_SENTRY_DSN
ENV VITE_KIT_SENTRY_DSN=${VITE_KIT_SENTRY_DSN}
# Mixpanel project token is public by design and baked into the SPA when set,
# but pass it via BuildKit secret so Docker does not flag TOKEN-named ARG/ENV.
# BuildKit secret values are not part of the layer cache key, so a non-secret
# fingerprint of the token is passed as a build arg purely to bust the
# `bun run build:all` cache when the token rotates — without it, GHA / Fly's
# remote builder would happily reuse the prior layer and ship a stale token.
ARG VITE_KIT_MIXPANEL_TOKEN_HASH=
# VITE_KIT_MIXPANEL_TOKEN_HASH must be expanded inside the RUN command
# string for BuildKit to fold it into the layer cache key — an unused
# ARG does not affect caching, so the rotation-busting effect would
# silently disappear if we only declared it above. The build script
# does not consume the hash; it only exists as a cache fingerprint.
RUN --mount=type=secret,id=VITE_KIT_MIXPANEL_TOKEN,required=false \
VITE_KIT_MIXPANEL_TOKEN_HASH="${VITE_KIT_MIXPANEL_TOKEN_HASH}" \
VITE_KIT_MIXPANEL_TOKEN="$(cat /run/secrets/VITE_KIT_MIXPANEL_TOKEN 2>/dev/null || true)" \
bun run build:all
# Remove the zlib overlay when Distroless ships the fix for CVE-2026-85091.
FROM debian:trixie-slim@sha256:a72b4433de1cf7d6bae0c4cee74d0547f58601a643b3375f070c51600d63b6b2 AS zlib-security
WORKDIR /tmp
ARG TARGETARCH
ADD https://snapshot.debian.org/archive/debian-security/20261107T075304Z/pool/updates/main/z/zlib/zlib1g_1.3.dfsg+really1.3.1-1+deb13u1_${TARGETARCH}.deb zlib1g.deb
RUN --network=none set -eux; \
case "$TARGETARCH" in \
amd64) checksum=8c27c342230503b73dfde629642c3b352e87b554e06d60cf58772f236a305ceb ;; \
arm64) checksum=0e41b3d7ad8ad7fcd36dd4d61ca91a70018478fc4af652e044f4be770784ddff ;; \
*) exit 1 ;; \
esac; \
printf '%s zlib1g.deb\n' "$checksum" | sha256sum -c -; \
dpkg-deb --extract zlib1g.deb /zlib; \
mkdir -p /zlib/var/lib/dpkg/status.d; \
dpkg-deb --field zlib1g.deb > /zlib/var/lib/dpkg/status.d/zlib1g; \
dpkg-deb --control zlib1g.deb control; \
cp control/md5sums /zlib/var/lib/dpkg/status.d/zlib1g.md5sums
# --- Runtime image (single binary + static assets) -----------------------
FROM gcr.io/distroless/base-debian13:nonroot@sha256:9039a88709bcc2bacf5a2faac331d65dd6840f763f225ad9594cc0c67bcd0fba AS runtime
WORKDIR /srv
ARG IAPKIT_REVISION=unknown
LABEL org.opencontainers.image.title="IAPKit" \
org.opencontainers.image.source="https://github.com/hyodotdev/openiap" \
org.opencontainers.image.revision="${IAPKIT_REVISION}"
COPY --from=zlib-security /zlib/ /
COPY --from=builder --chown=65532:65532 /app/packages/kit/openiap-kit-server ./openiap-kit-server
COPY --from=builder --chown=65532:65532 /app/packages/kit/dist ./public
ENV STATIC_ROOT=/srv/public
ENV PORT=3000
ENV NODE_ENV=production
ENV APP_ENV=production
ENV IAPKIT_REVISION=${IAPKIT_REVISION}
EXPOSE 3000/tcp
USER 65532:65532
ENTRYPOINT ["./openiap-kit-server"]