feat(archied): update agent-image sets the image new tasks run
This commit is contained in:
1 parent
e9ecc84064
commit
205d0ec976
1 file changed
+33
-1
@@ -35,11 +35,13 @@ const (
|
||||
const updateUsage = `usage:
|
||||
archied update check [-channel stable|next|exact-pin] [-pin version]
|
||||
archied update install -version X [-config FILE] [-report FILE -channel C -chat ID -thread ID]
|
||||
archied update watchdog [-config FILE] [-recover]`
|
||||
archied update watchdog [-config FILE] [-recover]
|
||||
archied update agent-image [-config FILE] REF`
|
||||
|
||||
// RunUpdate serves `archied update`: check prints the release snapshot,
|
||||
// install verifies and stages a release and hands it to the watchdog, and
|
||||
// watchdog switches over, watches the daemon and commits or rolls back.
|
||||
// agent-image points new tasks at an agent image built outside a release.
|
||||
func RunUpdate(args []string, out, stderr io.Writer) int {
|
||||
if len(args) == 0 {
|
||||
fmt.Fprintln(stderr, updateUsage)
|
||||
@@ -52,12 +54,42 @@ func RunUpdate(args []string, out, stderr io.Writer) int {
|
||||
return runUpdateInstall(args[1:], out, stderr)
|
||||
case "watchdog":
|
||||
return runUpdateWatchdog(args[1:], stderr)
|
||||
case "agent-image":
|
||||
return runUpdateAgentImage(args[1:], out, stderr)
|
||||
default:
|
||||
fmt.Fprintln(stderr, updateUsage)
|
||||
return 2
|
||||
}
|
||||
}
|
||||
|
||||
// runUpdateAgentImage sets the image new tasks run. A release install pins
|
||||
// its image by digest, so a locally loaded build is otherwise never used.
|
||||
func runUpdateAgentImage(args []string, out, stderr io.Writer) int {
|
||||
flags := flag.NewFlagSet("update agent-image", flag.ContinueOnError)
|
||||
flags.SetOutput(stderr)
|
||||
configPath := flags.String("config", configuration.DefaultConfigPath(), "bootstrap config file")
|
||||
if err := flags.Parse(args); err != nil {
|
||||
return 2
|
||||
}
|
||||
if flags.NArg() != 1 {
|
||||
fmt.Fprintln(stderr, updateUsage)
|
||||
return 2
|
||||
}
|
||||
ctx := context.Background()
|
||||
policy := imagePolicy{configPath: *configPath}
|
||||
current, err := policy.Image(ctx)
|
||||
if err != nil {
|
||||
fmt.Fprintln(stderr, err)
|
||||
return 1
|
||||
}
|
||||
if err := policy.SetImage(ctx, current, flags.Arg(0)); err != nil {
|
||||
fmt.Fprintln(stderr, err)
|
||||
return 1
|
||||
}
|
||||
fmt.Fprintf(out, "agent image: %s -> %s\n", current, flags.Arg(0))
|
||||
return 0
|
||||
}
|
||||
|
||||
func runUpdateInstall(args []string, out, stderr io.Writer) int {
|
||||
flags := flag.NewFlagSet("update install", flag.ContinueOnError)
|
||||
flags.SetOutput(stderr)
|
||||
|
||||
Reference in new issue
Block a user