Do a large chunk of the move to go

This commit moves a huge chunk of the code to go. The TODO.md document
indicates what is left to be done.
This commit is contained in:
Tom Wiesing 2022-08-14 10:57:59 +02:00
parent db2ad9b4bd
commit 7b38fdd801
No known key found for this signature in database
93 changed files with 4689 additions and 645 deletions

65
cmd/rebuild.go Normal file
View file

@ -0,0 +1,65 @@
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
}