diff --git a/.gitignore b/.gitignore index 4d349f5b7..8a6a2a7f2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ /archied /archie-agent /bin/ +/dist/ .task/ *.db .references/ diff --git a/Dockerfile b/Dockerfile index 2314c823e..2069bf70b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,9 +10,13 @@ FROM golang:1.27-trixie AS builder ARG RUNTIME_VERSION=dev WORKDIR /src COPY go.mod go.sum ./ -RUN go mod download +# Cache mounts keep modules and compiled packages on the build daemon; without +# them COPY . . makes every commit a cold compile. +RUN --mount=type=cache,target=/go/pkg/mod go mod download COPY . . -RUN CGO_ENABLED=0 go build \ +RUN --mount=type=cache,target=/go/pkg/mod \ + --mount=type=cache,target=/root/.cache/go-build \ + CGO_ENABLED=0 go build \ -ldflags "-X github.com/samcharles93/archie-core/internal/app/agentworker.version=${RUNTIME_VERSION} -X github.com/samcharles93/archie-core/internal/installtype.buildType=container" \ -o /usr/local/bin/archie-agent ./cmd/archie-agent/ diff --git a/Dockerfile.archied b/Dockerfile.archied index 2c86ddd69..c77664c25 100644 --- a/Dockerfile.archied +++ b/Dockerfile.archied @@ -12,12 +12,16 @@ RUN pnpm run build FROM golang:1.27-trixie AS builder WORKDIR /src COPY go.mod go.sum ./ -RUN go mod download +# Cache mounts keep modules and compiled packages on the build daemon; without +# them COPY . . makes every commit a cold compile. +RUN --mount=type=cache,target=/go/pkg/mod go mod download COPY . . COPY --from=dashboard /src/ui/dist ./ui/dist ARG GATEWAY_VERSION=dev ARG RUNTIME_VERSION=dev -RUN CGO_ENABLED=0 go build \ +RUN --mount=type=cache,target=/go/pkg/mod \ + --mount=type=cache,target=/root/.cache/go-build \ + CGO_ENABLED=0 go build \ -ldflags "-X github.com/samcharles93/archie-core/internal/buildinfo.Version=${GATEWAY_VERSION} -X github.com/samcharles93/archie-core/internal/buildinfo.Runtime=${RUNTIME_VERSION} -X github.com/samcharles93/archie-core/internal/installtype.buildType=container" \ -o /usr/local/bin/archied ./cmd/archied/ diff --git a/RELEASING.md b/RELEASING.md index a9cdb920c..858693f11 100644 --- a/RELEASING.md +++ b/RELEASING.md @@ -71,7 +71,9 @@ The tag push runs `deploy.yml`: - **Gate.** `task check TEST_FLAGS=-count=1` (uncached, including the Docker-backed tests `-short` skips) and `govulncheck`, then a check that the - tag has a `[version]` section in `CHANGELOG.md`. + tag has a `[version]` section in `CHANGELOG.md`. On a release the same task + run also builds the binaries the zip ships (`task dist`), so nothing is + compiled again after the gate. - **Images.** `archied:v` and `archie-agent:v` on a release tag; `archied:edge` and `archied:sha-` on any other push to `main`. `:latest` moves only on promotion, so it names the newest promoted release. @@ -92,7 +94,8 @@ release rather than committing the fix on top of a tagged one. ## The canary The canary is the production host, following `next`. Every quarter hour -`canary.yml` runs `archied release canary check`, which reads the canary +`canary.yml` takes `archied` from the published `archied:edge` image and runs +`release canary check`, which reads the canary through its dashboard API and judges **the release the canary actually runs**, not the moving `next` tag: diff --git a/Taskfile.yml b/Taskfile.yml index 2f600329e..a7a6f0f40 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -101,6 +101,9 @@ tasks: ui: desc: Build the dashboard into ui/dist, which the Go build embeds + # check builds the dashboard and then build depends on it again; a second + # build empties ui/dist under the Go steps that embed it. + run: once dir: ui deps: [ui:deps] cmds: @@ -231,6 +234,10 @@ tasks: build: desc: Build archie services and agent binaries deps: [ui] + # Static, like the binaries a release ships, so `dist` reuses these + # compiled packages and only links again. + env: + CGO_ENABLED: "0" vars: GATEWAY_VERSION: '{{.GATEWAY_VERSION | default .VERSION}}' RUNTIME_VERSION: '{{.RUNTIME_VERSION | default .VERSION}}' @@ -264,6 +271,30 @@ tasks: cmd: go build -trimpath -ldflags "{{.SERVICE_LDFLAGS}}" -o {{.BIN_DIR}}/{{.ITEM}} ./cmd/{{.ITEM}} - go build -trimpath -ldflags "-X github.com/samcharles93/archie-core/internal/app/agentworker.version={{.RUNTIME_VERSION}} -X github.com/samcharles93/archie-core/internal/installtype.buildType=binary" -o {{.BIN_DIR}}/archie-agent ./cmd/archie-agent + dist: + desc: Build the linux/amd64 binaries a release ships into dist/ (VERSION=1.2.3; needs jq) + deps: [ui] + env: + GOOS: linux + GOARCH: amd64 + CGO_ENABLED: "0" + vars: + DIST_LDFLAGS: >- + -X github.com/samcharles93/archie-core/internal/installtype.buildType=binary + -X github.com/samcharles93/archie-core/internal/buildinfo.Version={{.VERSION}} + -X github.com/samcharles93/archie-core/internal/buildinfo.Runtime={{.VERSION}} + -X github.com/samcharles93/archie-core/internal/app/agentworker.version={{.VERSION}} + cmds: + # release.json names what a release ships, so the zip and this build + # cannot disagree. The compiler flags match `build`, so after the gate + # has built bin/ this only links. + - | + set -eu + mkdir -p dist + for cmd in $(jq -r '.required_topology.units[], .required_topology.binaries[]?' release.json); do + go build -trimpath -ldflags "{{.DIST_LDFLAGS}}" -o "dist/$cmd" "./cmd/$cmd" + done + test: desc: Run Go tests; the release gate passes TEST_FLAGS=-count=1 cmds: