A standalone container for web_server, shaped like job-tracker: serves /usaco/ with solved problems public and solving/skipped plus edits (status, link, notes) for the site admin. Git is the only store: the server clones adamf/usaco from Gitea, pulls on the push webhook, and commits edits back. CI builds the image only when site/ changes. Co-Authored-By: Claude Opus 5.5 <[email protected]>
48 lines
2.0 KiB
Docker
48 lines
2.0 KiB
Docker
# =============================================================================
|
|
# The USACO site: one image, one process. Same three stages as the job
|
|
# tracker's Dockerfile, which this is copied from:
|
|
#
|
|
# web builds the Vue SPA (web/) with Vite. Only package*.json is copied
|
|
# before `npm ci`, so the dependency layer is cached across edits.
|
|
# build compiles the Go server. Same trick with go.mod/go.sum.
|
|
# runtime alpine with the binary and the built SPA, which the server serves
|
|
# from /app/static (STATIC_DIR) for every non-API path under /usaco/.
|
|
#
|
|
# The build context is site/, so the problems themselves are never in the
|
|
# image: the server clones them from Gitea at runtime into DATA_DIR.
|
|
#
|
|
# The runtime runs as uid 1000, not root. DATA_DIR (/data) must be writable by
|
|
# it: with a bind mount, `chown 1000 <dir>` on the host. git is the server's
|
|
# storage layer (internal/repo shells out to it); wget is for the healthcheck.
|
|
# =============================================================================
|
|
FROM node:22-alpine AS web
|
|
WORKDIR /web
|
|
COPY web/package.json web/package-lock.json ./
|
|
RUN npm ci --no-audit --no-fund
|
|
COPY web/ ./
|
|
RUN npm run build
|
|
|
|
FROM golang:1.26 AS build
|
|
WORKDIR /src
|
|
COPY go.mod go.sum ./
|
|
RUN --mount=type=cache,target=/go/pkg/mod go mod download
|
|
COPY cmd ./cmd
|
|
COPY internal ./internal
|
|
RUN --mount=type=cache,target=/go/pkg/mod \
|
|
--mount=type=cache,target=/root/.cache/go-build \
|
|
CGO_ENABLED=0 go build -trimpath -ldflags="-s -w" -o /out/usacosite ./cmd/usacosite
|
|
|
|
FROM alpine:3.22
|
|
RUN apk add --no-cache ca-certificates git wget \
|
|
&& adduser -D -H -u 1000 app \
|
|
&& mkdir /data && chown app /data
|
|
COPY --from=build /out/usacosite /app/usacosite
|
|
COPY --from=web /web/dist /app/static
|
|
USER app
|
|
VOLUME /data
|
|
EXPOSE 8080
|
|
# start-period covers the first clone, which /api/health waits for.
|
|
HEALTHCHECK --interval=30s --timeout=5s --start-period=60s --retries=3 \
|
|
CMD wget -qO- http://localhost:8080/usaco/api/health || exit 1
|
|
CMD ["/app/usacosite"]
|