~ knotless Search/
↑↓ move↵ open⇧↵ all results

socialweb.computer/socialweb-computer-kcp

socialweb.computer: a compute market on atproto (kcp)

1 collaborator
0
0

plan 0040 step 6: promote on the release binding; follower compares binaries; 0020 in the gate

Merged johnandersen777.bsky.social asked to merge into main from socialweb.computer/socialweb-computer-kcp:plan-0040-step6
.knotless/workflows/promote.ymlnew+20−0
@@ -0,0 +1,20 @@
# knotless CI: plan 0040 step 6, the release of a green main. After `test`, on the `release` executor binding (only main's names
# socialweb-computer-release, whose release-workload module holds the socialweb.computer session with the software.release.*
# scopes): its one step is `release <command>`: the module writes the rc's manifest and version and moves channel rc, runs the
# command on the VM (scripts/promote.sh: the droplets, the rc operators' heartbeats, the prod gate), then moves stable on exit 0,
# or moves rc back and runs `scripts/promote.sh rollback`.
on:
push:
refs: [refs/heads/main]
paths: [internal/**, cmd/**, api/**, tests/**, rust/**, deploy/**, scripts/**, go.mod, go.sum, .knotless/**]
asked:
refs: [refs/heads/main]
runners: [aliceoa.bsky.social]
after: [test]
executor: release
superseded: finish
secrets: [PROD_DEPLOY_SSH_KEY, ATIRC_AGENT_CONFIG]
steps:
- name: release
timeout: 240
run: release bash scripts/ci-test.sh host && bash scripts/ci-test.sh binary && bash scripts/promote.sh
deploy/release/rc-operators.jsonnew+7−0
@@ -0,0 +1,7 @@
{
"operators": [
{ "handle": "bobvmbuilder.bsky.social", "bidders": ["did:plc:2l2wdry77c7jtucbslstagkj", "did:plc:4vcig7s43z3nyqrnepmcfzqt", "did:plc:7fj5jk5jxadrqtc5txp7xitp"] },
{ "handle": "johnandersen777.bsky.social", "bidders": ["did:plc:7q5lnitxv4meizdon5fmhzrq"] }
],
"updateWithin": "10m"
}
docs/acceptance/0020-bidder-follows-release.md+5−6
@@ -5,16 +5,15 @@ Plan 0040 step 4. An installed bidder watches `software.release.channel/socialwe
```sh
cd tests
B='[{"version":"<A version>","url":"<A url>","sha256":"<A sha256>","size":<A bytes>},
{"version":"<B version>","url":"<B url>","sha256":"<B sha256>","size":<B bytes>}]'
SWC_TARGET=<staging target.json> cargo run -q -p swc-test-host -- compositions/0020 --entry run --input "{\"builds\": $B}"
SWC_TARGET=<staging target.json> cargo run -q -p swc-test-host -- compositions/0020 --entry run # B: --input '{"b":"main/<sha>"}'
```
A and B: two published linux/amd64 builds with the follower (main/<sha>/binaries/ from 6f7f2391 on).
A is the installed build's own `main/<commit>` binary; B defaults to `main/bce9465b` (the first follower that reads the network's
PLC). The host fetches each for its sha256, size and version.
Pass: the bidder installed on the staging root host (`--release-repo` the run's account) names A in its heartbeat after the
Pass: a bidder installed on the staging root host (`--release-repo` the run's account) names A in its heartbeat after the
account's `rc` channel points at A, then B after it points at B; the records are deleted and the bidder uninstalled. SKIP on
prod or without two builds.
prod, or when the installed build has no `main/<commit>` binary (a branch).
## Readings
docs/plans/0040-release-pipeline.md+18−0
@@ -185,6 +185,11 @@ Version and channel:
### 4. Bidder self-update
A bidder is on a release when it runs the binary of the release's artifact (CIDv1 raw sha2-256 of its own executable
equals the artifact's CID), not when version strings match: CI's rcs are main builds (`v0.0.0-rc99.0.<time>-<sha>`), so
a name like `v0.0.1-rc0` is never a binary's own version. The channel is `release-channel` (`install bidder -- --release-channel
rc|stable`), default `rc` for a version with `-rc`, else `stable`.
The standard kcp pattern: an `AtprotoRecordWatch` on
`at://did:plc:gmlkrhimoueejcertevr4hl3/software.release.channel/socialweb-computer:<rc|stable>`, fed by the relay and
firehose. A new controller reacts to a change of that record:
@@ -256,6 +261,19 @@ repo:software.release.version?action=create repo:software.release.channel?action
Only main's `release` executor binding names `socialweb-computer-release`. Staging, branches and forks never have the
release session.
How it runs (the runner calls `computer.socialweb.cicd.workload.run` once per step, with the run's env and no state between
calls, and stops at the first failed step, so the whole release is one step):
- `release-workload` (atlibs-socialweb-computer-requester `modules/release-workload`) implements `workload.run`. A step
whose script is `release <promote command>` runs in the module; any other step goes to `cicd-workload` unchanged.
- `release`: on the VM `scripts/release-artifacts.sh $KNOTLESS_RUN_SHA` prints the build's artifacts (url, sha256, size,
version); the module (session `release`, as socialweb.computer) computes the rc (Version numbers), writes the manifest
and version and moves `rc`; on the VM the promote command (`scripts/promote.sh`: droplets, rc operators' heartbeats,
prod gate) runs with `RELEASE_VERSION`; exit 0: the module writes the stable version and moves `stable`; else it
moves `rc` back and runs `scripts/promote.sh rollback` on the VM, and the step fails.
- `.knotless/workflows/promote.yml`: push main, `after: [test]`, `executor: release`, secrets `PROD_DEPLOY_SSH_KEY`
and `ATIRC_AGENT_CONFIG`, one step `release bash scripts/promote.sh`.
### 7. rc operators
`deploy/release/rc-operators.json`:
internal/app/marketbidder/marketbidder.go+2−0
@@ -34,6 +34,8 @@ const (
ReleaseRepoOption = "release-repo"
ReleaseChannelOption = "release-channel"
DefaultReleaseRepo = "did:plc:gmlkrhimoueejcertevr4hl3"
BidderComponent = "bidder"
BidderApp = "market-bidder"
internal/releasefollow/follow.go+21−0
@@ -27,6 +27,8 @@ type Reader interface {
type Config struct {
Running string
RunningSHA256 string
OS string
Arch string
@@ -89,6 +91,9 @@ func (f *Follower) Follow(ctx context.Context, ch contract.Channel) (contract.Ou
if i < 0 {
return out, fmt.Errorf("releasefollow: %s has no artifact for %s/%s", version.Version, f.cfg.OS, f.cfg.Arch)
}
if f.runs(manifest.Artifacts[i].CID) {
return out, nil
}
path, sum, err := f.download(ctx, manifest.Artifacts[i])
if err != nil {
return out, err
@@ -168,3 +173,19 @@ func (f *Follower) download(ctx context.Context, a release.HTTPArtifact) (string
}
return path, sum, nil
}
func (f *Follower) runs(artifactCID string) bool {
want, err := cid.Decode(artifactCID)
if err != nil || f.cfg.RunningSHA256 == "" {
return false
}
digest, err := hex.DecodeString(f.cfg.RunningSHA256)
if err != nil {
return false
}
mh, err := multihash.Encode(digest, multihash.SHA2_256)
if err != nil {
return false
}
return cid.NewCidV1(cid.Raw, mh).Equals(want)
}
internal/stack/bidder/core.go+3−1
@@ -11,6 +11,8 @@ import (
"time"
"github.com/johnandersen777/socialweb-computer-kcp/api/v1alpha1"
"github.com/johnandersen777/socialweb-computer-kcp/internal/app/compose"
"github.com/johnandersen777/socialweb-computer-kcp/internal/app/marketbidder"
"github.com/johnandersen777/socialweb-computer-kcp/internal/bootstrap"
"github.com/johnandersen777/socialweb-computer-kcp/internal/bootstrap/table"
"github.com/johnandersen777/socialweb-computer-kcp/internal/computevm"
@@ -136,7 +138,7 @@ func RunCore(ctx context.Context, c CoreConfig, m hostsvc.Manager) error {
if err := notify.Ready(); err != nil {
return fmt.Errorf("bidder: telling systemd the core is ready: %w", err)
}
go followRelease(ctx, k, c.StateDir, c.Spec.Network, log)
go followRelease(ctx, k, c.StateDir, compose.OptionValue(c.Spec.Options, marketbidder.ReleaseChannelOption), c.Spec.Network, log)
<-ctx.Done()
return nil
}}, m)
internal/stack/bidder/release.go+13−5
@@ -24,6 +24,7 @@ import (
contract "github.com/johnandersen777/socialweb-computer-kcp/internal/contract/release"
"github.com/johnandersen777/socialweb-computer-kcp/internal/controllers/runtime/kube"
"github.com/johnandersen777/socialweb-computer-kcp/internal/install"
"github.com/johnandersen777/socialweb-computer-kcp/internal/kit/selfexe"
"github.com/johnandersen777/socialweb-computer-kcp/internal/releasefollow"
)
@@ -54,7 +55,7 @@ const (
releaseRetry = 5 * time.Minute
)
func followRelease(ctx context.Context, k *Kcp, stateDir string, network *v1alpha1.MarketNetworkValue, log *slog.Logger) {
func followRelease(ctx context.Context, k *Kcp, stateDir, releaseChannel string, network *v1alpha1.MarketNetworkValue, log *slog.Logger) {
version, _ := buildstamp.Identity()
if buildstamp.Dev() || version == "" {
log.Info("releasefollow_off", "reason", "a dev build follows no release channel")
@@ -69,16 +70,23 @@ func followRelease(ctx context.Context, k *Kcp, stateDir string, network *v1alph
log.Warn("releasefollow_off", "reason", err.Error())
return
}
channel := "stable"
if strings.Contains(version, "-rc") {
channel = "rc"
channel := strings.TrimSpace(releaseChannel)
if channel == "" {
channel = "stable"
if strings.Contains(version, "-rc") {
channel = "rc"
}
}
sum := ""
if pin, err := selfexe.Sum(); err == nil {
sum = pin.Sha256
}
rkey := "socialweb-computer:" + channel
client, dir := releaseClient(network)
reader := market.NewHTTPReader(dir)
reader.Client = client
download := &http.Client{Transport: client.Transport, Timeout: releaseDownloadTimeout}
f := releasefollow.New(releasefollow.Config{Running: version, OS: runtime.GOOS, Arch: runtime.GOARCH,
f := releasefollow.New(releasefollow.Config{Running: version, RunningSHA256: sum, OS: runtime.GOOS, Arch: runtime.GOARCH,
Dir: filepath.Join(stateDir, "bin", ".incoming"), Reader: reader, HTTP: download, Log: log,
Upgrade: func(ctx context.Context, binary, sum string) error {
return install.Upgrade(ctx, install.UpgradeOptions{StateDir: stateDir, Home: u.HomeDir, Account: u.Username,
scripts/promote.shnew+53−0
@@ -0,0 +1,53 @@
#!/usr/bin/env bash
# promote.sh [rollback]: plan 0040 step 6, on the release VM, run by the release-workload module after it moved channel rc.
# (no argument) the socialweb.computer droplets to RELEASE_URL (RELEASE_SHA256), every rc operator's bidder heartbeating
# that binary (deploy/release/rc-operators.json, within updateWithin), then the prod gate as r2
# rollback the droplets back to PREVIOUS_URL (PREVIOUS_SHA256); no previous: nothing to do
# Needs PROD_DEPLOY_SSH_KEY (a secret of main), and before it `scripts/ci-test.sh host` and `binary` (the test host, the
# requester spec).
set -euo pipefail
cd "$(dirname "$0")/.."
command -v curl >/dev/null && command -v jq >/dev/null || { apt-get update -qq && apt-get install -y -qq curl jq >/dev/null; }
home=${CI_HOME:-/home/r2}
d=$(mktemp -d); trap 'rm -rf "$d"' EXIT
(umask 077 && printf '%s\n' "${PROD_DEPLOY_SSH_KEY:?PROD_DEPLOY_SSH_KEY}" > "$d/key")
unset PROD_DEPLOY_SSH_KEY
droplets() { # url sha256
curl -fsSL --retry 3 -o "$d/socialweb-computer" "$1"
echo "$2 $d/socialweb-computer" | sha256sum -c --quiet
chmod 0755 "$d/socialweb-computer"
BINARY=$d/socialweb-computer SHA256=$2 SSH_KEY=$d/key bash scripts/deploy.sh
ssh -i "$d/key" -o IdentitiesOnly=yes -o BatchMode=yes -o StrictHostKeyChecking=accept-new root@socialweb.computer \
'systemctl restart swc-ssh-gateway.service && systemctl is-active swc-ssh-gateway.service'
echo "==> droplets on $1"
}
if [ "${1:-}" = rollback ]; then
if [ -z "${PREVIOUS_URL:-}" ]; then echo "==> no previous release: the droplets stay"; exit 0; fi
droplets "$PREVIOUS_URL" "${PREVIOUS_SHA256:?PREVIOUS_SHA256}"
exit 0
fi
droplets "${RELEASE_URL:?RELEASE_URL}" "${RELEASE_SHA256:?RELEASE_SHA256}"
within=$(jq -r '.updateWithin' deploy/release/rc-operators.json | sed 's/m$//')
deadline=$(( $(date +%s) + within * 60 ))
for did in $(jq -r '.operators[].bidders[]' deploy/release/rc-operators.json); do
pds=$(curl -fsSL --retry 3 "https://plc.directory/$did" | jq -r '.service[] | select(.id == "#atproto_pds") | .serviceEndpoint')
while :; do
got=$(curl -fsS -m 20 "$pds/xrpc/com.atproto.repo.getRecord?repo=$did&collection=com.publicdomainrelay.temp.market.heartbeat&rkey=self" | jq -r '.value.version.sha256 // ""' || true)
[ "$got" = "$RELEASE_SHA256" ] && { echo "==> $did heartbeats the release"; break; }
[ "$(date +%s)" -lt "$deadline" ] || { echo "==> $did still heartbeats ${got:-nothing} after ${within}m" >&2; exit 1; }
sleep 20
done
done
spec="$(cat "$home/requester.spec")"
jq --arg b "$spec" '.requester = $b | .accounts.r2 = {handle: "", did: "", guestRequester: true}' tests/targets/prod.json > "$home/target-prod.json"
if [ -n "${ATIRC_AGENT_CONFIG:-}" ]; then
(umask 077 && printf '%s\n' "$ATIRC_AGENT_CONFIG" > "$d/agent-config.toml")
jq --arg c "$d/agent-config.toml" '.agentConfig = $c' "$home/target-prod.json" > "$home/target-prod.json.part" && mv "$home/target-prod.json.part" "$home/target-prod.json"
fi
unset ATIRC_AGENT_CONFIG
GATE_ACCOUNTS=r2 bash tests/gate.sh "$home/target-prod.json"
scripts/release-artifacts.shnew+20−0
@@ -0,0 +1,20 @@
#!/usr/bin/env bash
# release-artifacts.sh <sha>: plan 0040 step 6, on the release VM: one line `RELEASE_ARTIFACTS <json>` the release-workload
# module reads: main/<sha>/binaries' linux builds (url, sha256, size, arch), the amd64 binary's own version, the time.
set -euo pipefail
sha=${1:?usage: release-artifacts.sh <sha>}
command -v curl >/dev/null && command -v jq >/dev/null || { apt-get update -qq && apt-get install -y -qq curl jq >/dev/null; }
base=https://socialweb-computer-kcp.sfo3.digitaloceanspaces.com/main/$sha/binaries
d=$(mktemp -d); trap 'rm -rf "$d"' EXIT
curl -fsSL --retry 3 -o "$d/SHA256SUMS" "$base/SHA256SUMS"
curl -fsSL --retry 3 -o "$d/socialweb-computer-linux-amd64" "$base/socialweb-computer-linux-amd64"
(cd "$d" && grep ' socialweb-computer-linux-amd64$' SHA256SUMS | sha256sum -c --quiet)
chmod 0755 "$d/socialweb-computer-linux-amd64"
version=$("$d/socialweb-computer-linux-amd64" version | sed -n 1p | cut -d' ' -f2)
arts=$(while read -r sum name; do
name=${name#\*}
case $name in socialweb-computer-linux-*) ;; *) continue ;; esac
size=$(curl -fsSI --retry 3 "$base/$name" | tr -d '\r' | awk 'tolower($1)=="content-length:" {print $2+0}')
jq -nc --arg n "$name" --arg u "$base/$name" --arg s "$sum" --argjson z "$size" --arg a "${name##*-}" '{name: $n, url: $u, sha256: $s, size: $z, arch: $a}'
done < "$d/SHA256SUMS" | jq -sc .)
echo "RELEASE_ARTIFACTS $(jq -nc --arg v "$version" --arg c "$sha" --arg t "$(date -u +%Y-%m-%dT%H:%M:%SZ)" --argjson a "$arts" '{version: $v, commit: $c, now: $t, artifacts: $a}')"
tests/modules/acc-0020/src/lib.rs+41−14
tests/gate.sh+2−2