wisski-cloud-distillery/cmd/rebuild.go
Tom Wiesing 4b357476a3
Add 'dis' component
This commit adds a new 'dis' component to the distillery that serves a
list of all known instances for the moment.
2022-09-09 17:10:24 +02:00

65 lines
1.8 KiB
Go

package cmd
import (
wisski_distillery "github.com/FAU-CDI/wisski-distillery"
"github.com/FAU-CDI/wisski-distillery/core"
"github.com/FAU-CDI/wisski-distillery/internal/logging"
"github.com/FAU-CDI/wisski-distillery/internal/stack"
"github.com/tkw1536/goprogram/exit"
)
// Cron is the 'cron' command
var Rebuild wisski_distillery.Command = rebuild{}
type rebuild struct {
Positionals struct {
Slug []string `positional-arg-name:"SLUG" required:"0" description:"slug of instance(s) to run rebuild"`
} `positional-args:"true"`
}
func (rebuild) Description() wisski_distillery.Description {
return wisski_distillery.Description{
Requirements: core.Requirements{
NeedsDistillery: true,
},
Command: "rebuild",
Description: "Runs the rebuild script for several instances",
}
}
var errRebuildFailed = exit.Error{
Message: "Failed to run rebuild script for instance %q: exited with code %s",
ExitCode: exit.ExitGeneric,
}
func (rb rebuild) Run(context wisski_distillery.Context) error {
instances, err := context.Environment.Instances(rb.Positionals.Slug...)
if err != nil {
return err
}
// iterate over the instances and store the last value of error
var globalErr error
for _, instance := range instances {
logging.LogOperation(func() error {
s := instance.Stack()
if err := logging.LogOperation(func() error {
return s.Install(context.IOStream, stack.InstallationContext{})
}, context.IOStream, "Installing docker stack"); err != nil {
globalErr = err
return err
}
if err := logging.LogOperation(func() error {
return s.Update(context.IOStream, true)
}, context.IOStream, "Updating docker stack"); err != nil {
globalErr = err
return err
}
return nil
}, context.IOStream, "Rebuilding instance %s", instance.Slug)
}
return globalErr
}