wdcli: Use progress writer instead of IOStream
This commit is contained in:
parent
890022ae64
commit
3b78b06fff
49 changed files with 396 additions and 393 deletions
|
|
@ -41,12 +41,12 @@ func (bk backup) Run(context wisski_distillery.Context) error {
|
|||
// prune old backups
|
||||
if !bk.NoPrune {
|
||||
defer logging.LogOperation(func() error {
|
||||
return dis.Exporter().PruneExports(context.Context, context.IOStream)
|
||||
}, context.IOStream, "Pruning old backups")
|
||||
return dis.Exporter().PruneExports(context.Context, context.Stderr)
|
||||
}, context.Stderr, "Pruning old backups")
|
||||
}
|
||||
|
||||
// do the handling
|
||||
err := dis.Exporter().MakeExport(context.Context, context.IOStream, exporter.ExportTask{
|
||||
err := dis.Exporter().MakeExport(context.Context, context.Stderr, exporter.ExportTask{
|
||||
Dest: bk.Positionals.Dest,
|
||||
StagingOnly: bk.StagingOnly,
|
||||
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package cmd
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
|
||||
wisski_distillery "github.com/FAU-CDI/wisski-distillery"
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/cli"
|
||||
|
|
@ -9,7 +10,6 @@ import (
|
|||
"github.com/tkw1536/goprogram/exit"
|
||||
"github.com/tkw1536/goprogram/lib/collection"
|
||||
"github.com/tkw1536/goprogram/status"
|
||||
"github.com/tkw1536/goprogram/stream"
|
||||
)
|
||||
|
||||
// BlindUpdate is the 'blind_update' command
|
||||
|
|
@ -51,8 +51,8 @@ func (bu blindUpdate) Run(context wisski_distillery.Context) error {
|
|||
}
|
||||
|
||||
// and do the actual blind_update!
|
||||
return status.StreamGroup(context.IOStream, bu.Parallel, func(instance *wisski.WissKI, str stream.IOStream) error {
|
||||
return instance.Drush().Update(context.Context, str)
|
||||
return status.WriterGroup(context.Stderr, bu.Parallel, func(instance *wisski.WissKI, writer io.Writer) error {
|
||||
return instance.Drush().Update(context.Context, writer)
|
||||
}, wissKIs, status.SmartMessage(func(item *wisski.WissKI) string {
|
||||
return fmt.Sprintf("blind_update %q", item.Slug)
|
||||
}))
|
||||
|
|
|
|||
|
|
@ -84,7 +84,7 @@ func (bs cBootstrap) Run(context wisski_distillery.Context) error {
|
|||
}
|
||||
|
||||
{
|
||||
logging.LogMessage(context.IOStream, "Creating root deployment directory")
|
||||
logging.LogMessage(context.Stderr, "Creating root deployment directory")
|
||||
if err := env.MkdirAll(root, environment.DefaultDirPerm); err != nil {
|
||||
return errBootstrapFailedToCreateDirectory.WithMessageF(root)
|
||||
}
|
||||
|
|
@ -109,7 +109,7 @@ func (bs cBootstrap) Run(context wisski_distillery.Context) error {
|
|||
}
|
||||
|
||||
{
|
||||
logging.LogMessage(context.IOStream, "Copying over wdcli executable")
|
||||
logging.LogMessage(context.Stderr, "Copying over wdcli executable")
|
||||
exe, err := env.Executable()
|
||||
if err != nil {
|
||||
return errBoostrapFailedToCopyExe.WithMessageF(err)
|
||||
|
|
@ -132,7 +132,7 @@ func (bs cBootstrap) Run(context wisski_distillery.Context) error {
|
|||
defer env.Close()
|
||||
|
||||
return tpl.MarshalTo(env)
|
||||
}, context.IOStream, "Installing configuration file"); err != nil {
|
||||
}, context.Stderr, "Installing configuration file"); err != nil {
|
||||
return errBootstrapWriteConfig.WithMessageF(err)
|
||||
}
|
||||
|
||||
|
|
@ -169,7 +169,7 @@ func (bs cBootstrap) Run(context wisski_distillery.Context) error {
|
|||
}
|
||||
|
||||
return nil
|
||||
}, context.IOStream, "Creating additional config files"); err != nil {
|
||||
}, context.Stderr, "Creating additional config files"); err != nil {
|
||||
return errBootstrapCreateFile.WithMessageF(err)
|
||||
}
|
||||
}
|
||||
|
|
@ -177,7 +177,7 @@ func (bs cBootstrap) Run(context wisski_distillery.Context) error {
|
|||
}
|
||||
|
||||
// re-read the configuration and print it!
|
||||
logging.LogMessage(context.IOStream, "Configuration is now complete")
|
||||
logging.LogMessage(context.Stderr, "Configuration is now complete")
|
||||
f, err := env.Open(envPath)
|
||||
if err != nil {
|
||||
return errBootstrapOpenConfig.WithMessageF(err)
|
||||
|
|
@ -191,7 +191,7 @@ func (bs cBootstrap) Run(context wisski_distillery.Context) error {
|
|||
context.Println(cfg)
|
||||
|
||||
// Tell the user how to proceed
|
||||
logging.LogMessage(context.IOStream, "Bootstrap is complete")
|
||||
logging.LogMessage(context.Stderr, "Bootstrap is complete")
|
||||
context.Printf("Adjust the configuration file at %s\n", envPath)
|
||||
context.Printf("Then make sure 'docker compose' is installed.\n")
|
||||
context.Printf("Finally grab a GraphDB zipped source file and run:\n")
|
||||
|
|
|
|||
|
|
@ -2,12 +2,12 @@ package cmd
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
|
||||
wisski_distillery "github.com/FAU-CDI/wisski-distillery"
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/cli"
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/wisski"
|
||||
"github.com/tkw1536/goprogram/status"
|
||||
"github.com/tkw1536/goprogram/stream"
|
||||
)
|
||||
|
||||
// Cron is the 'cron' command
|
||||
|
|
@ -39,8 +39,8 @@ func (cr cron) Run(context wisski_distillery.Context) error {
|
|||
}
|
||||
|
||||
// and do the actual blind_update!
|
||||
return status.StreamGroup(context.IOStream, cr.Parallel, func(instance *wisski.WissKI, io stream.IOStream) error {
|
||||
return instance.Drush().Cron(context.Context, io)
|
||||
return status.WriterGroup(context.Stderr, cr.Parallel, func(instance *wisski.WissKI, writer io.Writer) error {
|
||||
return instance.Drush().Cron(context.Context, writer)
|
||||
}, wissKIs, status.SmartMessage(func(item *wisski.WissKI) string {
|
||||
return fmt.Sprintf("cron %q", item.Slug)
|
||||
}))
|
||||
|
|
|
|||
|
|
@ -39,36 +39,36 @@ func (monday monday) AfterParse() error {
|
|||
func (monday monday) Run(context wisski_distillery.Context) error {
|
||||
if err := logging.LogOperation(func() error {
|
||||
return context.Exec("backup")
|
||||
}, context.IOStream, "Running backup"); err != nil {
|
||||
}, context.Stderr, "Running backup"); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := logging.LogOperation(func() error {
|
||||
return context.Exec("system_update", monday.Positionals.GraphdbZip)
|
||||
}, context.IOStream, "Running system_update"); err != nil {
|
||||
}, context.Stderr, "Running system_update"); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := logging.LogOperation(func() error {
|
||||
return context.Exec("rebuild")
|
||||
}, context.IOStream, "Running rebuild"); err != nil {
|
||||
}, context.Stderr, "Running rebuild"); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := logging.LogOperation(func() error {
|
||||
return context.Exec("update_prefix_config")
|
||||
}, context.IOStream, "Running update_prefix_config"); err != nil {
|
||||
}, context.Stderr, "Running update_prefix_config"); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if monday.UpdateInstances {
|
||||
if err := logging.LogOperation(func() error {
|
||||
return context.Exec("blind_update")
|
||||
}, context.IOStream, "Running blind_update"); err != nil {
|
||||
}, context.Stderr, "Running blind_update"); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
logging.LogMessage(context.IOStream, "Done, have a great week!")
|
||||
logging.LogMessage(context.Stderr, "Done, have a great week!")
|
||||
return nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ func (p provision) Run(context wisski_distillery.Context) error {
|
|||
slug := p.Positionals.Slug
|
||||
|
||||
// check that it doesn't already exist
|
||||
logging.LogMessage(context.IOStream, "Provisioning new WissKI instance %s", slug)
|
||||
logging.LogMessage(context.Stderr, "Provisioning new WissKI instance %s", slug)
|
||||
if exists, err := dis.Instances().Has(context.Context, slug); err != nil || exists {
|
||||
return errProvisionAlreadyExists.WithMessageF(slug)
|
||||
}
|
||||
|
|
@ -56,7 +56,7 @@ func (p provision) Run(context wisski_distillery.Context) error {
|
|||
}
|
||||
|
||||
// check that the base directory does not exist
|
||||
logging.LogMessage(context.IOStream, "Checking that base directory %s does not exist", instance.FilesystemBase)
|
||||
logging.LogMessage(context.Stderr, "Checking that base directory %s does not exist", instance.FilesystemBase)
|
||||
if fsx.IsDirectory(dis.Environment, instance.FilesystemBase) {
|
||||
return errProvisionAlreadyExists.WithMessageF(slug)
|
||||
}
|
||||
|
|
@ -68,7 +68,7 @@ func (p provision) Run(context wisski_distillery.Context) error {
|
|||
}
|
||||
|
||||
return nil
|
||||
}, context.IOStream, "Updating bookkeeping database"); err != nil {
|
||||
}, context.Stderr, "Updating bookkeeping database"); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
@ -76,7 +76,7 @@ func (p provision) Run(context wisski_distillery.Context) error {
|
|||
if err := logging.LogOperation(func() error {
|
||||
domain := instance.Domain()
|
||||
for _, pc := range dis.Provisionable() {
|
||||
logging.LogMessage(context.IOStream, "Provisioning %s resources", pc.Name())
|
||||
logging.LogMessage(context.Stderr, "Provisioning %s resources", pc.Name())
|
||||
err := pc.Provision(context.Context, instance.Instance, domain)
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
@ -84,29 +84,29 @@ func (p provision) Run(context wisski_distillery.Context) error {
|
|||
}
|
||||
|
||||
return nil
|
||||
}, context.IOStream, "Provisioning instance-specific resources"); err != nil {
|
||||
}, context.Stderr, "Provisioning instance-specific resources"); err != nil {
|
||||
return errProvisionGeneric.WithMessageF(slug, err)
|
||||
}
|
||||
|
||||
// run the provision script
|
||||
if err := logging.LogOperation(func() error {
|
||||
if err := instance.Provisioner().Provision(context.Context, context.IOStream); err != nil {
|
||||
if err := instance.Provisioner().Provision(context.Context, context.Stderr); err != nil {
|
||||
return errProvisionGeneric.WithMessageF(slug, err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}, context.IOStream, "Running setup scripts"); err != nil {
|
||||
}, context.Stderr, "Running setup scripts"); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// start the container!
|
||||
logging.LogMessage(context.IOStream, "Starting Container")
|
||||
if err := instance.Barrel().Stack().Up(context.Context, context.IOStream); err != nil {
|
||||
logging.LogMessage(context.Stderr, "Starting Container")
|
||||
if err := instance.Barrel().Stack().Up(context.Context, context.Stderr); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// and we're done!
|
||||
logging.LogMessage(context.IOStream, "Instance has been provisioned")
|
||||
logging.LogMessage(context.Stderr, "Instance has been provisioned")
|
||||
context.Printf("URL: %s\n", instance.URL().String())
|
||||
context.Printf("Username: %s\n", instance.DrupalUsername)
|
||||
context.Printf("Password: %s\n", instance.DrupalPassword)
|
||||
|
|
|
|||
18
cmd/purge.go
18
cmd/purge.go
|
|
@ -58,7 +58,7 @@ func (p purge) Run(context wisski_distillery.Context) error {
|
|||
}
|
||||
|
||||
// load the instance (first via bookkeeping, then via defaults)
|
||||
logging.LogMessage(context.IOStream, "Checking bookkeeping table")
|
||||
logging.LogMessage(context.Stderr, "Checking bookkeeping table")
|
||||
instance, err := dis.Instances().WissKI(context.Context, slug)
|
||||
if err == instances.ErrWissKINotFound {
|
||||
context.Println("Not found in bookkeeping table, assuming defaults")
|
||||
|
|
@ -69,13 +69,13 @@ func (p purge) Run(context wisski_distillery.Context) error {
|
|||
}
|
||||
|
||||
// remove docker stack
|
||||
logging.LogMessage(context.IOStream, "Stopping and removing docker container")
|
||||
if err := instance.Barrel().Stack().Down(context.Context, context.IOStream); err != nil {
|
||||
logging.LogMessage(context.Stderr, "Stopping and removing docker container")
|
||||
if err := instance.Barrel().Stack().Down(context.Context, context.Stderr); err != nil {
|
||||
context.EPrintln(err)
|
||||
}
|
||||
|
||||
// remove the filesystem
|
||||
logging.LogMessage(context.IOStream, "Removing from filesystem %s", instance.FilesystemBase)
|
||||
logging.LogMessage(context.Stderr, "Removing from filesystem %s", instance.FilesystemBase)
|
||||
if err := dis.Still.Environment.RemoveAll(instance.FilesystemBase); err != nil {
|
||||
context.EPrintln(err)
|
||||
}
|
||||
|
|
@ -84,7 +84,7 @@ func (p purge) Run(context wisski_distillery.Context) error {
|
|||
if err := logging.LogOperation(func() error {
|
||||
domain := instance.Domain()
|
||||
for _, pc := range dis.Provisionable() {
|
||||
logging.LogMessage(context.IOStream, "Purging %s resources", pc.Name())
|
||||
logging.LogMessage(context.Stderr, "Purging %s resources", pc.Name())
|
||||
err := pc.Purge(context.Context, instance.Instance, domain)
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
@ -92,22 +92,22 @@ func (p purge) Run(context wisski_distillery.Context) error {
|
|||
}
|
||||
|
||||
return nil
|
||||
}, context.IOStream, "Purging instance-specific resources"); err != nil {
|
||||
}, context.Stderr, "Purging instance-specific resources"); err != nil {
|
||||
return errPurgeGeneric.WithMessageF(slug, err)
|
||||
}
|
||||
|
||||
// remove from bookkeeping
|
||||
logging.LogMessage(context.IOStream, "Removing instance from bookkeeping")
|
||||
logging.LogMessage(context.Stderr, "Removing instance from bookkeeping")
|
||||
if err := instance.Bookkeeping().Delete(context.Context); err != nil {
|
||||
context.EPrintln(err)
|
||||
}
|
||||
|
||||
// remove the filesystem
|
||||
logging.LogMessage(context.IOStream, "Remove lock data")
|
||||
logging.LogMessage(context.Stderr, "Remove lock data")
|
||||
if instance.Locker().TryUnlock(context.Context) {
|
||||
context.EPrintln("instance was not locked")
|
||||
}
|
||||
|
||||
logging.LogMessage(context.IOStream, "Instance %s has been purged", slug)
|
||||
logging.LogMessage(context.Stderr, "Instance %s has been purged", slug)
|
||||
return nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,13 +2,13 @@ package cmd
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
|
||||
wisski_distillery "github.com/FAU-CDI/wisski-distillery"
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/cli"
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/wisski"
|
||||
"github.com/tkw1536/goprogram/exit"
|
||||
"github.com/tkw1536/goprogram/status"
|
||||
"github.com/tkw1536/goprogram/stream"
|
||||
)
|
||||
|
||||
// Cron is the 'cron' command
|
||||
|
|
@ -46,8 +46,8 @@ func (rb rebuild) Run(context wisski_distillery.Context) error {
|
|||
}
|
||||
|
||||
// and do the actual rebuild
|
||||
return status.StreamGroup(context.IOStream, rb.Parallel, func(instance *wisski.WissKI, io stream.IOStream) error {
|
||||
return instance.Barrel().Build(context.Context, io, true)
|
||||
return status.WriterGroup(context.Stderr, rb.Parallel, func(instance *wisski.WissKI, writer io.Writer) error {
|
||||
return instance.Barrel().Build(context.Context, writer, true)
|
||||
}, wissKIs, status.SmartMessage(func(item *wisski.WissKI) string {
|
||||
return fmt.Sprintf("rebuild %q", item.Slug)
|
||||
}))
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ func (r reserve) Run(context wisski_distillery.Context) error {
|
|||
slug := r.Positionals.Slug
|
||||
|
||||
// check that it doesn't already exist
|
||||
logging.LogMessage(context.IOStream, "Reserving new WissKI instance %s", slug)
|
||||
logging.LogMessage(context.Stderr, "Reserving new WissKI instance %s", slug)
|
||||
if exists, err := dis.Instances().Has(context.Context, slug); err != nil || exists {
|
||||
return errProvisionAlreadyExists.WithMessageF(slug)
|
||||
}
|
||||
|
|
@ -57,7 +57,7 @@ func (r reserve) Run(context wisski_distillery.Context) error {
|
|||
}
|
||||
|
||||
// check that the base directory does not exist
|
||||
logging.LogMessage(context.IOStream, "Checking that base directory %s does not exist", instance.FilesystemBase)
|
||||
logging.LogMessage(context.Stderr, "Checking that base directory %s does not exist", instance.FilesystemBase)
|
||||
if fsx.IsDirectory(dis.Environment, instance.FilesystemBase) {
|
||||
return errProvisionAlreadyExists.WithMessageF(slug)
|
||||
}
|
||||
|
|
@ -66,20 +66,20 @@ func (r reserve) Run(context wisski_distillery.Context) error {
|
|||
s := instance.Reserve().Stack()
|
||||
{
|
||||
if err := logging.LogOperation(func() error {
|
||||
return s.Install(context.Context, context.IOStream, component.InstallationContext{})
|
||||
}, context.IOStream, "Installing docker stack"); err != nil {
|
||||
return s.Install(context.Context, context.Stderr, component.InstallationContext{})
|
||||
}, context.Stderr, "Installing docker stack"); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := logging.LogOperation(func() error {
|
||||
return s.Update(context.Context, context.IOStream, true)
|
||||
}, context.IOStream, "Updating docker stack"); err != nil {
|
||||
return s.Update(context.Context, context.Stderr, true)
|
||||
}, context.Stderr, "Updating docker stack"); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
// and we're done!
|
||||
logging.LogMessage(context.IOStream, "Instance has been reserved")
|
||||
logging.LogMessage(context.Stderr, "Instance has been reserved")
|
||||
context.Printf("URL: %s\n", instance.URL().String())
|
||||
|
||||
return nil
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ var errServerListen = exit.Error{
|
|||
|
||||
func (s server) Run(context wisski_distillery.Context) error {
|
||||
dis := context.Environment
|
||||
handler, err := dis.Control().Server(context.Context, context.IOStream)
|
||||
handler, err := dis.Control().Server(context.Context, context.Stderr)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ func (sn snapshot) Run(context wisski_distillery.Context) error {
|
|||
}
|
||||
|
||||
// do a snapshot of it!
|
||||
err = dis.Exporter().MakeExport(context.Context, context.IOStream, exporter.ExportTask{
|
||||
err = dis.Exporter().MakeExport(context.Context, context.Stderr, exporter.ExportTask{
|
||||
Dest: sn.Positionals.Dest,
|
||||
StagingOnly: sn.StagingOnly,
|
||||
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ var errSSHListen = exit.Error{
|
|||
|
||||
func (s ssh) Run(context wisski_distillery.Context) error {
|
||||
dis := context.Environment
|
||||
server, err := dis.SSH().Server(context.Context, s.PrivateKeyPath, context.IOStream)
|
||||
server, err := dis.SSH().Server(context.Context, s.PrivateKeyPath, context.Stderr)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,7 +12,6 @@ import (
|
|||
"github.com/FAU-CDI/wisski-distillery/pkg/logging"
|
||||
"github.com/tkw1536/goprogram/exit"
|
||||
"github.com/tkw1536/goprogram/status"
|
||||
"github.com/tkw1536/goprogram/stream"
|
||||
)
|
||||
|
||||
// SystemPause is the 'system_pause' command
|
||||
|
|
@ -54,24 +53,23 @@ func (sp systempause) Run(context wisski_distillery.Context) error {
|
|||
}
|
||||
|
||||
func (sp systempause) start(context wisski_distillery.Context, dis *dis.Distillery) error {
|
||||
logging.LogMessage(context.IOStream, "Starting Components")
|
||||
logging.LogMessage(context.Stderr, "Starting Components")
|
||||
|
||||
// find all the core stacks
|
||||
if err := status.RunErrorGroup(context.Stdout, status.Group[component.Installable, error]{
|
||||
if err := status.RunErrorGroup(context.Stderr, status.Group[component.Installable, error]{
|
||||
PrefixString: func(item component.Installable, index int) string {
|
||||
return fmt.Sprintf("[up %q]: ", item.Name())
|
||||
},
|
||||
PrefixAlign: true,
|
||||
|
||||
Handler: func(item component.Installable, index int, writer io.Writer) error {
|
||||
io := stream.NewIOStream(writer, writer, stream.Null, 0)
|
||||
return item.Stack(context.Environment.Environment).Up(context.Context, io)
|
||||
return item.Stack(context.Environment.Environment).Up(context.Context, writer)
|
||||
},
|
||||
}, dis.Installable()); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
logging.LogMessage(context.IOStream, "Starting Up WissKIs")
|
||||
logging.LogMessage(context.Stderr, "Starting Up WissKIs")
|
||||
|
||||
// find the instances
|
||||
wissKIs, err := dis.Instances().All(context.Context)
|
||||
|
|
@ -80,15 +78,14 @@ func (sp systempause) start(context wisski_distillery.Context, dis *dis.Distille
|
|||
}
|
||||
|
||||
// shut them all down
|
||||
if err := status.RunErrorGroup(context.Stdout, status.Group[*wisski.WissKI, error]{
|
||||
if err := status.RunErrorGroup(context.Stderr, status.Group[*wisski.WissKI, error]{
|
||||
PrefixString: func(item *wisski.WissKI, index int) string {
|
||||
return fmt.Sprintf("[up %q]: ", item.Slug)
|
||||
},
|
||||
PrefixAlign: true,
|
||||
|
||||
Handler: func(item *wisski.WissKI, index int, writer io.Writer) error {
|
||||
io := stream.NewIOStream(writer, writer, stream.Null, 0)
|
||||
return item.Barrel().Stack().Up(context.Context, io)
|
||||
return item.Barrel().Stack().Up(context.Context, writer)
|
||||
},
|
||||
}, wissKIs); err != nil {
|
||||
return err
|
||||
|
|
@ -98,7 +95,7 @@ func (sp systempause) start(context wisski_distillery.Context, dis *dis.Distille
|
|||
}
|
||||
|
||||
func (sp systempause) stop(context wisski_distillery.Context, dis *dis.Distillery) error {
|
||||
logging.LogMessage(context.IOStream, "Shutting Down WissKIs")
|
||||
logging.LogMessage(context.Stderr, "Shutting Down WissKIs")
|
||||
|
||||
// find the instances
|
||||
wissKIs, err := dis.Instances().All(context.Context)
|
||||
|
|
@ -107,32 +104,30 @@ func (sp systempause) stop(context wisski_distillery.Context, dis *dis.Distiller
|
|||
}
|
||||
|
||||
// shut them all down
|
||||
if err := status.RunErrorGroup(context.Stdout, status.Group[*wisski.WissKI, error]{
|
||||
if err := status.RunErrorGroup(context.Stderr, status.Group[*wisski.WissKI, error]{
|
||||
PrefixString: func(item *wisski.WissKI, index int) string {
|
||||
return fmt.Sprintf("[down %q]: ", item.Slug)
|
||||
},
|
||||
PrefixAlign: true,
|
||||
|
||||
Handler: func(item *wisski.WissKI, index int, writer io.Writer) error {
|
||||
io := stream.NewIOStream(writer, writer, stream.Null, 0)
|
||||
return item.Barrel().Stack().Down(context.Context, io)
|
||||
return item.Barrel().Stack().Down(context.Context, writer)
|
||||
},
|
||||
}, wissKIs); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
logging.LogMessage(context.IOStream, "Shutting Down Components")
|
||||
logging.LogMessage(context.Stderr, "Shutting Down Components")
|
||||
|
||||
// find all the core stacks
|
||||
if err := status.RunErrorGroup(context.Stdout, status.Group[component.Installable, error]{
|
||||
if err := status.RunErrorGroup(context.Stderr, status.Group[component.Installable, error]{
|
||||
PrefixString: func(item component.Installable, index int) string {
|
||||
return fmt.Sprintf("[down %q]: ", item.Name())
|
||||
},
|
||||
PrefixAlign: true,
|
||||
|
||||
Handler: func(item component.Installable, index int, writer io.Writer) error {
|
||||
io := stream.NewIOStream(writer, writer, stream.Null, 0)
|
||||
return item.Stack(context.Environment.Environment).Down(context.Context, io)
|
||||
return item.Stack(context.Environment.Environment).Down(context.Context, writer)
|
||||
},
|
||||
}, dis.Installable()); err != nil {
|
||||
return err
|
||||
|
|
@ -140,48 +135,3 @@ func (sp systempause) stop(context wisski_distillery.Context, dis *dis.Distiller
|
|||
|
||||
return nil
|
||||
}
|
||||
|
||||
/*
|
||||
handleStack := func(io stream.IOStream, stack component.StackWithResources) error {
|
||||
if sp.Start {
|
||||
return stack.Up(io)
|
||||
} else {
|
||||
return stack.Down(io)
|
||||
}
|
||||
}
|
||||
|
||||
logging.LogMessage(context.IOStream, "Iterating over components")
|
||||
if err := status.RunErrorGroup(context.Stdout, status.Group[component.Installable, error]{
|
||||
PrefixString: func(item component.Installable, index int) string {
|
||||
return fmt.Sprintf("[%s %q]: ", verb, item.Name())
|
||||
},
|
||||
PrefixAlign: true,
|
||||
|
||||
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)
|
||||
|
||||
return handleStack(io, stack)
|
||||
},
|
||||
}, dis.Installable()); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
logging.LogMessage(context.IOStream, "Shutting Down WissKIs")
|
||||
|
||||
// find the instances
|
||||
wissKIs, err := dis.Instances().All()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// and do the actual rebuild
|
||||
if err := status.StreamGroup(context.IOStream, rb.Parallel, func(instance *wisski.WissKI, io stream.IOStream) error {
|
||||
return instance.Barrel().Build(io, true)
|
||||
}, wissKIs, status.SmartMessage(func(item *wisski.WissKI) string {
|
||||
return fmt.Sprintf("rebuild %q", item.Slug)
|
||||
})); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -14,7 +14,6 @@ import (
|
|||
"github.com/tkw1536/goprogram/exit"
|
||||
"github.com/tkw1536/goprogram/parser"
|
||||
"github.com/tkw1536/goprogram/status"
|
||||
"github.com/tkw1536/goprogram/stream"
|
||||
)
|
||||
|
||||
// SystemUpdate is the 'system_update' command
|
||||
|
|
@ -67,7 +66,7 @@ func (si systemupdate) Run(context wisski_distillery.Context) error {
|
|||
dis := context.Environment
|
||||
|
||||
// create all the other directories
|
||||
logging.LogMessage(context.IOStream, "Ensuring distillery installation directories exist")
|
||||
logging.LogMessage(context.Stderr, "Ensuring distillery installation directories exist")
|
||||
for _, d := range []string{
|
||||
dis.Config.DeployRoot,
|
||||
dis.Instances().Path(),
|
||||
|
|
@ -82,7 +81,7 @@ func (si systemupdate) Run(context wisski_distillery.Context) error {
|
|||
|
||||
if si.InstallDocker {
|
||||
// install system updates
|
||||
logging.LogMessage(context.IOStream, "Updating Operating System Packages")
|
||||
logging.LogMessage(context.Stderr, "Updating Operating System Packages")
|
||||
if err := si.mustExec(context, "", "apt-get", "update"); err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
@ -91,7 +90,7 @@ func (si systemupdate) Run(context wisski_distillery.Context) error {
|
|||
}
|
||||
|
||||
// install docker
|
||||
logging.LogMessage(context.IOStream, "Installing / Updating Docker")
|
||||
logging.LogMessage(context.Stderr, "Installing / Updating Docker")
|
||||
if err := si.mustExec(context, "", "apt-get", "install", "curl"); err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
@ -101,19 +100,19 @@ func (si systemupdate) Run(context wisski_distillery.Context) error {
|
|||
}
|
||||
}
|
||||
|
||||
logging.LogMessage(context.IOStream, "Checking that 'docker' is installed")
|
||||
logging.LogMessage(context.Stderr, "Checking that 'docker' is installed")
|
||||
if err := si.mustExec(context, "", "docker", "--version", dis.Config.DockerNetworkName); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
logging.LogMessage(context.IOStream, "Checking that 'docker compose' is available")
|
||||
logging.LogMessage(context.Stderr, "Checking that 'docker compose' is available")
|
||||
if err := si.mustExec(context, "", "docker", "compose", "version"); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// create the docker network
|
||||
// TODO: Use docker API for this
|
||||
logging.LogMessage(context.IOStream, "Updating Docker Configuration")
|
||||
logging.LogMessage(context.Stderr, "Updating Docker Configuration")
|
||||
si.mustExec(context, "", "docker", "network", "create", dis.Config.DockerNetworkName)
|
||||
|
||||
// install and update the various stacks!
|
||||
|
|
@ -125,21 +124,20 @@ func (si systemupdate) Run(context wisski_distillery.Context) error {
|
|||
var updateMutex sync.Mutex
|
||||
|
||||
if err := logging.LogOperation(func() error {
|
||||
return status.RunErrorGroup(context.Stdout, status.Group[component.Installable, error]{
|
||||
return status.RunErrorGroup(context.Stderr, status.Group[component.Installable, error]{
|
||||
PrefixString: func(item component.Installable, index int) string {
|
||||
return fmt.Sprintf("[update %q]: ", item.Name())
|
||||
},
|
||||
PrefixAlign: true,
|
||||
|
||||
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 := stack.Install(context.Context, io, item.Context(ctx)); err != nil {
|
||||
if err := stack.Install(context.Context, writer, item.Context(ctx)); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := stack.Update(context.Context, io, true); err != nil {
|
||||
if err := stack.Update(context.Context, writer, true); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
@ -154,10 +152,10 @@ func (si systemupdate) Run(context wisski_distillery.Context) error {
|
|||
updated[item.ID()] = struct{}{}
|
||||
}()
|
||||
|
||||
return ud.Update(context.Context, io)
|
||||
return ud.Update(context.Context, writer)
|
||||
},
|
||||
}, dis.Installable())
|
||||
}, context.IOStream, "Performing Stack Updates"); err != nil {
|
||||
}, context.Stderr, "Performing Stack Updates"); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
@ -170,18 +168,18 @@ func (si systemupdate) Run(context wisski_distillery.Context) error {
|
|||
context.Println("Already updated")
|
||||
return nil
|
||||
}
|
||||
return item.Update(context.Context, context.IOStream)
|
||||
}, context.IOStream, "Updating Component: %s", name); err != nil {
|
||||
return item.Update(context.Context, context.Stderr)
|
||||
}, context.Stderr, "Updating Component: %s", name); err != nil {
|
||||
return errBootstrapComponent.WithMessageF(name, err)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}, context.IOStream, "Performing Component Updates"); err != nil {
|
||||
}, context.Stderr, "Performing Component Updates"); err != nil {
|
||||
return err
|
||||
}
|
||||
// TODO: Register cronjob in /etc/cron.d!
|
||||
|
||||
logging.LogMessage(context.IOStream, "System has been updated")
|
||||
logging.LogMessage(context.Stderr, "System has been updated")
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package cmd
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
|
||||
wisski_distillery "github.com/FAU-CDI/wisski-distillery"
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/cli"
|
||||
|
|
@ -9,7 +10,6 @@ import (
|
|||
|
||||
"github.com/tkw1536/goprogram/exit"
|
||||
"github.com/tkw1536/goprogram/status"
|
||||
"github.com/tkw1536/goprogram/stream"
|
||||
)
|
||||
|
||||
// Cron is the 'cron' command
|
||||
|
|
@ -42,8 +42,8 @@ func (upc updateprefixconfig) Run(context wisski_distillery.Context) error {
|
|||
return errPrefixUpdateFailed.Wrap(err)
|
||||
}
|
||||
|
||||
return status.StreamGroup(context.IOStream, upc.Parallel, func(instance *wisski.WissKI, io stream.IOStream) error {
|
||||
io.Println("reading prefixes")
|
||||
return status.WriterGroup(context.Stderr, upc.Parallel, func(instance *wisski.WissKI, writer io.Writer) error {
|
||||
fmt.Fprintln(writer, "reading prefixes")
|
||||
err := instance.Prefixes().Update(context.Context)
|
||||
if err != nil {
|
||||
return errPrefixUpdateFailed.Wrap(err)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue