This commit moves a huge chunk of the code to go. The TODO.md document indicates what is left to be done.
65 lines
1.8 KiB
Go
65 lines
1.8 KiB
Go
package cmd
|
|
|
|
import (
|
|
wisski_distillery "github.com/FAU-CDI/wisski-distillery"
|
|
"github.com/FAU-CDI/wisski-distillery/env"
|
|
"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: env.Requirements{
|
|
NeedsConfig: 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
|
|
}
|