0
0
plan 0040 step 4: bidders follow the release channel
deploy/apps/market-bidder/release-channel-watch.prod.yamlnew+10−0
| @@ -0,0 +1,10 @@ | ||
apiVersion: socialweb.computer/v1alpha1 | ||
kind: AtprotoRecordWatch | ||
metadata: | ||
name: release-channel | ||
spec: | ||
repo: did:plc:gmlkrhimoueejcertevr4hl3 | ||
collection: software.release.channel | ||
rkeys: ["socialweb-computer:rc", "socialweb-computer:stable"] | ||
source: | ||
eventSourceRefs: [{{.Pds.WatchEventSources}}] | ||
deploy/sets.yaml+4−0
| @@ -338,6 +338,10 @@ sets: | ||
workspace: root | ||
files: | ||
- path: apps/repo-pds/association-watch.prod.yaml | ||
- name: release-channel-watch@prod-qr | ||
workspace: root | ||
files: | ||
- path: apps/market-bidder/release-channel-watch.prod.yaml | ||
- name: association-watch@dev-local | ||
workspace: root | ||
files: | ||
docs/plans/0040-release-pipeline.md+7−0
| @@ -202,6 +202,13 @@ installed bidder core | ||
works on an install's `bin/`), following a channel in a staging account: move it forward, the heartbeat shows the | ||
new version; move it back, the previous one. | ||
| ||
Built (2026-11-16): `internal/releasefollow` (contract `internal/contract/release`), the watch | ||
`deploy/apps/market-bidder/release-channel-watch.prod.yaml` (set phase `release-channel-watch@prod-qr`), and | ||
`internal/stack/bidder/release.go` `followRelease` started from the installed core's `Members` (off for a dev build or a | ||
core without `bin/current`; `rc` for a version with `-rc`, else `stable`). Not yet proven. Order: the first `rc` channel | ||
target must be a build that has the follower (rc169 or later): a bidder that follows rc168 (53cad0e3, no follower) stops | ||
following. | ||
| ||
### 5. k8s gateway: `bidderDids` through its rentals | ||
| ||
The gateway's NodeClaim and Infra rentals take a bidder DID allowlist from their spec and pass it to the contract, | ||
internal/contract/release/release.gonew+21−0
| @@ -0,0 +1,21 @@ | ||
package release | ||
| ||
import "context" | ||
| ||
type Channel struct { | ||
URI string | ||
| ||
CID string | ||
| ||
Value map[string]any | ||
} | ||
| ||
type Outcome struct { | ||
Version string | ||
| ||
Installed bool | ||
} | ||
| ||
type Follower interface { | ||
Follow(ctx context.Context, channel Channel) (Outcome, error) | ||
} | ||
internal/releasefollow/follow.gonew+170−0
| @@ -0,0 +1,170 @@ | ||
package releasefollow | ||
| ||
import ( | ||
"context" | ||
"crypto/sha256" | ||
"encoding/hex" | ||
"fmt" | ||
"io" | ||
"log/slog" | ||
"net/http" | ||
"os" | ||
"path/filepath" | ||
"slices" | ||
| ||
"github.com/ipfs/go-cid" | ||
"github.com/multiformats/go-multihash" | ||
| ||
"github.com/johnandersen777/socialweb-computer-kcp/internal/atproto/market" | ||
"github.com/johnandersen777/socialweb-computer-kcp/internal/atproto/release" | ||
contract "github.com/johnandersen777/socialweb-computer-kcp/internal/contract/release" | ||
) | ||
| ||
type Reader interface { | ||
Resolve(ctx context.Context, ref market.RecordRef) (market.ResolvedRecord, error) | ||
} | ||
| ||
type Config struct { | ||
Running string | ||
| ||
OS string | ||
| ||
Arch string | ||
| ||
Dir string | ||
| ||
HTTP *http.Client | ||
| ||
Reader Reader | ||
| ||
Upgrade func(ctx context.Context, binary, sha256 string) error | ||
| ||
Log *slog.Logger | ||
} | ||
| ||
type Follower struct { | ||
cfg Config | ||
} | ||
| ||
var _ contract.Follower = (*Follower)(nil) | ||
| ||
func New(cfg Config) *Follower { | ||
if cfg.HTTP == nil { | ||
cfg.HTTP = http.DefaultClient | ||
} | ||
if cfg.Log == nil { | ||
cfg.Log = slog.New(slog.DiscardHandler) | ||
} | ||
return &Follower{cfg: cfg} | ||
} | ||
| ||
func (f *Follower) Follow(ctx context.Context, ch contract.Channel) (contract.Outcome, error) { | ||
channel, err := release.ParseChannel(ch.Value) | ||
if err != nil { | ||
return contract.Outcome{}, fmt.Errorf("releasefollow: the channel %s: %w", ch.URI, err) | ||
} | ||
versionRec, err := f.resolve(ctx, channel.Version.URI, channel.Version.CID) | ||
if err != nil { | ||
return contract.Outcome{}, err | ||
} | ||
version, err := release.ParseVersion(versionRec.Value) | ||
if err != nil { | ||
return contract.Outcome{}, fmt.Errorf("releasefollow: the version %s: %w", versionRec.URI, err) | ||
} | ||
out := contract.Outcome{Version: version.Version} | ||
if version.Version == f.cfg.Running { | ||
return out, nil | ||
} | ||
manifestRec, err := f.resolve(ctx, version.Manifest.URI, version.Manifest.CID) | ||
if err != nil { | ||
return out, err | ||
} | ||
manifest, err := release.ParseManifest(manifestRec.Value) | ||
if err != nil { | ||
return out, fmt.Errorf("releasefollow: the manifest %s: %w", manifestRec.URI, err) | ||
} | ||
i := slices.IndexFunc(manifest.Artifacts, func(a release.HTTPArtifact) bool { | ||
return a.Target.Os == f.cfg.OS && slices.Contains(a.Target.Arch, f.cfg.Arch) | ||
}) | ||
if i < 0 { | ||
return out, fmt.Errorf("releasefollow: %s has no artifact for %s/%s", version.Version, f.cfg.OS, f.cfg.Arch) | ||
} | ||
path, sum, err := f.download(ctx, manifest.Artifacts[i]) | ||
if err != nil { | ||
return out, err | ||
} | ||
f.cfg.Log.Info("releasefollow_upgrading", "channel", channel.Name, "from", f.cfg.Running, "to", version.Version, "sha256", sum) | ||
if err := f.cfg.Upgrade(ctx, path, sum); err != nil { | ||
return out, fmt.Errorf("releasefollow: upgrading to %s: %w", version.Version, err) | ||
} | ||
out.Installed = true | ||
return out, nil | ||
} | ||
| ||
func (f *Follower) resolve(ctx context.Context, uri, want string) (market.ResolvedRecord, error) { | ||
rec, err := f.cfg.Reader.Resolve(ctx, market.RecordRef{URI: uri, CID: want}) | ||
if err != nil { | ||
return rec, fmt.Errorf("releasefollow: resolving %s: %w", uri, err) | ||
} | ||
if rec.CID != want { | ||
return rec, fmt.Errorf("releasefollow: %s is %s, not the pinned %s", uri, rec.CID, want) | ||
} | ||
return rec, nil | ||
} | ||
| ||
func (f *Follower) download(ctx context.Context, a release.HTTPArtifact) (string, string, error) { | ||
want, err := cid.Decode(a.CID) | ||
if err != nil { | ||
return "", "", fmt.Errorf("releasefollow: the artifact cid %q: %w", a.CID, err) | ||
} | ||
if err := os.MkdirAll(f.cfg.Dir, 0o700); err != nil { | ||
return "", "", err | ||
} | ||
req, err := http.NewRequestWithContext(ctx, http.MethodGet, a.URL, nil) | ||
if err != nil { | ||
return "", "", err | ||
} | ||
resp, err := f.cfg.HTTP.Do(req) | ||
if err != nil { | ||
return "", "", fmt.Errorf("releasefollow: GET %s: %w", a.URL, err) | ||
} | ||
defer resp.Body.Close() | ||
if resp.StatusCode != http.StatusOK { | ||
return "", "", fmt.Errorf("releasefollow: GET %s: HTTP %d", a.URL, resp.StatusCode) | ||
} | ||
tmp, err := os.CreateTemp(f.cfg.Dir, ".incoming-*") | ||
if err != nil { | ||
return "", "", err | ||
} | ||
h := sha256.New() | ||
n, err := io.Copy(io.MultiWriter(tmp, h), resp.Body) | ||
if cerr := tmp.Close(); err == nil { | ||
err = cerr | ||
} | ||
if err != nil { | ||
os.Remove(tmp.Name()) | ||
return "", "", fmt.Errorf("releasefollow: downloading %s: %w", a.URL, err) | ||
} | ||
digest := h.Sum(nil) | ||
mh, err := multihash.Encode(digest, multihash.SHA2_256) | ||
if err != nil { | ||
os.Remove(tmp.Name()) | ||
return "", "", err | ||
} | ||
got := cid.NewCidV1(cid.Raw, mh) | ||
switch { | ||
case n != a.Size: | ||
os.Remove(tmp.Name()) | ||
return "", "", fmt.Errorf("releasefollow: %s is %d bytes, the manifest says %d", a.URL, n, a.Size) | ||
case !got.Equals(want): | ||
os.Remove(tmp.Name()) | ||
return "", "", fmt.Errorf("releasefollow: %s is %s, the manifest says %s", a.URL, got, want) | ||
} | ||
sum := hex.EncodeToString(digest) | ||
path := filepath.Join(f.cfg.Dir, sum) | ||
if err := os.Rename(tmp.Name(), path); err != nil { | ||
os.Remove(tmp.Name()) | ||
return "", "", err | ||
} | ||
return path, sum, nil | ||
} | ||
internal/stack/bidder/core.go+1−0
| @@ -136,6 +136,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, log) | ||
<-ctx.Done() | ||
return nil | ||
}}, m) | ||
internal/stack/bidder/release.gonew+79−0
| @@ -0,0 +1,79 @@ | ||
package bidder | ||
| ||
import ( | ||
"context" | ||
"encoding/json" | ||
"io" | ||
"log/slog" | ||
"os" | ||
"os/user" | ||
"path/filepath" | ||
"runtime" | ||
"strings" | ||
| ||
"github.com/bluesky-social/indigo/atproto/identity" | ||
| ||
"github.com/johnandersen777/socialweb-computer-kcp/api/v1alpha1" | ||
"github.com/johnandersen777/socialweb-computer-kcp/internal/atproto/market" | ||
"github.com/johnandersen777/socialweb-computer-kcp/internal/buildstamp" | ||
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/releasefollow" | ||
) | ||
| ||
const releaseChannelWatch = "release-channel" | ||
| ||
func followRelease(ctx context.Context, k *Kcp, stateDir string, log *slog.Logger) { | ||
version, _ := buildstamp.Identity() | ||
if buildstamp.Dev() || version == "" { | ||
log.Info("releasefollow_off", "reason", "a dev build follows no release channel") | ||
return | ||
} | ||
if _, err := os.Stat(filepath.Join(stateDir, "bin", "current")); err != nil { | ||
log.Info("releasefollow_off", "reason", "the core does not run from an install (no bin/current)") | ||
return | ||
} | ||
u, err := user.Current() | ||
if err != nil { | ||
log.Warn("releasefollow_off", "reason", err.Error()) | ||
return | ||
} | ||
channel := "stable" | ||
if strings.Contains(version, "-rc") { | ||
channel = "rc" | ||
} | ||
rkey := "socialweb-computer:" + channel | ||
f := releasefollow.New(releasefollow.Config{Running: version, OS: runtime.GOOS, Arch: runtime.GOARCH, | ||
Dir: filepath.Join(stateDir, "bin", ".incoming"), Reader: market.NewHTTPReader(identity.DefaultDirectory()), 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, | ||
RuntimeDir: install.OwnRuntimeDir(), Binary: binary, SHA256: sum, Out: io.Discard, | ||
SelfCheck: install.SelfCheck, Restart: install.RestartOwnUnits}) | ||
}}) | ||
log.Info("releasefollow_on", "channel", channel, "running", version) | ||
seen := "" | ||
_, _ = kube.Await(ctx, k.dyn.Resource(v1alpha1.AtprotoRecordWatchGVR), releaseChannelWatch, 0, func(o *v1alpha1.AtprotoRecordWatch) (bool, error) { | ||
if o == nil { | ||
return false, nil | ||
} | ||
for _, r := range o.Status.Records { | ||
if !strings.HasSuffix(r.URI, "/"+rkey) || r.Cid == seen { | ||
continue | ||
} | ||
seen = r.Cid | ||
var value map[string]any | ||
if err := json.Unmarshal(r.Value, &value); err != nil { | ||
log.Warn("releasefollow_failed", "channel", r.URI, "err", err.Error()) | ||
continue | ||
} | ||
out, err := f.Follow(ctx, contract.Channel{URI: r.URI, CID: r.Cid, Value: value}) | ||
if err != nil { | ||
log.Warn("releasefollow_failed", "channel", r.URI, "err", err.Error()) | ||
continue | ||
} | ||
log.Info("releasefollow_seen", "channel", r.URI, "version", out.Version, "installed", out.Installed) | ||
} | ||
return false, nil | ||
}) | ||
} | ||
.plans.yaml+2−2
| @@ -3,8 +3,8 @@ | ||
plans: | ||
- plan: docs/plans/0040-release-pipeline.md | ||
agent: ci-bootstrap | ||
status: in progress; steps 1-2 built | ||
next: step 3, the release records (project, manifest, version v0.0.0-rc168, channel rc) as socialweb.computer | ||
status: in progress; steps 1, 2, 4 built (4 not proven), step 3 lexicons | ||
next: prove step 4 on an installed staging bidder; step 3 records and step 6 composition (first CI rc with the follower: rc169) | ||
- plan: docs/plans/0050-staging-pki-dns.md | ||
agent: ci-bootstrap | ||
status: in progress; steps 1-5 built, step 6 for the PLC (one https PLC, DNS/front on 53/443); staging 16/16 in cycle 25 (2e44de85) | ||