system_update: Perform provisioning in parallel

This commit is contained in:
Tom Wiesing 2022-09-22 18:06:46 +02:00
parent c091761762
commit 72d95f58ea
No known key found for this signature in database
15 changed files with 182 additions and 27 deletions

78
cmd/drupal_setting.go Normal file
View file

@ -0,0 +1,78 @@
package cmd
import (
"encoding/json"
wisski_distillery "github.com/FAU-CDI/wisski-distillery"
"github.com/FAU-CDI/wisski-distillery/internal/core"
"github.com/tkw1536/goprogram/exit"
)
// DrupalSetting is then 'drupal_setting' command
var DrupalSetting wisski_distillery.Command = setting{}
type setting struct {
Positionals struct {
Slug string `positional-arg-name:"SLUG" required:"1-1" description:"slug of instance to get or set value for"`
Setting string `positional-arg-name:"SETTING" require:"1-1" description:"name of setting to read or write"`
Value string `positional-arg-name:"VALUE" description:"json serialization of value to write"`
} `positional-args:"true"`
}
func (setting) Description() wisski_distillery.Description {
return wisski_distillery.Description{
Requirements: core.Requirements{
NeedsDistillery: true,
},
Command: "drupal_setting",
Description: "Get or set a drupal setting",
}
}
var errSettingGet = exit.Error{
ExitCode: exit.ExitGeneric,
Message: "Unable to get setting",
}
var errSettingSet = exit.Error{
ExitCode: exit.ExitGeneric,
Message: "Unable to set setting",
}
func (ds setting) Run(context wisski_distillery.Context) error {
instance, err := context.Environment.Instances().WissKI(ds.Positionals.Slug)
if err != nil {
return err
}
if ds.Positionals.Value == "" {
// get the setting
value, err := instance.GetSettingsPHP(ds.Positionals.Setting)
if err != nil {
return errSettingGet.Wrap(err)
}
// and print it
if err := json.NewEncoder(context.Stdout).Encode(value); err != nil {
return errSettingGet.Wrap(err)
}
// finish with a newline
context.Println("")
return nil
}
// serialize the setting into json
var data any
if err := json.Unmarshal([]byte(ds.Positionals.Value), &data); err != nil {
return errSettingSet.Wrap(err)
}
// set the serialized value!
if err := instance.SetSettingsPHP(ds.Positionals.Setting, data); err != nil {
return errSettingSet.Wrap(err)
}
// and we're done
return nil
}

View file

@ -1,6 +1,9 @@
package cmd
import (
"fmt"
"io"
wisski_distillery "github.com/FAU-CDI/wisski-distillery"
"github.com/FAU-CDI/wisski-distillery/internal/component"
"github.com/FAU-CDI/wisski-distillery/internal/core"
@ -8,7 +11,9 @@ import (
"github.com/FAU-CDI/wisski-distillery/pkg/fsx"
"github.com/FAU-CDI/wisski-distillery/pkg/logging"
"github.com/tkw1536/goprogram/exit"
"github.com/tkw1536/goprogram/lib/status"
"github.com/tkw1536/goprogram/parser"
"github.com/tkw1536/goprogram/stream"
)
// SystemUpdate is the 'system_update' command
@ -106,24 +111,35 @@ func (si systemupdate) Run(context wisski_distillery.Context) error {
}
if err := logging.LogOperation(func() error {
for _, component := range dis.Installables() {
name := component.Name()
stack := component.Stack(dis.Core.Environment)
ctx := component.Context(ctx)
group := &status.Group[component.Installable]{
Writer: context.Stdout,
PrefixString: func(item component.Installable, index int) string {
return fmt.Sprintf("[install %q]: ", item.Name())
},
PrefixAlign: true,
ErrString: func(item component.Installable, index int, err error) string {
if err == nil {
return "ok"
}
return "failed (" + err.Error() + ")"
},
Handler: func(item component.Installable, index int, writer io.Writer) error {
io := stream.NewIOStream(writer, writer, stream.Null, 0)
stack := item.Stack(context.Environment.Environment)
if err := logging.LogOperation(func() error {
return stack.Install(context.IOStream, ctx)
}, context.IOStream, "Installing Docker Stack %q", name); err != nil {
return err
}
if err := stack.Install(io, item.Context(ctx)); err != nil {
return err
}
if err := logging.LogOperation(func() error {
return stack.Update(context.IOStream, true)
}, context.IOStream, "Updating Docker Stack: %q", name); err != nil {
return err
}
if err := stack.Update(io, true); err != nil {
return err
}
return nil
},
}
return nil
return group.Run(dis.Installables())
}, context.IOStream, "Performing Stack Updates"); err != nil {
return err
}

View file

@ -42,8 +42,10 @@ func init() {
wdcli.Register(cmd.Shell)
wdcli.Register(cmd.BlindUpdate)
wdcli.Register(cmd.UpdatePrefixConfig) // TODO: Move into post-instance configuration
wdcli.Register(cmd.Pathbuilders)
wdcli.Register(cmd.Prefixes)
wdcli.Register(cmd.DrupalSetting)
// backup & cron
wdcli.Register(cmd.Snapshot)