Repository navigation
Expand file tree
/
Copy pathDockerfile
More file actions
69 lines (54 loc) · 2.66 KB
/
Copy pathDockerfile
File metadata and controls
69 lines (54 loc) · 2.66 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
# syntax=docker/dockerfile:1
# ---------------------------------------------------------------------------
# OpenCode API container image.
#
# IMPORTANT: this image does NOT contain the OpenCode CLI. The gateway talks to
# `opencode serve`, which must be provided at runtime:
# * mount a binary into the container and set OPENCODE_BIN to its path, e.g.
# -v /usr/local/bin/opencode:/usr/local/bin/opencode:ro \
# -e OPENCODE_BIN=/usr/local/bin/opencode
# * or point OPENCODE_SERVER_URL at an OpenCode server running elsewhere.
# Without one of those the gateway starts but every completion fails with
# `503 upstream_unavailable`.
# ---------------------------------------------------------------------------
# ------------------------------------------------------------------ build ---
FROM node:22-bookworm-slim AS build
WORKDIR /app
RUN corepack enable
# Install with the lockfile first so the dependency layer is cached.
COPY package.json pnpm-lock.yaml pnpm-workspace.yaml* ./
RUN pnpm install --frozen-lockfile
COPY tsconfig.json tsconfig.build.json ./
COPY src ./src
# `pnpm build` runs `scripts/clean-dist.mjs` before `tsc`, so the build stage
# needs the scripts directory too.
COPY scripts ./scripts
RUN pnpm build
# Produce a pruned, production-only dependency tree (dist is already built).
RUN pnpm prune --prod
# ------------------------------------------------------------------ runtime ---
FROM node:22-bookworm-slim AS runtime
WORKDIR /app
ENV NODE_ENV=production \
HOST=0.0.0.0 \
PORT=20123
# The runtime never needs a package manager, so corepack is not enabled here and
# nothing is installed. Copy the built app, owned by the unprivileged user that
# Debian's node image already provides (uid/gid 1000).
COPY --from=build --chown=node:node /app/node_modules ./node_modules
COPY --from=build --chown=node:node /app/dist ./dist
COPY --from=build --chown=node:node /app/package.json ./package.json
# Default state and workspace directories. Mount volumes over these so state
# survives a container replacement. `COPY --chown` above keeps them writable by
# the node user only if the mount is.
RUN mkdir -p /data /workspace && chown -R node:node /data /workspace
VOLUME ["/data", "/workspace"]
ENV OPENCODE_DATA_DIR=/data \
OPENCODE_WORKDIR=/workspace
USER node
EXPOSE 20123
# Probe the public liveness endpoint with the bundled Node runtime. Uses
# `node -e` rather than wget/curl so no extra packages are needed.
HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=3 \
CMD ["node", "-e", "fetch(`http://127.0.0.1:${process.env.PORT ?? 20123}/health`).then(r=>process.exit(r.ok?0:1)).catch(()=>process.exit(1))"]
CMD ["node", "dist/index.js"]