build: add task dist, build the dashboard once, cache Go in image builds
`task dist` builds the binaries release.json names into dist/ with the compiler flags `build` uses, so after the gate has built bin/ it only links. `build` is now static (CGO_ENABLED=0), like what ships. `ui` runs once per task invocation: check built the dashboard, then build's dependency built it again under the Go steps that embed it. Both Dockerfiles compile with cache mounts for Go's module and build caches.
This commit is contained in:
1 parent
c3e64e5485
commit
b509397e8d
5 files changed
+49
-6
No files matched your search
@@ -1,6 +1,7 @@
|
||||
/archied
|
||||
/archie-agent
|
||||
/bin/
|
||||
/dist/
|
||||
.task/
|
||||
*.db
|
||||
.references/
|
||||
|
||||
+6
-2
@@ -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/
|
||||
|
||||
|
||||
+6
-2
@@ -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/
|
||||
|
||||
|
||||
+5
-2
@@ -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<version>` and `archie-agent:v<version>` on a release
|
||||
tag; `archied:edge` and `archied:sha-<commit>` 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:
|
||||
|
||||
|
||||
@@ -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:
|
||||
|
||||
Reference in new issue
Block a user