fix(release): ship archie-agent beside archied so Kit runs have one to mount
This commit is contained in:
1 parent
e5d02d9980
commit
d26bc875ac
8 files changed
+58
-25
No files matched your search
@@ -18,6 +18,7 @@ import (
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"runtime"
|
||||
"slices"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@@ -90,8 +91,8 @@ func (t *Transaction) Prepare(ctx context.Context, req PrepareRequest) (Result,
|
||||
return Result{}, err
|
||||
}
|
||||
if err := t.stage(req, release, j); err != nil {
|
||||
for _, unit := range j.Units {
|
||||
_ = os.Remove(t.staged(unit))
|
||||
for _, app := range append(slices.Clone(j.Units), j.Binaries...) {
|
||||
_ = os.Remove(t.staged(app))
|
||||
}
|
||||
return Result{}, err
|
||||
}
|
||||
@@ -128,13 +129,13 @@ func (t *Transaction) fetch(ctx context.Context, req PrepareRequest, work string
|
||||
if err != nil {
|
||||
return "", Manifest{}, err
|
||||
}
|
||||
for _, unit := range manifest.Required.Units {
|
||||
reported, err := reportedVersion(ctx, filepath.Join(release, unit), unit)
|
||||
for _, binary := range manifest.Required.apps() {
|
||||
reported, err := reportedVersion(ctx, filepath.Join(release, binary), binary)
|
||||
if err != nil {
|
||||
return "", Manifest{}, err
|
||||
}
|
||||
if !sameVersion(reported, req.Version) {
|
||||
return "", Manifest{}, fmt.Errorf("candidate %s reports %q, not %s", unit, reported, req.Version)
|
||||
return "", Manifest{}, fmt.Errorf("candidate %s reports %q, not %s", binary, reported, req.Version)
|
||||
}
|
||||
}
|
||||
return release, manifest, nil
|
||||
@@ -167,6 +168,7 @@ func (t *Transaction) snapshotHost(ctx context.Context, req PrepareRequest, mani
|
||||
ComponentAgent: installedAgent(t.BinDir),
|
||||
},
|
||||
Units: manifest.Required.Units,
|
||||
Binaries: manifest.Required.Binaries,
|
||||
Managed: managed,
|
||||
Image: imageChange{Previous: image, Candidate: manifest.AgentImage},
|
||||
SchemaBefore: schema,
|
||||
@@ -189,7 +191,7 @@ func (t *Transaction) stage(req PrepareRequest, release string, j journal) error
|
||||
if err := installFile(filepath.Join(release, WatchdogBinary), filepath.Join(preparing, WatchdogBinary), 0o700); err != nil {
|
||||
return fmt.Errorf("freeze the watchdog: %w", err)
|
||||
}
|
||||
for _, unit := range j.Units {
|
||||
for _, unit := range append(slices.Clone(j.Units), j.Binaries...) {
|
||||
live := filepath.Join(t.BinDir, unit)
|
||||
if _, err := os.Stat(live); err == nil {
|
||||
if err := installFile(live, filepath.Join(preparing, "previous", unit), 0o755); err != nil {
|
||||
@@ -340,7 +342,7 @@ func readManifest(path string) (Manifest, error) {
|
||||
if len(manifest.Required.Units) == 0 {
|
||||
return Manifest{}, errors.New("release has no required_topology")
|
||||
}
|
||||
for _, unit := range manifest.Required.Units {
|
||||
for _, unit := range manifest.Required.apps() {
|
||||
if !releaseUnit.MatchString(unit) {
|
||||
return Manifest{}, fmt.Errorf("invalid release unit %q", unit)
|
||||
}
|
||||
|
||||
@@ -1,12 +1,24 @@
|
||||
package releaseupdate
|
||||
|
||||
import "fmt"
|
||||
import (
|
||||
"fmt"
|
||||
"slices"
|
||||
)
|
||||
|
||||
type Topology struct {
|
||||
Units []string `json:"units"`
|
||||
ConfigSections []string `json:"config_sections"`
|
||||
// Binaries are the release's host binaries that run beside the units
|
||||
// without a service of their own, such as the archie-agent a Kit run
|
||||
// mounts from archied's directory. They are installed and switched with
|
||||
// the units and are never started, stopped or demanded as a unit.
|
||||
Binaries []string `json:"binaries,omitempty"`
|
||||
}
|
||||
|
||||
// apps returns the binaries the release installs: its units, and the host
|
||||
// binaries that run beside them without a service.
|
||||
func (t Topology) apps() []string { return append(slices.Clone(t.Units), t.Binaries...) }
|
||||
|
||||
// MigrationPlan preserves the release's dependency order. Unknown observations
|
||||
// require every step to be checked manually rather than assuming a partial host.
|
||||
func (t Topology) MigrationPlan(units, sections map[string]bool) []string {
|
||||
|
||||
@@ -106,6 +106,7 @@ type journal struct {
|
||||
Version string `json:"version"`
|
||||
Previous map[string]string `json:"previous"`
|
||||
Units []string `json:"units"`
|
||||
Binaries []string `json:"binaries,omitempty"`
|
||||
Managed bool `json:"managed"`
|
||||
Image imageChange `json:"image"`
|
||||
SchemaBefore int64 `json:"schema_before"`
|
||||
@@ -180,7 +181,7 @@ func (t *Transaction) switchOver(ctx context.Context, j *journal) error {
|
||||
if err := t.stopUnits(ctx, *j); err != nil {
|
||||
return err
|
||||
}
|
||||
for _, unit := range j.Units {
|
||||
for _, unit := range append(slices.Clone(j.Units), j.Binaries...) {
|
||||
if err := os.Rename(t.staged(unit), filepath.Join(t.BinDir, unit)); err != nil {
|
||||
return fmt.Errorf("switch %s: %w", unit, err)
|
||||
}
|
||||
@@ -250,8 +251,8 @@ func (t *Transaction) rollback(ctx context.Context, j journal) error {
|
||||
// abandon discards a transaction that never switched anything.
|
||||
func (t *Transaction) abandon(ctx context.Context, j journal) error {
|
||||
t.say("update to %s was staged but never started; discarding it", j.Version)
|
||||
for _, unit := range j.Units {
|
||||
if err := os.Remove(t.staged(unit)); err != nil && !errors.Is(err, os.ErrNotExist) {
|
||||
for _, app := range append(slices.Clone(j.Units), j.Binaries...) {
|
||||
if err := os.Remove(t.staged(app)); err != nil && !errors.Is(err, os.ErrNotExist) {
|
||||
return err
|
||||
}
|
||||
}
|
||||
@@ -273,7 +274,7 @@ func (t *Transaction) incomplete(err error) error {
|
||||
|
||||
func (t *Transaction) restoreFiles(j journal) error {
|
||||
previous := filepath.Join(JournalPath(t.StateDir), "previous")
|
||||
for _, unit := range j.Units {
|
||||
for _, unit := range append(slices.Clone(j.Units), j.Binaries...) {
|
||||
live := filepath.Join(t.BinDir, unit)
|
||||
saved := filepath.Join(previous, unit)
|
||||
if _, err := os.Stat(saved); errors.Is(err, os.ErrNotExist) {
|
||||
|
||||
Reference in new issue
Block a user