Files
archie/.woodpecker/deploy.yaml
T
sam 73860b26d2
Quality / check (pull_request) Canceled after 0s
ci/woodpecker/pr/quality Pipeline was canceled
ci(woodpecker): build once, keep Go's caches, fetch archied for the canary
The same changes as the Actions workflows: a release gate runs
`task check dist` and the dist step only packages; canary and promote copy
archied out of archied:edge instead of compiling it.

The gate and the pull-request check keep Go's module, build and lint caches
on the host, in separate directories so a pull request cannot write into the
cache a release build reads.

Fixes: notes wait for the signed release and carry the prerelease flag;
the canary clones with tags, which its rollback needs to diff migrations;
release puts HEAD on main before `task release`, which refuses anything else.
2026-11-10 10:57:59 +00:00

338 lines
15 KiB
YAML

# Publish pipeline: a push to main builds the edge images, a v* tag also cuts a
# signed release. The release workflow pushes main and the tag in one command,
# so both events are delivered for the same commit; `plan` decides which
# pipeline does the work and the other one skips.
#
# Requires repo secrets: deploy_token (pushes images, publishes the Gitea
# release, links the packages) and release_signing_key (the ed25519 seed the
# release statement is signed with). canary_url and canary_token are optional;
# without them the canary install is skipped.
#
# Every shell-side reference is written $$name, which arrives at the shell as
# $name. Woodpecker rewrites only the braced form: ${name} is substituted before
# the shell runs, and an operator inside it is dropped, so ${version:-none}
# becomes empty instead of defaulting. The escaped form is used everywhere so the
# rule is mechanical rather than a judgement per line.
when:
- event: push
branch: [main]
- event: tag
ref: refs/tags/v*
# Two deployments at once would race on the released tags and on `latest`.
concurrency: 1
variables:
# Only the gate builds the dashboard and the release binaries; later steps
# reuse what it left in the workspace. The Node digest and the pnpm version
# are pinned here.
- &node-setup |
set -eu
apt-get update -qq
# jq reads release.json for `task dist`.
apt-get install -y -qq --no-install-recommends xz-utils jq
curl -fsSL -o /tmp/node.tar.xz https://nodejs.org/dist/v24.22.2/node-v24.22.2-linux-x64.tar.xz
echo "48cc0e21e048790e54c0cf5749c2725005313d652651c40b7a21feb9697aaf75 /tmp/node.tar.xz" | sha256sum -c -
tar -xJf /tmp/node.tar.xz -C /usr/local --strip-components=1
# pnpm's version belongs to the lockfile; installing any other one makes
# `pnpm install --frozen-lockfile` reject the tree.
npm install -g "pnpm@$(node -p 'require("./ui/package.json").packageManager.split("@")[1]')"
clone:
git:
image: woodpeckerci/plugin-git:2.8.0
settings:
# A tag pipeline must see the tag it is building, and a branch pipeline
# must see a tag pointing at HEAD to know the tag pipeline owns it.
tags: true
fetch_target_branch: true
steps:
- name: plan
image: alpine:3
commands:
- apk add --no-cache git
- |
set -eu
# An annotated tag makes CI_COMMIT_SHA the tag object, so the commit is
# resolved from the ref: image tags and the release statement pin it.
sha=$(git rev-parse "$$CI_COMMIT_REF^{commit}")
version=$(git tag --points-at HEAD --list 'v*' | sed -e 's|^v||' | sort -V | tail -1)
run=true
case "$$CI_PIPELINE_EVENT" in
tag) ;;
*) [ -z "$$version" ] || run=false ;;
esac
{
echo "COMMIT_SHA=$$sha"
echo "RELEASE_VERSION=$$version"
echo "RUN=$$run"
} > "$$CI_WORKSPACE/.git/ci-plan.env"
echo "commit $$sha, release $${version:-none}, run $$run"
- name: gate
image: golang:1.27.3-bookworm
depends_on: [plan]
# The full test suite starts containers. It drives the host daemon through
# the Go client, so the socket is enough - this step needs no docker CLI.
# The one test that needs the daemon binds a temporary directory into the
# container it starts, so that directory has to exist at the same path on
# the host; TMPDIR points the test at it.
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- /var/tmp/woodpecker-archie-gate:/var/tmp/woodpecker-archie-gate
# Module, build and lint caches outlive the step's container; without
# them every pipeline downloads and compiles everything from nothing.
- /var/cache/woodpecker-archie:/cache
environment:
DOCKER_HOST: unix:///var/run/docker.sock
TMPDIR: /var/tmp/woodpecker-archie-gate
GOCACHE: /cache/go-build
GOMODCACHE: /cache/go-mod
GOLANGCI_LINT_CACHE: /cache/golangci-lint
commands:
- '. "$$CI_WORKSPACE/.git/ci-plan.env"'
- '[ "$$RUN" = true ] || { echo "a release tag owns this commit; the tag pipeline publishes it"; exit 0; }'
- go install github.com/go-task/task/v3/cmd/task@v3.48.0
- go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@$(cat .golangci-version)
- go install mvdan.cc/gofumpt@v0.11.0
- bash tools/proto.sh install
- *node-setup
- |
set -eu
if ! git show-ref --verify --quiet refs/heads/main; then
if git rev-parse --verify --quiet origin/main >/dev/null; then
git branch main origin/main
else
# A tag pipeline clones the tag alone. HEAD is the released commit,
# which was on main, so the contract baseline is that same tree.
echo "no origin/main in this clone; using the released commit as the contract baseline"
git branch main HEAD
fi
fi
# A release also builds the binaries it ships, in the same task run: the
# dashboard is built once and the tree that passed is the tree that is
# published. dist/ stays in the workspace for the steps below.
- |
set -eu
if [ -n "$$RELEASE_VERSION" ]; then
task check dist TEST_FLAGS=-count=1 VERSION="$$RELEASE_VERSION"
else
task check TEST_FLAGS=-count=1
fi
- git diff --exit-code
- go install golang.org/x/vuln/cmd/govulncheck@v1.9.0
- govulncheck ./...
- |
set -eu
fail=0
for tag in $(git tag --points-at HEAD); do
case "$$tag" in
v*)
ver=$(echo "$$tag" | sed -e 's|^v||')
echo " release tag $$tag -> looking for [$$ver] in CHANGELOG.md"
grep -q "^## \[$$ver\]" CHANGELOG.md || {
echo " FAIL: CHANGELOG.md has no [$$ver] section"
fail=1
}
;;
esac
done
if [ $$fail -ne 0 ]; then
echo
echo "A release tag points at this commit but its changelog does not"
echo "describe that version. Cut releases with the release workflow."
exit 1
fi
if ! git tag --points-at HEAD | grep -qE '^v[0-9]'; then
echo "This commit isn't a release, so the images are published as :edge and sha-<sha>; :latest keeps naming the newest promoted release."
fi
- name: archied-image
image: docker:29-cli
depends_on: [gate]
volumes:
- /var/run/docker.sock:/var/run/docker.sock
environment:
DOCKER_HOST: unix:///var/run/docker.sock
DEPLOY_TOKEN:
from_secret: deploy_token
commands:
- '. "$$CI_WORKSPACE/.git/ci-plan.env"'
- '[ "$$RUN" = true ] || { echo "skipped: the tag pipeline publishes this commit"; exit 0; }'
- '[ -n "$$DEPLOY_TOKEN" ] || { echo "repo secret deploy_token is not set"; exit 1; }'
- printf '%s' "$$DEPLOY_TOKEN" | docker login git.catlow.cloud -u "$$CI_REPO_OWNER" --password-stdin
- |
set -eu
# A release reports its version; anything else is a build of main and
# says so, so a running binary can always name its commit.
if [ -n "$$RELEASE_VERSION" ]; then
component=$$RELEASE_VERSION
else
component="dev+$(echo "$$COMMIT_SHA" | cut -c1-12)"
fi
set -- \
--tag "git.catlow.cloud/sam/archied:edge" \
--tag "git.catlow.cloud/sam/archied:sha-$$COMMIT_SHA"
if [ -n "$$RELEASE_VERSION" ]; then
set -- "$$@" --tag "git.catlow.cloud/sam/archied:v$$RELEASE_VERSION"
fi
# No cache flags: the agent's daemon keeps its layer cache between
# pipelines, which is what type=gha bought on ephemeral runners.
docker buildx build --push --file Dockerfile.archied \
--build-arg GATEWAY_VERSION="$$component" \
--build-arg RUNTIME_VERSION="$$component" \
--provenance=false \
"$$@" .
- name: agent-image
image: docker:29-cli
depends_on: [gate]
volumes:
- /var/run/docker.sock:/var/run/docker.sock
environment:
DOCKER_HOST: unix:///var/run/docker.sock
DEPLOY_TOKEN:
from_secret: deploy_token
commands:
- '. "$$CI_WORKSPACE/.git/ci-plan.env"'
- '[ "$$RUN" = true ] || { echo "skipped: the tag pipeline publishes this commit"; exit 0; }'
- '[ -n "$$RELEASE_VERSION" ] || { echo "not a release; the agent image is only published with a release"; exit 0; }'
- '[ -n "$$DEPLOY_TOKEN" ] || { echo "repo secret deploy_token is not set"; exit 1; }'
- printf '%s' "$$DEPLOY_TOKEN" | docker login git.catlow.cloud -u "$$CI_REPO_OWNER" --password-stdin
- |
set -eu
apk add --no-cache jq
docker buildx build --push --file Dockerfile \
--build-arg RUNTIME_VERSION="$$RELEASE_VERSION" \
--tag "git.catlow.cloud/sam/archie-agent:v$$RELEASE_VERSION" \
--tag "git.catlow.cloud/sam/archie-agent:sha-$$COMMIT_SHA" \
--provenance=false \
--metadata-file "$$CI_WORKSPACE/.git/agent-image.json" \
.
# The release statement pins the agent image by digest, so the digest is
# what the distribution records, not the tag.
jq -er '."containerimage.digest"' "$$CI_WORKSPACE/.git/agent-image.json" \
> "$$CI_WORKSPACE/.git/agent-image.digest"
echo "agent image $(cat "$$CI_WORKSPACE/.git/agent-image.digest")"
- name: dist
image: golang:1.27.3-bookworm
depends_on: [archied-image, agent-image]
commands:
- '. "$$CI_WORKSPACE/.git/ci-plan.env"'
- '[ "$$RUN" = true ] || { echo "skipped: the tag pipeline publishes this commit"; exit 0; }'
- '[ -n "$$RELEASE_VERSION" ] || { echo "not a release; no distribution to build"; exit 0; }'
- apt-get update -qq
- apt-get install -y -qq --no-install-recommends jq zip
# The gate built dist/ from the tree it checked; this only packages it.
- |
set -eu
cmds=$(jq -r '.required_topology.units[], .required_topology.binaries[]?' release.json)
name="archie-core-archied-v$$RELEASE_VERSION-linux-amd64"
mkdir -p "$$name"
for cmd in $$cmds; do
cp "dist/$$cmd" "$$name/"
done
cp deployments/INSTRUCTIONS.md CHANGELOG.md "$$name/"
if [ -f README.md ]; then cp README.md "$$name/"; fi
digest=$(cat "$$CI_WORKSPACE/.git/agent-image.digest")
test -n "$$digest"
jq --arg image "git.catlow.cloud/sam/archie-agent@$$digest" '. + {agent_image: $$image}' \
release.json > "$$name/release.json"
zip -qr "$$name.zip" "$$name"
echo "RELEASE_ZIP=$$name.zip" >> "$$CI_WORKSPACE/.git/ci-plan.env"
echo "built $$name.zip"
- name: publish
image: golang:1.27.3-bookworm
depends_on: [dist]
environment:
DEPLOY_TOKEN:
from_secret: deploy_token
ARCHIE_RELEASE_SEED:
from_secret: release_signing_key
commands:
- '. "$$CI_WORKSPACE/.git/ci-plan.env"'
- '[ "$$RUN" = true ] || { echo "skipped: the tag pipeline publishes this commit"; exit 0; }'
- '[ -n "$$RELEASE_VERSION" ] || { echo "not a release; nothing to publish"; exit 0; }'
- '[ -n "$$ARCHIE_RELEASE_SEED" ] || { echo "repo secret release_signing_key is not set"; exit 1; }'
# archied pushes the release artifact with oras, which reads the registry
# credentials a docker login would have written.
- |
set -eu
mkdir -p "$$HOME/.docker"
auth=$(printf '%s:%s' "$$CI_REPO_OWNER" "$$DEPLOY_TOKEN" | base64 -w0)
printf '{"auths":{"git.catlow.cloud":{"auth":"%s"}}}\n' "$$auth" > "$$HOME/.docker/config.json"
- |
set -eu
prerelease=false
case "$$RELEASE_VERSION" in *-*) prerelease=true ;; esac
digest=$(cat "$$CI_WORKSPACE/.git/agent-image.digest")
./dist/archied release publish -source git.catlow.cloud/sam/archie \
-version "$$RELEASE_VERSION" -prerelease="$$prerelease" \
-zip "$$RELEASE_ZIP" \
-agent-image "git.catlow.cloud/sam/archie-agent@$$digest" \
-changelog "https://git.catlow.cloud/sam/archie/releases/tag/v$$RELEASE_VERSION"
- name: notes
image: golang:1.27.3-bookworm
depends_on: [publish]
environment:
DEPLOY_TOKEN:
from_secret: deploy_token
commands:
- '. "$$CI_WORKSPACE/.git/ci-plan.env"'
- '[ "$$RUN" = true ] || { echo "skipped: the tag pipeline publishes this commit"; exit 0; }'
- '[ -n "$$RELEASE_VERSION" ] || { echo "not a release; no notes to publish"; exit 0; }'
- '[ -n "$$DEPLOY_TOKEN" ] || { echo "repo secret deploy_token is not set"; exit 1; }'
- apt-get update -qq
- apt-get install -y -qq --no-install-recommends jq
- |
set -eu
tag="v$$RELEASE_VERSION"
prerelease=false
case "$$RELEASE_VERSION" in *-*) prerelease=true ;; esac
notes=$(mktemp)
awk -v hdr="## [$$RELEASE_VERSION]" '
index($$0, hdr) == 1 { printing = 1 }
printing && /^## \[/ && index($$0, hdr) != 1 { exit }
printing { print }
' CHANGELOG.md > "$$notes"
if ! [ -s "$$notes" ]; then
echo "no [$$RELEASE_VERSION] section extracted from CHANGELOG.md" >&2
exit 1
fi
api=https://git.catlow.cloud/api/v1
repo=sam/archie
auth="Authorization: token $$DEPLOY_TOKEN"
curl -sf -X DELETE -H "$$auth" "$$api/repos/$$repo/releases/tags/$$tag" >/dev/null || true
curl -sf -X POST -H "$$auth" -H "Content-Type: application/json" \
-d "$(jq -n --arg tag "$$tag" --arg name "Archie v$$RELEASE_VERSION" --arg body "$(cat "$$notes")" \
--argjson prerelease "$$prerelease" \
'{tag_name: $$tag, name: $$name, body: $$body, draft: false, prerelease: $$prerelease}')" \
"$$api/repos/$$repo/releases" >/dev/null
echo "published release notes for $$tag"
# The packages exist under this repository's namespace but are not
# linked to it, so the package pages stay empty until this runs.
for name in archied archie-agent archie; do
curl -sS -o /dev/null -X POST -H "$$auth" \
"$$api/packages/sam/container/$$name/-/link/archie" || true
done
- name: canary
image: golang:1.27.3-bookworm
depends_on: [publish]
environment:
CANARY_URL:
from_secret: canary_url
ARCHIE_CANARY_TOKEN:
from_secret: canary_token
commands:
- '. "$$CI_WORKSPACE/.git/ci-plan.env"'
- '[ "$$RUN" = true ] || { echo "skipped: the tag pipeline publishes this commit"; exit 0; }'
- '[ -n "$$RELEASE_VERSION" ] || { echo "not a release; nothing to install on the canary"; exit 0; }'
- '[ -n "$$CANARY_URL" ] || { echo "canary_url is not set; skipping the canary install"; exit 0; }'
- ./dist/archied release canary start -dashboard "$$CANARY_URL" -version "$$RELEASE_VERSION"