diff --git a/cmd/archied/main.go b/cmd/archied/main.go index cee2db186..162e233f6 100644 --- a/cmd/archied/main.go +++ b/cmd/archied/main.go @@ -16,8 +16,8 @@ func main() { if archied.IsSetupArgs(args) { os.Exit(archied.RunSetup(args[1:], os.Stdin, os.Stdout, os.Stderr)) } - if len(args) > 0 && args[0] == "select-release" { - os.Exit(archied.RunReleaseChannel(args[1:], os.Stdin, os.Stdout, os.Stderr)) + if len(args) > 0 && args[0] == "update" { + os.Exit(archied.RunUpdate(args[1:], os.Stdout, os.Stderr)) } if len(args) > 0 && args[0] == "update-image" { os.Exit(archied.RunUpdateImage(args[1:], os.Stderr)) diff --git a/deployments/INSTRUCTIONS.md b/deployments/INSTRUCTIONS.md index f7a6dc257..8b49494e3 100644 --- a/deployments/INSTRUCTIONS.md +++ b/deployments/INSTRUCTIONS.md @@ -92,15 +92,15 @@ an install (or an upgrade across v1.30.0) needs its unit as well -- see `archie-update-install` downloads the approved release's Linux/amd64 archive and verifies its `SHA256SUMS` entry before executing or installing it. Releases -must include `release.json`, all host binaries, and the three updater scripts. +must include `release.json`, all host binaries, and the two updater scripts. Older releases without this contract cannot be installed through the artifact path. `--from-source` (or `ARCHIE_UPDATE_SOURCE_BUILD=1`) explicitly clones and builds the selected release instead. -The update check command accepts `--channel stable` (default), `--channel next` -(includes prereleases), or `--channel exact-pin --pin 1.2.3`. The services run -only the scripts installed beside their binaries; Settings → Status → Updates -chooses the channel they select from. +`archied update check` finds the newest GitHub release with a linux-amd64 zip on +the channel chosen under Settings → Status → Updates: stable, next (includes +prereleases) or a pinned version. From a shell it reads +`ARCHIE_UPDATE_RELEASE_CHANNEL` and `ARCHIE_UPDATE_PIN`, or `-channel` and `-pin`. The notification destination remains separate from the release channel. For scheduled, unattended runs, `archie-update-install --auto` discovers the diff --git a/go.mod b/go.mod index 197ee156a..073c0e1d2 100644 --- a/go.mod +++ b/go.mod @@ -4,8 +4,11 @@ go 1.27.0 require ( cel.dev/expr v0.25.3 // indirect + code.gitea.io/sdk/gitea v0.23.2 // indirect dario.cat/mergo v1.0.2 // indirect + github.com/42wim/httpsig v1.2.4 // indirect github.com/Azure/go-ansiterm v0.0.0-20260917205352-e937bb47801a // indirect + github.com/Masterminds/semver/v3 v3.5.0 // indirect github.com/Microsoft/go-winio v0.6.2 // indirect github.com/ProtonMail/go-crypto v1.5.1 // indirect github.com/antithesishq/antithesis-sdk-go v0.8.0 // indirect @@ -18,6 +21,7 @@ require ( github.com/containerd/log v0.2.0 // indirect github.com/containerd/platforms v1.0.0-rc.5 // indirect github.com/cpuguy83/dockercfg v0.3.2 // indirect + github.com/davidmz/go-pageant v1.0.2 // indirect github.com/distribution/reference v0.6.0 // indirect github.com/docker/go-connections v0.8.1 // indirect github.com/docker/go-units v0.5.0 // indirect @@ -26,6 +30,7 @@ require ( github.com/emirpasic/gods v1.18.1 // indirect github.com/fatih/color v1.19.0 // indirect github.com/felixge/httpsnoop v1.1.0 // indirect + github.com/go-fed/httpsig v1.1.0 // indirect github.com/go-git/gcfg/v2 v2.0.2 // indirect github.com/go-jose/go-jose/v4 v4.1.5 // indirect github.com/go-json-experiment/json v0.0.0-20260820222146-c27c302e5fc3 // indirect @@ -33,8 +38,13 @@ require ( github.com/go-logr/stdr v1.2.2 // indirect github.com/go-ole/go-ole v1.3.0 // indirect github.com/golang/protobuf v1.5.4 // indirect + github.com/google/go-github/v86 v86.0.0 // indirect + github.com/google/go-querystring v1.2.0 // indirect github.com/google/go-tpm v0.9.8 // indirect github.com/google/jsonschema-go v0.4.3 // indirect + github.com/hashicorp/go-cleanhttp v0.5.2 // indirect + github.com/hashicorp/go-retryablehttp v0.7.8 // indirect + github.com/hashicorp/go-version v1.9.0 // indirect github.com/hashicorp/yamux v0.1.2 // indirect github.com/jackc/pgpassfile v1.0.0 // indirect github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect @@ -71,8 +81,10 @@ require ( github.com/stretchr/testify v1.12.1 // indirect github.com/tklauser/go-sysconf v0.4.0 // indirect github.com/tklauser/numcpus v0.12.0 // indirect + github.com/ulikunitz/xz v0.5.15 // indirect github.com/yosida95/uritemplate/v3 v3.0.2 // indirect github.com/yusufpapurcu/wmi v1.2.4 // indirect + gitlab.com/gitlab-org/api/client-go v1.46.0 // indirect go.opentelemetry.io/auto/sdk v1.2.1 // indirect go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.71.0 // indirect go.opentelemetry.io/otel v1.46.0 // indirect @@ -96,6 +108,7 @@ require ( github.com/BurntSushi/toml v1.6.0 github.com/cedar-policy/cedar-go v1.8.0 github.com/coreos/go-oidc/v3 v3.21.0 + github.com/creativeprojects/go-selfupdate v1.6.0 github.com/docker/sandbox-kit-spec/v3 v3.0.0-m.6 github.com/go-git/go-billy/v6 v6.0.0-alpha.2 github.com/go-git/go-git/v6 v6.0.0-alpha.5 diff --git a/go.sum b/go.sum index c35bea910..f3120a7f4 100644 --- a/go.sum +++ b/go.sum @@ -2,14 +2,20 @@ cel.dev/cel-go v0.32.0 h1:irvpFKr5EuGPyxeME03ERh0rii1TX+BDAnB9eL3IvNk= cel.dev/cel-go v0.32.0/go.mod h1:DnVip7tpJSsgZymwfT+m1tnEVy3ivAjSMXPx12YrMkU= cel.dev/expr v0.25.3 h1:A2jO8jwOugrrovveCWfj0KEZOfqiLgAcwjpHPhzIGw0= cel.dev/expr v0.25.3/go.mod h1:hrXvqGP6G6gyx8UAHSHJ5RGk//1Oj5nXQ2NI02Nrsg4= +code.gitea.io/sdk/gitea v0.23.2 h1:iJB1FDmLegwfwjX8gotBDHdPSbk/ZR8V9VmEJaVsJYg= +code.gitea.io/sdk/gitea v0.23.2/go.mod h1:yyF5+GhljqvA30sRDreoyHILruNiy4ASufugzYg0VHM= dario.cat/mergo v1.0.2 h1:85+piFYR1tMbRrLcDwR18y4UKJ3aH1Tbzi24VRW1TK8= dario.cat/mergo v1.0.2/go.mod h1:E/hbnu0NxMFBjpMIE34DRGLWqDy0g5FuKDhCb31ngxA= +github.com/42wim/httpsig v1.2.4 h1:mI5bH0nm4xn7K18fo1K3okNDRq8CCJ0KbBYWyA6r8lU= +github.com/42wim/httpsig v1.2.4/go.mod h1:yKsYfSyTBEohkPik224QPFylmzEBtda/kjyIAJjh3ps= github.com/AdaLogics/go-fuzz-headers v0.0.0-20240806141605-e8a1dd7889d6 h1:He8afgbRMd7mFxO99hRNu+6tazq8nFF9lIwo9JFroBk= github.com/AdaLogics/go-fuzz-headers v0.0.0-20240806141605-e8a1dd7889d6/go.mod h1:8o94RPi1/7XTJvwPpRSzSUedZrtlirdB3r9Z20bi2f8= github.com/Azure/go-ansiterm v0.0.0-20260917205352-e937bb47801a h1:4hxax9ktNjSDoFn1tZSeL6gXMTRMpO0FzjdKfT01jgY= github.com/Azure/go-ansiterm v0.0.0-20260917205352-e937bb47801a/go.mod h1:3EWSSOZ50kb+arhww0qIaEXHToib/3FjBj9Jj5lcP5g= github.com/BurntSushi/toml v1.6.0 h1:dRaEfpa2VI55EwlIW72hMRHdWouJeRF7TPYhI+AUQjk= github.com/BurntSushi/toml v1.6.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho= +github.com/Masterminds/semver/v3 v3.5.0 h1:kQceYJfbupGfZOKZQg0kou0DgAKhzDg2NZPAwZ/2OOE= +github.com/Masterminds/semver/v3 v3.5.0/go.mod h1:4V+yj/TJE1HU9XfppCwVMZq3I84lprf4nC11bSS5beM= github.com/Microsoft/go-winio v0.6.2 h1:F2VQgta7ecxGYO8k3ZZz3RS8fVIXVxONVUPlNERoyfY= github.com/Microsoft/go-winio v0.6.2/go.mod h1:yd8OoFMLzJbo9gZq8j5qaps8bJ9aShtEA8Ipt1oGCvU= github.com/ProtonMail/go-crypto v1.5.1 h1:pTrLDQHyOT8y3DFYIpijgPBTw/7E2GLMimutvOlceuE= @@ -46,8 +52,12 @@ github.com/cpuguy83/dockercfg v0.3.2 h1:DlJTyZGBDlXqUZ2Dk2Q3xHs/FtnooJJVaad2S9GK github.com/cpuguy83/dockercfg v0.3.2/go.mod h1:sugsbF4//dDlL/i+S+rtpIWp+5h0BHJHfjj5/jFyUJc= github.com/creack/pty v1.1.24 h1:bJrF4RRfyJnbTJqzRLHzcGaZK1NeM5kTC9jGgovnR1s= github.com/creack/pty v1.1.24/go.mod h1:08sCNb52WyoAwi2QDyzUCTgcvVFhUzewun7wtTfvcwE= +github.com/creativeprojects/go-selfupdate v1.6.0 h1:Bu3cIgdyfI1Pg8XsL8nbaT2uMjfZ8HIoxnBmPJbN0sw= +github.com/creativeprojects/go-selfupdate v1.6.0/go.mod h1:Ids8O474XGQG0jZ5vpBIhWffcGYjUP6ccOI0mMcvQbI= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davidmz/go-pageant v1.0.2 h1:bPblRCh5jGU+Uptpz6LgMZGD5hJoOt7otgT454WvHn0= +github.com/davidmz/go-pageant v1.0.2/go.mod h1:P2EDDnMqIwG5Rrp05dTRITj9z2zpGcD9efWSkTNKLIE= github.com/distribution/reference v0.6.0 h1:0IXCQ5g4/QMHHkarYzh5l+u8T3t73zM5QvfrDyIgxBk= github.com/distribution/reference v0.6.0/go.mod h1:BbU0aIcezP1/5jX/8MP0YiH4SdvB5Y4f/wlDRiLyi3E= github.com/docker/go-connections v0.8.1 h1:JibmG5hULs5qXSr/cp/w3Pw5fZuStt4MOHMUExb29/M= @@ -69,6 +79,8 @@ github.com/felixge/httpsnoop v1.1.0 h1:3YtUj32ZZkqZtt3sZZsClsymw/QDuVfpNhoA31zeO github.com/felixge/httpsnoop v1.1.0/go.mod h1:Zqxgdd+1Rkcz8euOqdr7lqgCRJztwr5hp9vDSi5UZCE= github.com/gliderlabs/ssh v0.3.8 h1:a4YXD1V7xMF9g5nTkdfnja3Sxy1PVDCj1Zg4Wb8vY6c= github.com/gliderlabs/ssh v0.3.8/go.mod h1:xYoytBv1sV0aL3CavoDuJIQNURXkkfPA/wxQ1pL1fAU= +github.com/go-fed/httpsig v1.1.0 h1:9M+hb0jkEICD8/cAiNqEB66R87tTINszBRTjwjQzWcI= +github.com/go-fed/httpsig v1.1.0/go.mod h1:RCMrTZvN1bJYtofsG4rd5NaO5obxQ5xBkdiS7xsT7bM= github.com/go-git/gcfg/v2 v2.0.2 h1:MY5SIIfTGGEMhdA7d7JePuVVxtKL7Hp+ApGDJAJ7dpo= github.com/go-git/gcfg/v2 v2.0.2/go.mod h1:/lv2NsxvhepuMrldsFilrgct6pxzpGdSRC13ydTLSLs= github.com/go-git/go-billy/v6 v6.0.0-alpha.2 h1:1Sv5WemXL8CxKrAx1gioJ+uHNb2bZJhiQLfwSZ4Et8c= @@ -95,18 +107,31 @@ github.com/golang-jwt/jwt/v5 v5.3.1 h1:kYf81DTWFe7t+1VvL7eS+jKFVWaUnK9cB1qbwn63Y github.com/golang-jwt/jwt/v5 v5.3.1/go.mod h1:fxCRLWMO43lRc8nhHWY6LGqRcf+1gQWArsqaEUEa5bE= github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek= github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps= +github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8= github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU= +github.com/google/go-github/v86 v86.0.0 h1:S/6aANJhwRm8EQmGKVML3j41yq0h2BsTP8FnDkO7kcA= +github.com/google/go-github/v86 v86.0.0/go.mod h1:zKv1l4SwDXNFMGByi2FWkq71KwSXqj/eQRZuqtmcot8= +github.com/google/go-querystring v1.2.0 h1:yhqkPbu2/OH+V9BfpCVPZkNmUXhb2gBxJArfhIxNtP0= +github.com/google/go-querystring v1.2.0/go.mod h1:8IFJqpSRITyJ8QhQ13bmbeMBDfmeEJZD5A0egEOmkqU= github.com/google/go-tpm v0.9.8 h1:slArAR9Ft+1ybZu0lBwpSmpwhRXaa85hWtMinMyRAWo= github.com/google/go-tpm v0.9.8/go.mod h1:h9jEsEECg7gtLis0upRBQU+GhYVH6jMjrFxI8u6bVUY= github.com/google/jsonschema-go v0.4.3 h1:/DBOLZTfDow7pe2GmaJNhltueGTtDKICi8V8p+DQPd0= github.com/google/jsonschema-go v0.4.3/go.mod h1:r5quNTdLOYEz95Ru18zA0ydNbBuYoo9tgaYcxEYhJVE= github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/graph-gophers/graphql-go v1.9.0 h1:yu0ucKHLc5qGpRwLYKIWtr9bOoxovkWasuBrPQwlHls= +github.com/graph-gophers/graphql-go v1.9.0/go.mod h1:23olKZ7duEvHlF/2ELEoSZaY1aNPfShjP782SOoNTyM= +github.com/hashicorp/go-cleanhttp v0.5.2 h1:035FKYIWjmULyFRBKPs8TBQoi0x6d9G4xc9neXJWAZQ= +github.com/hashicorp/go-cleanhttp v0.5.2/go.mod h1:kO/YDlP8L1346E6Sodw+PrpBSV4/SoxCXGY6BqNFT48= github.com/hashicorp/go-hclog v1.6.3 h1:Qr2kF+eVWjTiYmU7Y31tYlP1h0q/X3Nl3tPGdaB11/k= github.com/hashicorp/go-hclog v1.6.3/go.mod h1:W4Qnvbt70Wk/zYJryRzDRU/4r0kIg0PVHBcfoyhpF5M= github.com/hashicorp/go-plugin v1.8.0 h1:ie8S6RRY8RvB2usYZv+AAZ/wBvx2AU5p5QeP5j/FORs= github.com/hashicorp/go-plugin v1.8.0/go.mod h1:BExt6KEaIYx804z8k4gRzRLEvxKVb+kn0NMcihqOqb8= +github.com/hashicorp/go-retryablehttp v0.7.8 h1:ylXZWnqa7Lhqpk0L1P1LzDtGcCR0rPVUrx/c8Unxc48= +github.com/hashicorp/go-retryablehttp v0.7.8/go.mod h1:rjiScheydd+CxvumBsIrFKlx3iS0jrZ7LvzFGFmuKbw= +github.com/hashicorp/go-version v1.9.0 h1:CeOIz6k+LoN3qX9Z0tyQrPtiB1DFYRPfCIBtaXPSCnA= +github.com/hashicorp/go-version v1.9.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA= github.com/hashicorp/yamux v0.1.2 h1:XtB8kyFOyHXYVFnwT5C3+Bdo8gArse7j2AQ0DA0Uey8= github.com/hashicorp/yamux v0.1.2/go.mod h1:C+zze2n6e/7wshOZep2A70/aQU6QBRWJO/G6FT1wIns= github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM= @@ -238,10 +263,14 @@ github.com/tklauser/go-sysconf v0.4.0 h1:7H0uAN+7RkwWRaxhYXDLqa5V3LPrJeV8wmD9dRU github.com/tklauser/go-sysconf v0.4.0/go.mod h1:8mTNWyog7H+MpKijp4VmKJAd2bbYQ2zuUwkYRbUArPI= github.com/tklauser/numcpus v0.12.0 h1:NR85qdvHA9pFse3x3weVZ0r0ST8R6l5RHbZrlRaqob4= github.com/tklauser/numcpus v0.12.0/go.mod h1:ABHeXzJnr/qqwguhClkZKT1/8VABcYrsyUiUGobwWJg= +github.com/ulikunitz/xz v0.5.15 h1:9DNdB5s+SgV3bQ2ApL10xRc35ck0DuIX/isZvIk+ubY= +github.com/ulikunitz/xz v0.5.15/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oWt/14= github.com/yosida95/uritemplate/v3 v3.0.2 h1:Ed3Oyj9yrmi9087+NczuL5BwkIc4wvTb5zIM+UJPGz4= github.com/yosida95/uritemplate/v3 v3.0.2/go.mod h1:ILOh0sOhIJR3+L/8afwt/kE++YT040gmv5BQTMR2HP4= github.com/yusufpapurcu/wmi v1.2.4 h1:zFUKzehAFReQwLys1b/iSMl+JQGSCSjtVqQn9bBrPo0= github.com/yusufpapurcu/wmi v1.2.4/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0= +gitlab.com/gitlab-org/api/client-go v1.46.0 h1:YxBWFZIFYKcGESCb9fpkwzouo+apyB9pr/XTWzNoL24= +gitlab.com/gitlab-org/api/client-go v1.46.0/go.mod h1:FtgyU6g2HS5+fMhw6nLK96GBEEBx5MzntOiJWfIaiN8= go.lsp.dev/jsonrpc2 v1.0.1 h1:JZAchpm6RcOuwEOnZ7kF3kA1EpEjdJZ/6rMSfOF3+F4= go.lsp.dev/jsonrpc2 v1.0.1/go.mod h1:WN+TesqrPumBmUdsuWyn9DHq3zl4i85L/qG0NLdj8qg= go.lsp.dev/protocol v1.0.1 h1:kLWUIk1v/deXxo1D0VO4avjZnfeuZ82mouJgJd/NbdU= @@ -266,21 +295,29 @@ go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0= go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y= go.yaml.in/yaml/v3 v3.0.5 h1:N6y/pJk8buWs9NY5ERU2HSMfm+IuD/OtfdAnq6kESPw= go.yaml.in/yaml/v3 v3.0.5/go.mod h1:HVTZu1O7/Vkt2N+BFy8Zza+lnLsABggaTM2ZpNIGuKg= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/crypto v0.0.0-20210513164829-c07d793c2f9a/go.mod h1:P+XmwS30IXTQdn5tA2iutPOUgjI07+tq3H3K9MVA1s8= golang.org/x/crypto v0.57.0 h1:3ZVCjf8Ggz7zneR/EHRVx68Ctf+2pmIMP2UFhh9cC6M= golang.org/x/crypto v0.57.0/go.mod h1:Fdz0i5U6CoizGwLda9DttjSk6qlZo25zYNtR+ycvuZA= golang.org/x/exp v0.0.0-20260908205506-85c1c2202aba h1:Ck8QetSgk912qxWLMCKxd0in+aiyBQyDSMae6e/xmpU= golang.org/x/exp v0.0.0-20260908205506-85c1c2202aba/go.mod h1:50RgIsmK7OwqzTTeqcSXQW8SswW0o8fRcDxmqGluJ8E= golang.org/x/mod v0.41.0 h1:qJmnOUb4YB+FsEuM3HcWucdZASCPGhsX6uljO6pog0c= golang.org/x/mod v0.41.0/go.mod h1:Ek9pY8RKWXwsWvd3rQiHYtMqkjSUV+s1Rj7j4H5Ur6o= +golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.59.0 h1:5zfYln+w5XCxwrnMMJPufRgNoXEaGxl0wo5GqPXyues= golang.org/x/net v0.59.0/go.mod h1:2DA/G1UfVbCpQPeWTmMPGY7Cs2PkBkwu743bVX5PIVg= golang.org/x/oauth2 v0.37.0 h1:JUlcxA8oAtauLfiH8FX2/FkAWHAdi0QtGCGc+hofE98= golang.org/x/oauth2 v0.37.0/go.mod h1:IxwZNxUULJmpBFf9K/9NTMSIfZZuvuTy1gGxhigP/58= golang.org/x/sync v0.23.0 h1:KameEIfc1IkluZyXWLn39Wd4tURc6GbCiISGiZm2bQk= golang.org/x/sync v0.23.0/go.mod h1:sUUOizhqBxiL6pEWpqNLUiaJn1ShEbZ6BBqskPbjZm0= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201204225414-ed752295db88/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= @@ -290,12 +327,16 @@ golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/sys v0.48.0 h1:bbX/i/6MgT9BVLM9RT1thmxL04yeTAhbEz4SyadbXoo= golang.org/x/sys v0.48.0/go.mod h1:hNLxWAXmnKAxqDtdwIYC4bM9oQPEecfsnNMuSxOs3og= +golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.46.0 h1:3+OXuTbaKDgwk8jTi3aSLHRlmWqHEUDUtxnbFigO4YE= golang.org/x/term v0.46.0/go.mod h1:+K02xbkittuwc0Am4abfA3Fc+XRGXkvBXNO88NCXPoc= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.42.0 h1:JbOZXgfeCPU9gacVtYliJqOhD+zhrEqK4LfdpmlUZqI= golang.org/x/text v0.42.0/go.mod h1:ojzP1Z+2QtioaF8DTtO8K5q7JWVVYwZKenzujK0Zd0E= golang.org/x/time v0.16.0 h1:vMb6ptszcQMkcwiRTAuNNU50gom6++Q/6gY2hDM6VDE= golang.org/x/time v0.16.0/go.mod h1:rVKOqvZeKvrDKTQiAHJ7wmwP0RzleSphoEA9RcdLA0s= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.50.0 h1:c2ifzfcuY7L90lZ2aKd8S4K2NpASF08SZx9ZuJkHmSU= golang.org/x/tools v0.50.0/go.mod h1:7ulVMw3831Mwi5EZD6RomGyffr4VFjuNYXf2BbCEAV0= gonum.org/v1/gonum v0.17.0 h1:VbpOemQlsSMrYmn7T2OUvQ4dqxQXU+ouZFQsZOx50z4= diff --git a/internal/app/archied/release_channel.go b/internal/app/archied/release_channel.go deleted file mode 100644 index 4bc31f915..000000000 --- a/internal/app/archied/release_channel.go +++ /dev/null @@ -1,32 +0,0 @@ -package archied - -import ( - "flag" - "fmt" - "io" - "strings" - - "github.com/samcharles93/archie-core/internal/releaseupdate" -) - -func RunReleaseChannel(args []string, in io.Reader, out, stderr io.Writer) int { - flags := flag.NewFlagSet("select-release", flag.ContinueOnError) - flags.SetOutput(stderr) - channel := flags.String("channel", "stable", "stable, next, or exact-pin") - pin := flags.String("pin", "", "exact release version") - if err := flags.Parse(args); err != nil { - return 1 - } - data, err := io.ReadAll(in) - if err != nil { - fmt.Fprintln(stderr, err) - return 1 - } - version, err := releaseupdate.SelectRelease(strings.Fields(string(data)), *channel, *pin) - if err != nil { - fmt.Fprintln(stderr, err) - return 1 - } - fmt.Fprintln(out, version) - return 0 -} diff --git a/internal/app/archied/update_check.go b/internal/app/archied/update_check.go new file mode 100644 index 000000000..348512a89 --- /dev/null +++ b/internal/app/archied/update_check.go @@ -0,0 +1,48 @@ +package archied + +import ( + "context" + "encoding/json" + "flag" + "fmt" + "io" + "os" + + "github.com/samcharles93/archie-core/internal/releaseupdate" +) + +// RunUpdate serves `archied update check`, printing the release snapshot as +// JSON. The channel defaults to the environment the installer passes on. +func RunUpdate(args []string, out, stderr io.Writer) int { + if len(args) == 0 || args[0] != "check" { + fmt.Fprintln(stderr, "usage: archied update check [-channel stable|next|exact-pin] [-pin version]") + return 2 + } + flags := flag.NewFlagSet("update check", flag.ContinueOnError) + flags.SetOutput(stderr) + channel := flags.String("channel", envOr("ARCHIE_UPDATE_RELEASE_CHANNEL", "stable"), "stable, next, or exact-pin") + pin := flags.String("pin", os.Getenv("ARCHIE_UPDATE_PIN"), "exact release version") + if err := flags.Parse(args[1:]); err != nil { + return 2 + } + catalog := releaseupdate.GitHubCatalog{Channel: func(context.Context) (string, string, error) { return *channel, *pin, nil }} + snapshot, err := catalog.Check(context.Background()) + if err != nil { + fmt.Fprintln(stderr, err) + return 1 + } + encoder := json.NewEncoder(out) + encoder.SetIndent("", " ") + if err := encoder.Encode(snapshot); err != nil { + fmt.Fprintln(stderr, err) + return 1 + } + return 0 +} + +func envOr(key, fallback string) string { + if value := os.Getenv(key); value != "" { + return value + } + return fallback +} diff --git a/internal/infrastructure/controlplanerpc/vocabulary.go b/internal/infrastructure/controlplanerpc/vocabulary.go index 06710d693..8b7a29787 100644 --- a/internal/infrastructure/controlplanerpc/vocabulary.go +++ b/internal/infrastructure/controlplanerpc/vocabulary.go @@ -118,23 +118,26 @@ type UpdateSettings struct { Pin string `json:"pin" title:"Pinned version" doc:"The version exact-pin installs."` } -// UpdateService runs the stored update commands, reading them on every call. -// statePath keeps each recipient's deferrals; healthURL reaches the installer. +// UpdateService checks GitHub on the stored release channel and installs +// through the script beside this binary. statePath keeps each recipient's +// deferrals; healthURL reaches the installer. func UpdateService(reader ResourceReader, statePath, healthURL string) *releaseupdate.Service { - commands := releaseupdate.SettingsCommands{Load: updateCommands(reader), HealthURL: healthURL} - return &releaseupdate.Service{Catalog: commands, Installer: commands, StatePath: statePath, InstallType: installtype.Type()} + return &releaseupdate.Service{ + Catalog: releaseupdate.GitHubCatalog{Channel: updateChannel(reader)}, + Installer: releaseupdate.ScriptInstaller{HealthURL: healthURL}, + StatePath: statePath, + InstallType: installtype.Type(), + } } -// updateCommands reads the update-settings resource. An unstored kind is the +// updateChannel reads the update-settings resource. An unstored kind is the // stable channel. -func updateCommands(reader ResourceReader) func(context.Context) (releaseupdate.Commands, error) { - return func(ctx context.Context) (releaseupdate.Commands, error) { +func updateChannel(reader ResourceReader) func(context.Context) (string, string, error) { + return func(ctx context.Context) (string, string, error) { settings := UpdateSettings{Channel: "stable"} - if _, _, err := reader.Query(ctx, UpdateSettingsKind, func(value []byte) error { + _, _, err := reader.Query(ctx, UpdateSettingsKind, func(value []byte) error { return json.Unmarshal(value, &settings) - }); err != nil { - return releaseupdate.Commands{}, err - } - return releaseupdate.ScriptCommands(settings.Channel, settings.Pin), nil + }) + return settings.Channel, settings.Pin, err } } diff --git a/internal/releaseupdate/channel.go b/internal/releaseupdate/channel.go index c7917da80..ae2f2dd36 100644 --- a/internal/releaseupdate/channel.go +++ b/internal/releaseupdate/channel.go @@ -2,7 +2,6 @@ package releaseupdate import ( "fmt" - "regexp" "strings" "golang.org/x/mod/semver" @@ -19,45 +18,3 @@ func ValidateChannel(channel, pin string) error { } return nil } - -// SelectRelease compares release versions, never git-describe strings. Exact -// pins still have to exist in the catalog; a pin cannot invent a release. -func SelectRelease(tags []string, channel, pin string) (string, error) { - if channel == "" { - channel = "stable" - } - if err := ValidateChannel(channel, pin); err != nil { - return "", err - } - pin = strings.TrimPrefix(pin, "v") - fullVersion := regexp.MustCompile(`^v[0-9]+\.[0-9]+\.[0-9]+([+-].*)?$`) - newest := "" - for _, tag := range tags { - tag = strings.TrimPrefix(tag, "refs/tags/") - tag = strings.TrimPrefix(tag, "archied/") - if !fullVersion.MatchString(tag) || !semver.IsValid(tag) { - continue - } - if !releaseMatchesChannel(tag, channel, pin) { - continue - } - if semver.Compare(tag, newest) > 0 { - newest = tag - } - } - if newest == "" { - return "", fmt.Errorf("no release found for channel %s (pin %s)", channel, pin) - } - return strings.TrimPrefix(newest, "v"), nil -} - -func releaseMatchesChannel(tag, channel, pin string) bool { - switch channel { - case "stable": - return semver.Prerelease(tag) == "" - case "exact-pin": - return tag == "v"+pin - default: - return true - } -} diff --git a/internal/releaseupdate/channel_test.go b/internal/releaseupdate/channel_test.go deleted file mode 100644 index 025732d85..000000000 --- a/internal/releaseupdate/channel_test.go +++ /dev/null @@ -1,24 +0,0 @@ -package releaseupdate - -import "testing" - -func TestSelectRelease(t *testing.T) { - tags := []string{"archied/v1.9.0", "v1.10.0", "archied/v2.0.0-rc.2", "v2.0.0-rc.10", "archie/v9.0.0", "nonsense"} - for _, tc := range []struct{ channel, pin, want string }{ - {"stable", "", "1.10.0"}, - {"", "", "1.10.0"}, - {"next", "", "2.0.0-rc.10"}, - {"exact-pin", "1.9.0", "1.9.0"}, - {"exact-pin", "2.0.0-rc.2", "2.0.0-rc.2"}, - {"exact-pin", "9.0.0", ""}, - {"exact-pin", "", ""}, - {"invalid", "", ""}, - } { - t.Run(tc.channel+tc.pin, func(t *testing.T) { - got, err := SelectRelease(tags, tc.channel, tc.pin) - if got != tc.want || (err != nil) != (tc.want == "") { - t.Fatalf("got %q, %v; want %q", got, err, tc.want) - } - }) - } -} diff --git a/internal/releaseupdate/command.go b/internal/releaseupdate/command.go index f17108723..52ae9088d 100644 --- a/internal/releaseupdate/command.go +++ b/internal/releaseupdate/command.go @@ -19,31 +19,6 @@ import ( // as-is. const updateResultSentinel = "ARCHIE_UPDATE_RESULT " -// CommandCatalog reads a Snapshot JSON document from an explicitly configured -// argv command. It never invokes a shell; deployment tooling remains an -// administrator-owned adapter. -type CommandCatalog struct { - Command []string - Env []string -} - -func (c CommandCatalog) Check(ctx context.Context) (Snapshot, error) { - if len(c.Command) == 0 { - return Snapshot{}, fmt.Errorf("update check command is empty") - } - cmd := exec.CommandContext(ctx, c.Command[0], c.Command[1:]...) - cmd.Env = append(cmd.Environ(), c.Env...) - output, err := cmd.Output() - if err != nil { - return Snapshot{}, fmt.Errorf("run update check: %w", err) - } - var snapshot Snapshot - if err := json.Unmarshal(output, &snapshot); err != nil { - return Snapshot{}, fmt.Errorf("decode update check output: %w", err) - } - return snapshot, nil -} - // CommandInstaller runs the deployment's install command. HealthURL is // passed as ARCHIE_HEALTH_URL when set. type CommandInstaller struct { @@ -137,67 +112,30 @@ func componentVersions(snapshot Snapshot) map[string]Component { // ErrNotConfigured is returned when the step's command is unset. var ErrNotConfigured = errors.New("updates are not configured") -// Commands is what a deployment runs to check for and install updates. Env -// is added to the check's environment. -type Commands struct { - Check []string - Install []string - Env []string -} - -// ScriptCommands runs the update scripts a release installs beside this -// binary, selecting releases from channel. Only these scripts ever run, so a -// setting cannot name an arbitrary program. A missing script is unset. -func ScriptCommands(channel, pin string) Commands { - exe, err := os.Executable() - if err != nil { - return Commands{} - } - script := func(name string) []string { - path := filepath.Join(filepath.Dir(exe), name) - if info, err := os.Stat(path); err != nil || info.Mode()&0o111 == 0 { - return nil - } - return []string{path} - } - return Commands{ - Check: script("archie-update-check"), - Install: script("archie-update-install"), - Env: []string{"ARCHIE_UPDATE_RELEASE_CHANNEL=" + channel, "ARCHIE_UPDATE_PIN=" + pin}, - } -} - -// SettingsCommands is both Catalog and Installer. It loads Commands on every -// call so an edited setting applies without a restart. -type SettingsCommands struct { - Load func(context.Context) (Commands, error) +// ScriptInstaller runs the install script a release places beside this binary. +type ScriptInstaller struct { HealthURL string } -func (s SettingsCommands) Check(ctx context.Context) (Snapshot, error) { - commands, err := s.Load(ctx) +func (s ScriptInstaller) path() string { + exe, err := os.Executable() if err != nil { - return Snapshot{}, err + return "" } - if len(commands.Check) == 0 { - return Snapshot{}, ErrNotConfigured + path := filepath.Join(filepath.Dir(exe), "archie-update-install") + if info, err := os.Stat(path); err != nil || info.Mode()&0o111 == 0 { + return "" } - return CommandCatalog{Command: commands.Check, Env: commands.Env}.Check(ctx) + return path } -func (s SettingsCommands) Install(ctx context.Context, snapshot Snapshot, meta InstallMeta, progress func(string)) (Result, error) { - commands, err := s.Load(ctx) - if err != nil { - return Result{}, err - } - if len(commands.Install) == 0 { +func (s ScriptInstaller) Install(ctx context.Context, snapshot Snapshot, meta InstallMeta, progress func(string)) (Result, error) { + path := s.path() + if path == "" { return Result{}, ErrNotConfigured } - return CommandInstaller{Command: commands.Install, HealthURL: s.HealthURL}.Install(ctx, snapshot, meta, progress) + return CommandInstaller{Command: []string{path}, HealthURL: s.HealthURL}.Install(ctx, snapshot, meta, progress) } -// Installable reports whether an install command is set. -func (s SettingsCommands) Installable(ctx context.Context) bool { - commands, err := s.Load(ctx) - return err == nil && len(commands.Install) != 0 -} +// Installable reports whether the install script is present. +func (s ScriptInstaller) Installable(context.Context) bool { return s.path() != "" } diff --git a/internal/releaseupdate/github.go b/internal/releaseupdate/github.go new file mode 100644 index 000000000..ebf73d2df --- /dev/null +++ b/internal/releaseupdate/github.go @@ -0,0 +1,114 @@ +package releaseupdate + +import ( + "context" + "errors" + "fmt" + "os" + "path/filepath" + "regexp" + "strings" + + "github.com/creativeprojects/go-selfupdate" + + "github.com/samcharles93/archie-core/internal/buildinfo" +) + +// ReleaseSlug is the repository releases are published to. +const ReleaseSlug = "samcharles93/archie-core" + +const changelogURL = "https://github.com/" + ReleaseSlug + "/blob/main/CHANGELOG.md" + +// buildSuffix is the git-describe tail of an untagged build (1.7.0-4-g0736708). +var buildSuffix = regexp.MustCompile(`-[0-9]+-g[0-9a-f]+$`) + +// GitHubCatalog finds the newest release on the selected channel that ships a +// linux-amd64 zip, and reports it against this build. Only one version covers +// every component, so the daemon and agent are offered the same release. +type GitHubCatalog struct { + // Channel returns the release channel and pin in force. + Channel func(context.Context) (channel, pin string, err error) +} + +func (c GitHubCatalog) Check(ctx context.Context) (Snapshot, error) { + channel, pin, err := c.Channel(ctx) + if err != nil { + return Snapshot{}, err + } + if channel == "" { + channel = "stable" + } + release, err := detectRelease(ctx, channel, pin) + if err != nil { + return Snapshot{}, err + } + component := func(id, label, installed string) Component { + return Component{ + ID: id, Label: label, + Installed: installed, Available: release.Version(), + Reference: release.AssetName, Changelog: changelogURL, + } + } + return Snapshot{Components: []Component{ + component("daemon", "Gateway", installedVersion(buildinfo.Version)), + component("agent", "Runtime", installedAgent()), + }}, nil +} + +// detectRelease resolves channel to one published release. A release with no +// zip for this platform is not installable, so it is never offered. +func detectRelease(ctx context.Context, channel, pin string) (*selfupdate.Release, error) { + if err := ValidateChannel(channel, pin); err != nil { + return nil, err + } + updater, err := selfupdate.NewUpdater(selfupdate.Config{ + Validator: &selfupdate.ChecksumValidator{UniqueFilename: "SHA256SUMS"}, + Filters: []string{`-linux-amd64\.zip$`}, + OS: "linux", + Arch: "amd64", + Prerelease: channel == "next", + }) + if err != nil { + return nil, err + } + repository := selfupdate.ParseSlug(ReleaseSlug) + var ( + release *selfupdate.Release + found bool + ) + if channel == "exact-pin" { + release, found, err = updater.DetectVersion(ctx, repository, "v"+strings.TrimPrefix(pin, "v")) + } else { + release, found, err = updater.DetectLatest(ctx, repository) + } + if err != nil { + return nil, fmt.Errorf("find releases: %w", err) + } + if !found { + return nil, errors.New("no published release with a linux-amd64 zip matches the channel") + } + return release, nil +} + +func installedVersion(version string) string { + return buildSuffix.ReplaceAllString(version, "") +} + +// installedAgent is the image the installer last switched to, recorded in a +// sidecar beside the binaries; without one it is the runtime this release was +// cut with. A malformed sidecar is unknown, not guessed. +func installedAgent() string { + exe, err := os.Executable() + if err != nil { + return installedVersion(buildinfo.Runtime) + } + data, err := os.ReadFile(filepath.Join(filepath.Dir(exe), "archie-agent.version")) + if errors.Is(err, os.ErrNotExist) { + return installedVersion(buildinfo.Runtime) + } + version := strings.TrimSpace(string(data)) + if err != nil || strings.ContainsAny(version, " \n") || ValidateChannel("exact-pin", version) != nil { + return "" + } + return installedVersion(version) +} diff --git a/internal/releaseupdate/installer_test.go b/internal/releaseupdate/installer_test.go index 861471f0e..1d32a0ddc 100644 --- a/internal/releaseupdate/installer_test.go +++ b/internal/releaseupdate/installer_test.go @@ -161,7 +161,7 @@ func makeUpdateArchive(t *testing.T, root, scripts, scenario string) []byte { for _, name := range []string{"archied", "archie-state-store", "archie-gateway", "archie-ui", "archie-messaging"} { files[name] = "#!/bin/bash\n# new\nif [ \"$1\" = -version ]; then echo '" + name + " 2.0.0'; fi\nexit 0\n" } - for _, name := range []string{"archie-update-install", "archie-update-watchdog", "archie-update-check"} { + for _, name := range []string{"archie-update-install", "archie-update-watchdog"} { data, err := os.ReadFile(filepath.Join(scripts, name)) if err != nil { t.Fatal(err) diff --git a/scripts/archie-update-check b/scripts/archie-update-check deleted file mode 100755 index 6a4b5bd99..000000000 --- a/scripts/archie-update-check +++ /dev/null @@ -1,186 +0,0 @@ -#!/usr/bin/env bash -# archie-update-check -- update discovery adapter for archied's /update command. -# -# Writes a releaseupdate.Snapshot JSON document to stdout. archied runs this -# via CommandCatalog (internal/releaseupdate/command.go), which never invokes -# a shell, so this file must be directly executable. -# -# "Installed" for the daemon is the release the running binary was ACTUALLY -# built from, read via `archied -version`. The agent value in that output is -# only the runtime version the daemon release was cut with; it is not the -# managed image that an installer later rebuilt. The installer therefore owns -# a sidecar beside BIN_DIR, archie-agent.version, and that is authoritative. -# Older installations without the sidecar use the agent line as a compatibility -# fallback. An existing malformed sidecar is reported as unknown, not replaced -# by a fabricated version. Build-stamp git-describe suffixes are stripped for -# comparison (1.7.0-4-g0736708 -> 1.7.0). -# -# "Available" is the newest release TAG, resolved without any dependency on a -# local checkout. Two independent sources, in order: -# -# 1. the forge API (tags + releases), which also reports whether the tag has -# a PUBLISHED artifact -- the thing an artifact install path downloads; -# 2. `git ls-remote` against the source remote, which needs no API and no -# working tree. -# -# The tag is the authority for "an update exists"; the artifact is reported -# separately in Reference, so a tagged-but-unpublished release is still -# announced (it is installable via the source-build fallback) instead of being -# silently hidden. -# -# A tag source that fails to resolve is a FAILURE TO CHECK, not an absence. -# An empty Available means "this component is at the newest release we could -# resolve", so it must never be the result of a probe that failed. When no -# authoritative source answers at all, this script exits non-zero and the -# /update command says it could not check -- rather than rendering a failed -# lookup as "Archie is up to date". -set -uo pipefail - -readonly REPO_SLUG="${ARCHIE_SOURCE_SLUG:-samcharles93/archie-core}" -readonly API_BASE="${ARCHIE_FORGE_API:-https://api.github.com}" -readonly SOURCE_URL="${ARCHIE_SOURCE_URL:-https://github.com/${REPO_SLUG}.git}" -readonly BIN="${ARCHIE_BIN:-$HOME/.local/bin/archied}" -readonly BIN_DIR="${ARCHIE_BIN_DIR:-$(dirname "$BIN")}" -readonly AGENT_VERSION_FILE="${ARCHIE_AGENT_VERSION_FILE:-$BIN_DIR/archie-agent.version}" -readonly CURL_TIMEOUT="${ARCHIE_FORGE_TIMEOUT:-20}" -readonly TOKEN="${ARCHIE_FORGE_TOKEN:-}" - -# base 1.7.0-4-g0736708 -> 1.7.0 -base() { printf '%s\n' "$1" | sed -E 's/-[0-9]+-g[0-9a-f]+$//'; } - -# installed_for reads the version this binary reports for a named component. -# archied stamps both its own version and the runtime version the release was -# cut with, and -version prints one line per component -- so the installed -# runtime is what THIS RELEASE says it was built against, not a stray binary -# on the host. releaseupdate/service.go documents why a host-side archie-agent -# binary cannot answer this: every archie-agent process is task-scoped and -# ephemeral, observed only through a completed taskrun.Response. -installed_for() { - "$BIN" -version 2>/dev/null | awk -v n="$1" '$1 == n { print $2; exit }' -} - -curl_api() { - if [ -n "$TOKEN" ]; then - curl -fsS --max-time "$CURL_TIMEOUT" \ - -H "Authorization: Bearer $TOKEN" \ - -H "Accept: application/vnd.github+json" \ - "$1" 2>/dev/null - else - curl -fsS --max-time "$CURL_TIMEOUT" \ - -H "Accept: application/vnd.github+json" \ - "$1" 2>/dev/null - fi -} - -RELEASE_CHANNEL="${ARCHIE_UPDATE_RELEASE_CHANNEL:-stable}" -PIN="${ARCHIE_UPDATE_PIN:-}" -while [ "$#" -gt 0 ]; do - case "$1" in - --channel) RELEASE_CHANNEL="$2"; shift 2 ;; - --pin) PIN="$2"; shift 2 ;; - *) echo "unknown option: $1" >&2; exit 1 ;; - esac -done -select_release() { "$BIN" select-release -channel "$RELEASE_CHANNEL" -pin "$PIN"; } -newest_tag_git() { - local tags - tags="$(git ls-remote --tags --refs "$SOURCE_URL" 'archied/v*' 'v*' 2>/dev/null)" || return 1 - printf '%s\n' "$tags" | awk '{print $2}' | select_release -} -newest_tag_api() { - local page payload tags="" - for page in $(seq 1 100); do - payload="$(curl_api "${API_BASE}/repos/${REPO_SLUG}/tags?per_page=100&page=${page}")" || return 1 - tags+="$(jq -er '.[].name' <<< "$payload")"$'\n' - if [ "$(jq 'length' <<< "$payload")" -lt 100 ]; then - printf '%s' "$tags" | select_release - return $? - fi - done - echo "tag catalog exceeded pagination limit" >&2 - return 1 -} - -# artifact_state reports whether a tagged release is PUBLISHED with assets, -# which decides whether an artifact install can use it or the source-build -# fallback has to. Purely descriptive: a failure here never fabricates a -# state, it reports "unknown-artifact". -artifact_state() { - local tag="$1" payload count - command -v jq >/dev/null 2>&1 || { printf 'unknown-artifact'; return 0; } - payload="$(curl_api "${API_BASE}/repos/${REPO_SLUG}/releases/tags/${tag}")" || { printf 'no-release'; return 0; } - [ -n "$payload" ] || { printf 'no-release'; return 0; } - count="$(printf '%s\n' "$payload" | jq -r '[.assets[] | select(.name != "")] | length' 2>/dev/null)" - case "${count:-}" in - '' | *[!0-9]*) printf 'unknown-artifact' ;; - 0) printf 'no-artifact' ;; - *) printf '%s-assets' "$count" ;; - esac -} - -esc() { printf '%s' "${1:-}" | sed 's/\\/\\\\/g; s/"/\\"/g'; } - -daemon_installed="$(base "$(installed_for archied || true)")" -agent_installed="" -if [ -f "$AGENT_VERSION_FILE" ]; then - # A sidecar is updater state: accept only one released semantic version and - # deliberately do not fall back if it is empty or malformed. - sidecar_version="$(awk 'NF { if (seen++) { bad=1; next } gsub(/^[[:space:]]+|[[:space:]]+$/, "", $0); print } END { if (bad) exit 1 }' "$AGENT_VERSION_FILE" 2>/dev/null || true)" - if [[ "$sidecar_version" =~ ^[0-9]+\.[0-9]+\.[0-9]+([+-][0-9A-Za-z.-]+)?$ ]]; then - agent_installed="$(base "$sidecar_version")" - fi -else - # Compatibility for hosts installed before the sidecar existed. - agent_installed="$(base "$(installed_for archie-agent || true)")" -fi - -# One version covers every component (RELEASING.md): the runtime image a -# release publishes carries the release's own version, tagged archied/v*. -daemon_available="$(newest_tag_git archied || true)" -tag_source="git-tags" -if [ -z "$daemon_available" ]; then - daemon_available="$(newest_tag_api archied || true)" - tag_source="forge-api-tags" -fi -agent_available="$daemon_available" -if [ -z "$daemon_available" ]; then - # Neither source answered. Report the failure; do not exit 0 with two empty - # components, which the caller renders as "up to date". - echo "archie-update-check: could not resolve any release tag from ${SOURCE_URL} or ${API_BASE}/repos/${REPO_SLUG}/tags" >&2 - exit 1 -fi - -daemon_artifacts="" -[ -n "$daemon_available" ] && daemon_artifacts="$(artifact_state "archied/v${daemon_available}")" -agent_artifacts="" -agent_artifacts="$daemon_artifacts" - -reference_for() { - local component="$1" version="$2" artifacts="$3" - [ -z "$version" ] && { printf ''; return 0; } - printf '%s artifact=%s (%s)' "$tag_source" "$artifacts" "$component" -} - -cat <