Move to yaml-based configuration

This commit updates the configuration to be yaml-based and updates the
configuration to read in a yaml file.
This commit is contained in:
Tom Wiesing 2023-02-12 18:13:52 +01:00
parent 568c005d15
commit 945329a080
No known key found for this signature in database
70 changed files with 1150 additions and 350 deletions

View file

@ -21,6 +21,5 @@ func (c cfg) Description() wisski_distillery.Description {
}
func (cfg) Run(context wisski_distillery.Context) error {
context.Printf("%#v", context.Environment.Config)
return nil
return context.Environment.Config.Marshal(context.Stdout)
}

64
cmd/config_migrate.go Normal file
View file

@ -0,0 +1,64 @@
package cmd
import (
"bytes"
wisski_distillery "github.com/FAU-CDI/wisski-distillery"
"github.com/FAU-CDI/wisski-distillery/internal/cli"
"github.com/FAU-CDI/wisski-distillery/internal/config"
"github.com/FAU-CDI/wisski-distillery/internal/config/legacy"
"github.com/FAU-CDI/wisski-distillery/pkg/environment"
)
// ConfigMigrate is the config-migrate command
var ConfigMigrate wisski_distillery.Command = cfgMigrate{}
type cfgMigrate struct {
Positionals struct {
Input string `positional-arg-name:"input" required:"1-1" description:"old config to migrate"`
} `positional-args:"true"`
}
func (cfgMigrate) Description() wisski_distillery.Description {
return wisski_distillery.Description{
Requirements: cli.Requirements{
NeedsDistillery: false,
},
Command: "config_migrate",
Description: "migrate legacy configuration",
}
}
func (c cfgMigrate) Run(context wisski_distillery.Context) error {
// migration environment is the native environment!
env := new(environment.Native)
// open the legacy file
file, err := env.Open(c.Positionals.Input)
if err != nil {
return err
}
defer file.Close()
// migrate from a legacy configuration
// then marshal, and re-read
var cfg config.Config
{
var mconfig config.Config
var output bytes.Buffer
if err := legacy.Migrate(&mconfig, env, file); err != nil {
return err
}
if err := mconfig.Marshal(&output); err != nil {
return err
}
if err := cfg.Unmarshal(env, &output); err != nil {
return err
}
}
// do a final marshal
return cfg.Marshal(context.Stdout)
}

View file

@ -68,7 +68,7 @@ func (si systemupdate) Run(context wisski_distillery.Context) error {
// create all the other directories
logging.LogMessage(context.Stderr, context.Context, "Ensuring distillery installation directories exist")
for _, d := range []string{
dis.Config.DeployRoot,
dis.Config.Paths.Root,
dis.Instances().Path(),
dis.Exporter().StagingPath(),
dis.Exporter().ArchivePath(),
@ -102,7 +102,7 @@ func (si systemupdate) Run(context wisski_distillery.Context) error {
}
logging.LogMessage(context.Stderr, context.Context, "Checking that 'docker' is installed")
if err := si.mustExec(context, "", "docker", "--version", dis.Config.DockerNetworkName); err != nil {
if err := si.mustExec(context, "", "docker", "--version"); err != nil {
return err
}
@ -114,7 +114,7 @@ func (si systemupdate) Run(context wisski_distillery.Context) error {
// create the docker network
// TODO: Use docker API for this
logging.LogMessage(context.Stderr, context.Context, "Updating Docker Configuration")
si.mustExec(context, "", "docker", "network", "create", dis.Config.DockerNetworkName)
si.mustExec(context, "", "docker", "network", "create", dis.Config.Docker.Network)
// install and update the various stacks!
ctx := component.InstallationContext{
@ -193,7 +193,7 @@ var errMustExecFailed = exit.Error{
func (si systemupdate) mustExec(context wisski_distillery.Context, workdir string, exe string, argv ...string) error {
dis := context.Environment
if workdir == "" {
workdir = dis.Config.DeployRoot
workdir = dis.Config.Paths.Root
}
code := dis.Still.Environment.Exec(context.Context, context.IOStream, workdir, exe, argv...)()
if code != 0 {

View file

@ -18,6 +18,7 @@ var wdcli = wisski_distillery.NewProgram()
func init() {
// self commands
wdcli.Register(cmd.Config)
wdcli.Register(cmd.ConfigMigrate)
wdcli.Register(cmd.License)
// setup commands