Add support for provisioning and rebuilding via interface
This commit is contained in:
parent
f5c5999f44
commit
ddb4bb3546
76 changed files with 1306 additions and 625 deletions
|
|
@ -4,6 +4,7 @@ import (
|
|||
wisski_distillery "github.com/FAU-CDI/wisski-distillery"
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/cli"
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/dis/component/provision"
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/models"
|
||||
"github.com/FAU-CDI/wisski-distillery/pkg/logging"
|
||||
"github.com/tkw1536/goprogram/exit"
|
||||
)
|
||||
|
|
@ -12,8 +13,9 @@ import (
|
|||
var Provision wisski_distillery.Command = pv{}
|
||||
|
||||
type pv struct {
|
||||
PHPVersion string `short:"p" long:"php" description:"specific php version to use for instance. Should be one of '8.0', '8.1'."`
|
||||
Positionals struct {
|
||||
PHPVersion string `short:"p" long:"php" description:"specific php version to use for instance. Should be one of '8.0', '8.1'."`
|
||||
OPCacheDevelopment bool `short:"o" long:"opcache-devel" description:"Include opcache development configuration"`
|
||||
Positionals struct {
|
||||
Slug string `positional-arg-name:"slug" required:"1-1" description:"slug of instance to create"`
|
||||
} `positional-args:"true"`
|
||||
}
|
||||
|
|
@ -36,9 +38,12 @@ var errProvisionGeneric = exit.Error{
|
|||
// TODO: AfterParse to check instance!
|
||||
|
||||
func (p pv) Run(context wisski_distillery.Context) error {
|
||||
instance, err := context.Environment.Provision().Provision(context.Stderr, context.Context, provision.ProvisionFlags{
|
||||
Slug: p.Positionals.Slug,
|
||||
PHPVersion: p.PHPVersion,
|
||||
instance, err := context.Environment.Provision().Provision(context.Stderr, context.Context, provision.Flags{
|
||||
Slug: p.Positionals.Slug,
|
||||
System: models.System{
|
||||
PHP: p.PHPVersion,
|
||||
OpCacheDevelopment: p.OPCacheDevelopment,
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
return errProvisionGeneric.WithMessageF(p.Positionals.Slug).Wrap(err)
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import (
|
|||
|
||||
wisski_distillery "github.com/FAU-CDI/wisski-distillery"
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/cli"
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/models"
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/wisski"
|
||||
"github.com/tkw1536/goprogram/exit"
|
||||
"github.com/tkw1536/pkglib/status"
|
||||
|
|
@ -15,9 +16,11 @@ import (
|
|||
var Rebuild wisski_distillery.Command = rebuild{}
|
||||
|
||||
type rebuild struct {
|
||||
Parallel int `short:"p" long:"parallel" description:"run on (at most) this many instances in parallel. 0 for no limit." default:"1"`
|
||||
PHPVersion string `short:"u" long:"php" description:"update to specific php version to use for instance. Should be one of '8.0', '8.1'."`
|
||||
Positionals struct {
|
||||
Parallel int `short:"a" long:"parallel" description:"run on (at most) this many instances in parallel. 0 for no limit." default:"1"`
|
||||
|
||||
PHPVersion string `short:"p" long:"php" description:"update to specific php version to use for instance. Should be one of '8.0', '8.1'."`
|
||||
OPCacheDevelopment bool `short:"o" long:"opcache-devel" description:"Include opcache development configuration"`
|
||||
Positionals struct {
|
||||
Slug []string `positional-arg-name:"SLUG" required:"0" description:"slug of instance or instances to run rebuild"`
|
||||
} `positional-args:"true"`
|
||||
}
|
||||
|
|
@ -50,13 +53,10 @@ func (rb rebuild) Run(context wisski_distillery.Context) (err error) {
|
|||
|
||||
// and do the actual rebuild
|
||||
return status.WriterGroup(context.Stderr, rb.Parallel, func(instance *wisski.WissKI, writer io.Writer) error {
|
||||
if rb.PHPVersion != "" {
|
||||
if err := instance.Provisioner().ApplyFlags(context.Context, writer, rb.PHPVersion); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return instance.Barrel().Build(context.Context, writer, true)
|
||||
return instance.SystemManager().Apply(context.Context, writer, models.System{
|
||||
PHP: rb.PHPVersion,
|
||||
OpCacheDevelopment: rb.OPCacheDevelopment,
|
||||
}, true)
|
||||
}, wissKIs, status.SmartMessage(func(item *wisski.WissKI) string {
|
||||
return fmt.Sprintf("rebuild %q", item.Slug)
|
||||
}))
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import (
|
|||
wisski_distillery "github.com/FAU-CDI/wisski-distillery"
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/cli"
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/dis/component"
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/models"
|
||||
"github.com/FAU-CDI/wisski-distillery/pkg/logging"
|
||||
"github.com/tkw1536/goprogram/exit"
|
||||
"github.com/tkw1536/pkglib/fsx"
|
||||
|
|
@ -53,7 +54,7 @@ func (r reserve) Run(context wisski_distillery.Context) (err error) {
|
|||
}
|
||||
|
||||
// make it in-memory
|
||||
instance, err := dis.Instances().Create(slug, "")
|
||||
instance, err := dis.Instances().Create(slug, models.System{})
|
||||
if err != nil {
|
||||
return errProvisionGeneric.WithMessageF(slug, err)
|
||||
}
|
||||
|
|
|
|||
15
cmd/shell.go
15
cmd/shell.go
|
|
@ -5,6 +5,7 @@ import (
|
|||
|
||||
wisski_distillery "github.com/FAU-CDI/wisski-distillery"
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/cli"
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/wisski/ingredient/barrel"
|
||||
"github.com/tkw1536/goprogram/exit"
|
||||
"github.com/tkw1536/goprogram/parser"
|
||||
)
|
||||
|
|
@ -43,12 +44,16 @@ func (sh shell) Run(context wisski_distillery.Context) error {
|
|||
return errShellWissKI.Wrap(err)
|
||||
}
|
||||
|
||||
code := instance.Barrel().Shell(context.Context, context.IOStream, sh.Positionals.Args...)()
|
||||
if code != 0 {
|
||||
return exit.Error{
|
||||
ExitCode: exit.ExitCode(uint8(code)),
|
||||
Message: fmt.Sprintf("Exit code %d", code),
|
||||
{
|
||||
err := instance.Barrel().Shell(context.Context, context.IOStream, sh.Positionals.Args...)
|
||||
if err != nil {
|
||||
code := err.(barrel.ExitError).Code()
|
||||
return exit.Error{
|
||||
ExitCode: code,
|
||||
Message: fmt.Sprintf("Exit code %d", code),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue