Files
opencode2api/Dockerfile
T
Jason Xu 46def7fedc refactor: organize Go packages and remove test files
Move the command to cmd/opencode2api and group production code into
configuration, gateway, protocol, model, admin, telemetry and helper packages.
Keep shared state private behind context, metrics and runtime interfaces.

Remove the requested test files and replace test-only CI jobs with vet/build
checks. Update Docker and release build paths, preserve version injection and
make the WebUI an explicit embedded asset package.

Add directory trees and source reading guides to both READMEs. Anchor binary
ignore rules so the command package is tracked.
2026-09-15 01:28:44 +08:00

50 lines
1.4 KiB
Docker

FROM --platform=$BUILDPLATFORM golang:1.24-alpine AS builder
ARG TARGETOS
ARG TARGETARCH
ARG VERSION=dev
WORKDIR /src
COPY go.mod go.sum ./
RUN go mod download
COPY . .
RUN CGO_ENABLED=0 \
GOOS="${TARGETOS:-linux}" \
GOARCH="${TARGETARCH:-amd64}" \
go build \
-trimpath \
-ldflags="-s -w -X main.version=${VERSION}" \
-o /out/opencode2api ./cmd/opencode2api
FROM alpine:3.22
RUN apk add --no-cache ca-certificates su-exec tzdata \
&& addgroup -S opencode2api \
&& adduser -S -G opencode2api -h /var/lib/opencode2api opencode2api \
&& mkdir -p /app /var/lib/opencode2api \
&& chown -R opencode2api:opencode2api /app /var/lib/opencode2api
COPY --from=builder /out/opencode2api /usr/local/bin/opencode2api
COPY --chmod=0755 docker-entrypoint.sh /usr/local/bin/docker-entrypoint
COPY --chown=opencode2api:opencode2api config.example.json /app/config.example.json
# LISTEN_ADDRESS / WEBUI_LISTEN_ADDRESS are intentionally unset: config.json is
# authoritative. Export them to override the configured listen addresses.
ENV CONFIG_PATH=/var/lib/opencode2api/config.json \
CONFIG_SEED_PATH= \
LISTEN_ADDRESS= \
WEBUI_LISTEN_ADDRESS= \
STATE_DIR=/var/lib/opencode2api
WORKDIR /app
EXPOSE 8080 8081
HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=3 \
CMD wget -q -O /dev/null http://127.0.0.1:8080/healthz || exit 1
ENTRYPOINT ["/usr/local/bin/docker-entrypoint"]