Do a large chunk of the move to go
This commit moves a huge chunk of the code to go. The TODO.md document indicates what is left to be done.
This commit is contained in:
parent
db2ad9b4bd
commit
7b38fdd801
93 changed files with 4689 additions and 645 deletions
121
cmd/provision.go
Normal file
121
cmd/provision.go
Normal file
|
|
@ -0,0 +1,121 @@
|
|||
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/fsx"
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/logging"
|
||||
"github.com/tkw1536/goprogram/exit"
|
||||
)
|
||||
|
||||
// Provision is the 'provision' command
|
||||
var Provision wisski_distillery.Command = provision{}
|
||||
|
||||
type provision struct {
|
||||
Positionals struct {
|
||||
Slug string `positional-arg-name:"slug" required:"1-1" description:"name of WissKI Instance to create"`
|
||||
} `positional-args:"true"`
|
||||
}
|
||||
|
||||
func (provision) Description() wisski_distillery.Description {
|
||||
return wisski_distillery.Description{
|
||||
Requirements: env.Requirements{
|
||||
NeedsConfig: true,
|
||||
},
|
||||
Command: "provision",
|
||||
Description: "Creates a new WissKI Instance",
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: AfterParse to check instance!
|
||||
|
||||
var errProvisionAlreadyExists = exit.Error{
|
||||
Message: "Instance %q already exists",
|
||||
ExitCode: exit.ExitGeneric,
|
||||
}
|
||||
|
||||
var errProvisionGeneric = exit.Error{
|
||||
Message: "Unable to provision instance %s: %s",
|
||||
ExitCode: exit.ExitGeneric,
|
||||
}
|
||||
|
||||
func (p provision) Run(context wisski_distillery.Context) error {
|
||||
dis := context.Environment
|
||||
slug := p.Positionals.Slug
|
||||
|
||||
// check that it doesn't already exist
|
||||
logging.LogMessage(context.IOStream, "Provisioning new WissKI instance %s", slug)
|
||||
if exists, err := dis.HasInstance(slug); err != nil || exists {
|
||||
return errProvisionAlreadyExists.WithMessageF(slug)
|
||||
}
|
||||
|
||||
// make it in-memory
|
||||
instance, err := dis.NewInstance(slug)
|
||||
if err != nil {
|
||||
return errProvisionGeneric.WithMessageF(slug, err)
|
||||
}
|
||||
|
||||
// check that the base directory does not exist
|
||||
logging.LogMessage(context.IOStream, "Checking that base directory %s does not exist", instance.FilesystemBase)
|
||||
if fsx.IsDirectory(instance.FilesystemBase) {
|
||||
return errProvisionAlreadyExists.WithMessageF(slug)
|
||||
}
|
||||
|
||||
// Store in bookkeeping
|
||||
if err := logging.LogOperation(func() error {
|
||||
if err := instance.Update(); err != nil {
|
||||
return errProvisionGeneric.WithMessageF(slug, err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}, context.IOStream, "Updating bookkeeping database"); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// create the sql
|
||||
if err := logging.LogOperation(func() error {
|
||||
if err := dis.SQLProvision(instance.SqlDatabase, instance.SqlUser, instance.SqlPassword); err != nil {
|
||||
return errProvisionGeneric.WithMessageF(slug, err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}, context.IOStream, "Provisioning SQL Database"); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// create the triplestore
|
||||
if err := logging.LogOperation(func() error {
|
||||
if err := dis.TriplestoreProvision(instance.GraphDBRepository, instance.Domain(), instance.GraphDBUser, instance.GraphDBPassword); err != nil {
|
||||
return errProvisionGeneric.WithMessageF(slug, err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}, context.IOStream, "Provisioning Triplestore"); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// run the provision script
|
||||
if err := logging.LogOperation(func() error {
|
||||
if err := instance.Provision(context.IOStream); err != nil {
|
||||
return errProvisionGeneric.WithMessageF(slug, err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}, context.IOStream, "Running setup scripts"); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// start the container!
|
||||
logging.LogMessage(context.IOStream, "Starting Container")
|
||||
if err := instance.Stack().Up(context.IOStream); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// and we're done!
|
||||
logging.LogMessage(context.IOStream, "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)
|
||||
|
||||
return nil
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue