Repository navigation
Expand file tree
/
Copy pathDockerfile.api
More file actions
115 lines (94 loc) · 5.15 KB
/
Copy pathDockerfile.api
File metadata and controls
115 lines (94 loc) · 5.15 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
# Optional offline inputs; defaults retain the upstream base images.
ARG NODE_SLIM_IMAGE=node:26.13.1-bookworm-slim@sha256:5df79989ed685e09f0a98019db4cebfb22fb9df1a53c0161664a011f7ff6b0f1
ARG NODE_IMAGE=
ARG API_TOOLCHAIN_IMAGE=
# Replaced with a directory or image containing store/ and pnpm.tgz.
FROM scratch AS pnpm-offline
# ---- Dependencies stage ----
FROM ${NODE_IMAGE:-${NODE_SLIM_IMAGE}} AS deps
ARG PNPM_OFFLINE=0
RUN --mount=type=bind,from=pnpm-offline,target=/pnpm-offline \
if [ "$PNPM_OFFLINE" = "1" ]; then \
mkdir -p /opt/pnpm \
&& tar -xzf /pnpm-offline/pnpm.tgz -C /opt/pnpm --strip-components=2 \
&& ln -s /opt/pnpm/bin/pnpm.cjs /usr/local/bin/pnpm \
&& ln -s /opt/pnpm/bin/pnpx.cjs /usr/local/bin/pnpx; \
else npm install -g pnpm@10.34.8; fi
WORKDIR /app
# Copy workspace config
COPY package.json pnpm-lock.yaml pnpm-workspace.yaml turbo.json tsconfig.base.json ./
COPY patches/ patches/
# Copy package.json for ALL workspace packages (pnpm needs full workspace graph)
COPY apps/api/package.json apps/api/tsconfig.json apps/api/drizzle.config.ts apps/api/
COPY apps/cli/package.json apps/cli/
COPY apps/web/package.json apps/web/
COPY apps/site/package.json apps/site/
COPY packages/shared/package.json packages/shared/tsconfig.json packages/shared/
COPY packages/container-runtime/package.json packages/container-runtime/tsconfig.json packages/container-runtime/
COPY packages/agent-adapters/package.json packages/agent-adapters/tsconfig.json packages/agent-adapters/
COPY packages/ticket-providers/package.json packages/ticket-providers/tsconfig.json packages/ticket-providers/
# Include every workspace manifest so the frozen lockfile matches.
COPY packages/mcp-bridge/package.json packages/mcp-bridge/
# Install production dependencies (--ignore-scripts avoids husky prepare hook)
RUN --mount=type=bind,from=pnpm-offline,target=/pnpm-offline,rw \
if [ "$PNPM_OFFLINE" = "1" ]; then \
pnpm install --frozen-lockfile --ignore-scripts --prod --filter @optio/api... \
--offline --store-dir /pnpm-offline/store; \
else pnpm install --frozen-lockfile --ignore-scripts --prod --filter @optio/api...; fi
# ---- The Optio CLI bundle (docs/remote-workspaces.md): served at /api/cli/optio-cli.tgz ----
# node-pty has no Linux prebuild, so it is compiled here (python3, make, g++
# in this stage only; the headers come with the image, nothing is downloaded).
# On the full Node image (NODE_IMAGE) the compilers are already there.
FROM deps AS cli-build
# Build dependencies stay in this stage; the runtime copies production deps only.
ARG PNPM_OFFLINE=0
# This install changes the deps stage's production-only node_modules, and pnpm
# won't replace it without a TTY unless told to.
ENV CI=true
RUN --mount=type=bind,from=pnpm-offline,target=/pnpm-offline,rw \
if [ "$PNPM_OFFLINE" = "1" ]; then \
pnpm install --frozen-lockfile --ignore-scripts --filter @optio/cli... \
--offline --store-dir /pnpm-offline/store; \
else pnpm install --frozen-lockfile --ignore-scripts --filter @optio/cli...; fi
RUN if ! command -v g++ >/dev/null || ! command -v make >/dev/null; then \
apt-get update \
&& apt-get install -y --no-install-recommends python3 make g++ \
&& rm -rf /var/lib/apt/lists/*; fi
ENV npm_config_nodedir=/usr/local
COPY packages/shared/ packages/shared/
COPY apps/cli/ apps/cli/
COPY scripts/build-cli-tarball.sh scripts/
RUN pnpm --filter @optio/cli rebuild node-pty && scripts/build-cli-tarball.sh /app/optio-cli.tgz
# ---- Prebuildable third-party runtime toolchain ----
FROM ${NODE_SLIM_IMAGE} AS api-toolchain
# Verify Node ships OpenSSL >= 3.5 for post-quantum TLS (X25519MLKEM768)
RUN node -e 'const [maj,min] = process.versions.openssl.split(".").map(Number); if (maj < 3 || (maj === 3 && min < 5)) { console.error("OpenSSL " + process.versions.openssl + " too old; need >= 3.5"); process.exit(1); }'
# git + ca-certificates: required by the skill-sync worker for shallow-cloning
# marketplace skills (issue #497, Phase 2). Agent harnesses run only in
# isolated agent containers, never in this control-plane image.
RUN apt-get update \
&& apt-get upgrade -y \
&& apt-get install -y --no-install-recommends git ca-certificates \
&& rm -rf /var/lib/apt/lists/*
# Install tsx globally for TypeScript execution at runtime
# (workspace packages export .ts source, so the API runs via tsx)
# npm is only needed to install the launcher; keep its separate dependency tree
# out of the production image (agent package installs happen in agent pods).
RUN npm install -g tsx && npm uninstall -g npm && rm -rf /root/.npm
# ---- Runtime stage ----
FROM ${API_TOOLCHAIN_IMAGE:-api-toolchain}
ARG OPTIO_VERSION=dev
ENV OPTIO_VERSION=${OPTIO_VERSION}
WORKDIR /app
# Copy production dependencies from deps stage
COPY --from=deps /app/ ./
# Copy source
COPY packages/ packages/
COPY apps/api/ apps/api/
COPY --from=cli-build /app/optio-cli.tgz /app/static/optio-cli.tgz
EXPOSE 4000
HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=3 \
CMD ["node", "-e", "fetch('http://localhost:4000/api/health').then(r=>{if(!r.ok)process.exit(1)}).catch(()=>process.exit(1))"]
USER node
WORKDIR /app/apps/api
CMD ["tsx", "src/index.ts"]