internal/stack: Cleanup API
This commit cleans up the internal stack API to prepare it for an eventual move to using a native docker client.
This commit is contained in:
parent
7b38fdd801
commit
5d906169f4
15 changed files with 96 additions and 65 deletions
|
|
@ -3,6 +3,7 @@ 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/execx"
|
||||
"github.com/tkw1536/goprogram/exit"
|
||||
)
|
||||
|
||||
|
|
@ -44,7 +45,10 @@ func (bu blindUpdate) Run(context wisski_distillery.Context) error {
|
|||
}
|
||||
context.EPrintf("Updating instance %s\n", instance.Slug)
|
||||
|
||||
code := instance.Shell(context.IOStream, "/utils/blind_update.sh")
|
||||
code, err := instance.Shell(context.IOStream, "/utils/blind_update.sh")
|
||||
if err != nil {
|
||||
return errBlindUpdateFailed.WithMessageF(instance.Slug, execx.ExecCommandError)
|
||||
}
|
||||
if code != 0 {
|
||||
return errBlindUpdateFailed.WithMessageF(instance.Slug, code)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -40,7 +40,10 @@ func (cr cron) Run(context wisski_distillery.Context) error {
|
|||
// iterate over the instances and store the last value of error
|
||||
for _, instance := range instances {
|
||||
logging.LogOperation(func() error {
|
||||
code := instance.Shell(context.IOStream, "/utils/cron.sh")
|
||||
code, err := instance.Shell(context.IOStream, "/utils/cron.sh")
|
||||
if err != nil {
|
||||
context.EPrintln(err)
|
||||
}
|
||||
if code != 0 {
|
||||
// keep going, because we want to run as many crons as possible
|
||||
err = errBlindUpdateFailed.WithMessageF(instance.Slug, code)
|
||||
|
|
|
|||
|
|
@ -55,7 +55,10 @@ func (mma makeMysqlAccount) Run(context wisski_distillery.Context) error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
code := context.Environment.SQLShell(context.IOStream, "-e", query)
|
||||
code, err := context.Environment.SQLShell(context.IOStream, "-e", query)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if code != 0 {
|
||||
return exit.Error{
|
||||
|
|
|
|||
|
|
@ -32,7 +32,10 @@ func (mysql) Description() wisski_distillery.Description {
|
|||
}
|
||||
|
||||
func (ms mysql) Run(context wisski_distillery.Context) error {
|
||||
code := context.Environment.SQLShell(context.IOStream, ms.Positionals.Args...)
|
||||
code, err := context.Environment.SQLShell(context.IOStream, ms.Positionals.Args...)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if code != 0 {
|
||||
return exit.Error{
|
||||
ExitCode: exit.ExitCode(uint8(code)),
|
||||
|
|
|
|||
10
cmd/shell.go
10
cmd/shell.go
|
|
@ -32,13 +32,21 @@ func (shell) Description() wisski_distillery.Description {
|
|||
}
|
||||
}
|
||||
|
||||
var errShell = exit.Error{
|
||||
Message: "Unable to start shell: %s",
|
||||
ExitCode: exit.ExitGeneric,
|
||||
}
|
||||
|
||||
func (sh shell) Run(context wisski_distillery.Context) error {
|
||||
instance, err := context.Environment.Instance(sh.Positionals.Slug)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
code := instance.Shell(context.IOStream, sh.Positionals.Args...)
|
||||
code, err := instance.Shell(context.IOStream, sh.Positionals.Args...)
|
||||
if err != nil {
|
||||
return errShell.WithMessageF(err)
|
||||
}
|
||||
if code != 0 {
|
||||
return exit.Error{
|
||||
ExitCode: exit.ExitCode(uint8(code)),
|
||||
|
|
|
|||
|
|
@ -114,13 +114,13 @@ func (si systemupdate) Run(context wisski_distillery.Context) error {
|
|||
for _, stack := range dis.Stacks() {
|
||||
if err := logging.LogOperation(func() error {
|
||||
return stack.Install(context.IOStream, ctx)
|
||||
}, context.IOStream, "Installing docker stack %q", stack.Name); err != nil {
|
||||
}, context.IOStream, "Installing docker stack %q", stack.Dir); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := logging.LogOperation(func() error {
|
||||
return stack.Update(context.IOStream, true)
|
||||
}, context.IOStream, "Updating docker stack %q", stack.Name); err != nil {
|
||||
}, context.IOStream, "Updating docker stack %q", stack.Dir); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue