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
|
|
@ -2,6 +2,7 @@ package barrel
|
|||
|
||||
import (
|
||||
"context"
|
||||
"io"
|
||||
"time"
|
||||
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/dis/component"
|
||||
|
|
@ -10,13 +11,12 @@ import (
|
|||
"github.com/FAU-CDI/wisski-distillery/internal/wisski/ingredient"
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/wisski/ingredient/locker"
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/wisski/ingredient/mstore"
|
||||
"github.com/tkw1536/goprogram/stream"
|
||||
)
|
||||
|
||||
// Build builds or rebuilds the barel connected to this instance.
|
||||
//
|
||||
// It also logs the current time into the metadata belonging to this instance.
|
||||
func (barrel *Barrel) Build(ctx context.Context, stream stream.IOStream, start bool) error {
|
||||
func (barrel *Barrel) Build(ctx context.Context, progress io.Writer, start bool) error {
|
||||
if !barrel.Locker.TryLock(ctx) {
|
||||
err := locker.Locked
|
||||
return err
|
||||
|
|
@ -28,14 +28,14 @@ func (barrel *Barrel) Build(ctx context.Context, stream stream.IOStream, start b
|
|||
var context component.InstallationContext
|
||||
|
||||
{
|
||||
err := stack.Install(ctx, stream, context)
|
||||
err := stack.Install(ctx, progress, context)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
err := stack.Update(ctx, stream, start)
|
||||
err := stack.Update(ctx, progress, start)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,8 +2,11 @@ package drush
|
|||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"io"
|
||||
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/phpx"
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/status"
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/wisski/ingredient"
|
||||
|
|
@ -16,15 +19,15 @@ var errCronFailed = exit.Error{
|
|||
ExitCode: exit.ExitGeneric,
|
||||
}
|
||||
|
||||
func (drush *Drush) Cron(ctx context.Context, io stream.IOStream) error {
|
||||
code, err := drush.Barrel.Shell(ctx, io, "/runtime/cron.sh")
|
||||
func (drush *Drush) Cron(ctx context.Context, progress io.Writer) error {
|
||||
code, err := drush.Barrel.Shell(ctx, stream.NonInteractive(progress), "/runtime/cron.sh")
|
||||
if err != nil {
|
||||
io.EPrintln(err)
|
||||
fmt.Fprintln(progress, err)
|
||||
}
|
||||
if code != 0 {
|
||||
// keep going, because we want to run as many crons as possible
|
||||
err = errCronFailed.WithMessageF(drush.Slug, code)
|
||||
io.EPrintln(err)
|
||||
fmt.Fprintln(progress, err)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package drush
|
|||
|
||||
import (
|
||||
"context"
|
||||
"io"
|
||||
"time"
|
||||
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/dis/component/meta"
|
||||
|
|
@ -19,8 +20,8 @@ var errBlindUpdateFailed = exit.Error{
|
|||
}
|
||||
|
||||
// Update performs a blind drush update
|
||||
func (drush *Drush) Update(ctx context.Context, io stream.IOStream) error {
|
||||
code, err := drush.Barrel.Shell(ctx, io, "/runtime/blind_update.sh")
|
||||
func (drush *Drush) Update(ctx context.Context, progress io.Writer) error {
|
||||
code, err := drush.Barrel.Shell(ctx, stream.NonInteractive(progress), "/runtime/blind_update.sh")
|
||||
if err != nil {
|
||||
return errBlindUpdateFailed.WithMessageF(drush.Slug, environment.ExecCommandError)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ package provisioner
|
|||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"io"
|
||||
"strings"
|
||||
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/wisski/ingredient"
|
||||
|
|
@ -20,10 +21,10 @@ type Provisioner struct {
|
|||
}
|
||||
|
||||
// Provision provisions an instance, assuming that the required databases already exist.
|
||||
func (provision *Provisioner) Provision(ctx context.Context, io stream.IOStream) error {
|
||||
func (provision *Provisioner) Provision(ctx context.Context, progress io.Writer) error {
|
||||
|
||||
// build the container
|
||||
if err := provision.Barrel.Build(ctx, io, false); err != nil {
|
||||
if err := provision.Barrel.Build(ctx, progress, false); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
@ -54,7 +55,7 @@ func (provision *Provisioner) Provision(ctx context.Context, io stream.IOStream)
|
|||
// TODO: Move the provision script into the control plane!
|
||||
provisionScript := "sudo PATH=$PATH -u www-data /bin/bash /provision_container.sh " + strings.Join(provisionParams, " ")
|
||||
|
||||
code, err := provision.Barrel.Stack().Run(ctx, io, true, "barrel", "/bin/bash", "-c", provisionScript)
|
||||
code, err := provision.Barrel.Stack().Run(ctx, stream.NonInteractive(progress), true, "barrel", "/bin/bash", "-c", provisionScript)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,15 +2,15 @@ package barrel
|
|||
|
||||
import (
|
||||
"context"
|
||||
"io"
|
||||
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/status"
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/wisski/ingredient"
|
||||
"github.com/tkw1536/goprogram/stream"
|
||||
)
|
||||
|
||||
// Running checks if this WissKI is currently running.
|
||||
func (barrel *Barrel) Running(ctx context.Context) (bool, error) {
|
||||
ps, err := barrel.Stack().Ps(ctx, stream.FromNil())
|
||||
func (barrel *Barrel) Running(ctx context.Context, progress io.Writer) (bool, error) {
|
||||
ps, err := barrel.Stack().Ps(ctx, progress)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
|
@ -28,6 +28,6 @@ var (
|
|||
)
|
||||
|
||||
func (rf *RunningFetcher) Fetch(flags ingredient.FetcherFlags, info *status.WissKI) (err error) {
|
||||
info.Running, err = rf.Barrel.Running(flags.Context)
|
||||
info.Running, err = rf.Barrel.Running(flags.Context, io.Discard)
|
||||
return
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue