Add 'dis' component

This commit adds a new 'dis' component to the distillery that serves a
list of all known instances for the moment.
This commit is contained in:
Tom Wiesing 2022-09-09 17:10:24 +02:00
parent 35bb95c5ca
commit 4b357476a3
No known key found for this signature in database
43 changed files with 434 additions and 167 deletions

View file

@ -5,6 +5,7 @@ import (
"os"
wisski_distillery "github.com/FAU-CDI/wisski-distillery"
"github.com/FAU-CDI/wisski-distillery/core"
"github.com/FAU-CDI/wisski-distillery/env"
"github.com/FAU-CDI/wisski-distillery/internal/logging"
"github.com/FAU-CDI/wisski-distillery/internal/targz"
@ -24,7 +25,7 @@ type backup struct {
func (backup) Description() wisski_distillery.Description {
return wisski_distillery.Description{
Requirements: env.Requirements{
Requirements: core.Requirements{
NeedsDistillery: true,
},
Command: "backup",

View file

@ -2,7 +2,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/core"
"github.com/FAU-CDI/wisski-distillery/internal/execx"
"github.com/tkw1536/goprogram/exit"
)
@ -19,7 +19,7 @@ type blindUpdate struct {
func (blindUpdate) Description() wisski_distillery.Description {
return wisski_distillery.Description{
Requirements: env.Requirements{
Requirements: core.Requirements{
NeedsDistillery: true,
},
Command: "blind_update",

View file

@ -6,8 +6,8 @@ import (
"path/filepath"
wisski_distillery "github.com/FAU-CDI/wisski-distillery"
"github.com/FAU-CDI/wisski-distillery/core"
"github.com/FAU-CDI/wisski-distillery/distillery"
"github.com/FAU-CDI/wisski-distillery/env"
cfg "github.com/FAU-CDI/wisski-distillery/internal/config"
"github.com/FAU-CDI/wisski-distillery/internal/fsx"
"github.com/FAU-CDI/wisski-distillery/internal/hostname"
@ -26,7 +26,7 @@ type bootstrap struct {
func (bootstrap) Description() wisski_distillery.Description {
return wisski_distillery.Description{
Requirements: env.Requirements{
Requirements: core.Requirements{
NeedsDistillery: false,
},
Command: "bootstrap",
@ -74,7 +74,7 @@ func (bs bootstrap) Run(context wisski_distillery.Context) error {
// check that we didn't get a different base directory
{
got, err := env.ReadBaseDirectory()
got, err := core.ReadBaseDirectory()
if err == nil && got != "" && got != root {
return errBootstrapDifferent.WithMessageF(got)
}
@ -85,15 +85,15 @@ func (bs bootstrap) Run(context wisski_distillery.Context) error {
if err := os.MkdirAll(root, fs.ModeDir); err != nil {
return errBootstrapFailedToCreateDirectory.WithMessageF(root)
}
if err := env.WriteBaseDirectory(root); err != nil {
if err := core.WriteBaseDirectory(root); err != nil {
return errBootstrapFailedToSaveDirectory.WithMessageF(root)
}
context.Println(root)
}
// TODO: Read these from the command line?
wdcliPath := filepath.Join(root, env.Executable)
envPath := filepath.Join(root, env.ConfigFile)
// TODO: Should we read an existing configuration file?
wdcliPath := filepath.Join(root, core.Executable)
envPath := filepath.Join(root, core.ConfigFile)
domain := bs.Hostname
if domain == "" {
domain = hostname.FQDN()

View file

@ -2,7 +2,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/core"
)
// Config is the configuration command
@ -13,7 +13,7 @@ type config struct {
func (s config) Description() wisski_distillery.Description {
return wisski_distillery.Description{
Requirements: env.Requirements{
Requirements: core.Requirements{
NeedsDistillery: true,
},
Command: "config",

View file

@ -2,7 +2,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/core"
"github.com/FAU-CDI/wisski-distillery/internal/logging"
"github.com/tkw1536/goprogram/exit"
)
@ -18,7 +18,7 @@ type cron struct {
func (cron) Description() wisski_distillery.Description {
return wisski_distillery.Description{
Requirements: env.Requirements{
Requirements: core.Requirements{
NeedsDistillery: true,
},
Command: "cron",

43
cmd/dis_server.go Normal file
View file

@ -0,0 +1,43 @@
package cmd
import (
"net/http"
wisski_distillery "github.com/FAU-CDI/wisski-distillery"
"github.com/FAU-CDI/wisski-distillery/core"
"github.com/tkw1536/goprogram/exit"
)
// DisServer is the 'dis_server' command
var DisServer wisski_distillery.Command = disServer{}
type disServer struct {
Prefix string `short:"p" long:"prefix" description:"prefix to listen under"`
Bind string `short:"b" long:"bind" description:"address to listen on" default:"127.0.0.1:8888"`
}
func (disServer) Description() wisski_distillery.Description {
return wisski_distillery.Description{
Requirements: core.Requirements{
NeedsDistillery: true,
},
Command: "dis_server",
Description: "Starts a server with information about this distillery",
}
}
var errServerListen = exit.Error{
ExitCode: exit.ExitGeneric,
Message: "Unable to listen",
}
func (s disServer) Run(context wisski_distillery.Context) error {
server := context.Environment.Server()
context.Printf("Listening on %s\n", s.Bind)
err := http.ListenAndServe(s.Bind, http.StripPrefix(s.Prefix, server))
if err == nil {
return nil
}
return errServerListen.Wrap(err)
}

View file

@ -2,7 +2,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/core"
)
// Info is then 'info' command
@ -16,7 +16,7 @@ type info struct {
func (info) Description() wisski_distillery.Description {
return wisski_distillery.Description{
Requirements: env.Requirements{
Requirements: core.Requirements{
NeedsDistillery: true,
},
Command: "info",

View file

@ -2,7 +2,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/core"
"github.com/FAU-CDI/wisski-distillery/internal/legal"
)
@ -15,7 +15,7 @@ type license struct{}
func (license) Description() wisski_distillery.Description {
return wisski_distillery.Description{
Requirements: env.Requirements{
Requirements: core.Requirements{
NeedsDistillery: false,
},
Command: "license",

View file

@ -2,7 +2,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/core"
)
// Ls is the 'ls' command
@ -16,7 +16,7 @@ type ls struct {
func (ls) Description() wisski_distillery.Description {
return wisski_distillery.Description{
Requirements: env.Requirements{
Requirements: core.Requirements{
NeedsDistillery: true,
},
Command: "ls",

View file

@ -4,7 +4,7 @@ import (
"fmt"
wisski_distillery "github.com/FAU-CDI/wisski-distillery"
"github.com/FAU-CDI/wisski-distillery/env"
"github.com/FAU-CDI/wisski-distillery/core"
"github.com/FAU-CDI/wisski-distillery/internal/sqle"
"github.com/tkw1536/goprogram/exit"
"github.com/tkw1536/goprogram/parser"
@ -17,7 +17,7 @@ type makeMysqlAccount struct{}
func (makeMysqlAccount) Description() wisski_distillery.Description {
return wisski_distillery.Description{
Requirements: env.Requirements{
Requirements: core.Requirements{
NeedsDistillery: true,
},
ParserConfig: parser.Config{

View file

@ -4,7 +4,7 @@ import (
"os"
wisski_distillery "github.com/FAU-CDI/wisski-distillery"
"github.com/FAU-CDI/wisski-distillery/env"
"github.com/FAU-CDI/wisski-distillery/core"
"github.com/FAU-CDI/wisski-distillery/internal/logging"
)
@ -20,7 +20,7 @@ type monday struct {
func (monday) Description() wisski_distillery.Description {
return wisski_distillery.Description{
Requirements: env.Requirements{
Requirements: core.Requirements{
NeedsDistillery: true,
},
Command: "monday",

View file

@ -4,7 +4,7 @@ import (
"fmt"
wisski_distillery "github.com/FAU-CDI/wisski-distillery"
"github.com/FAU-CDI/wisski-distillery/env"
"github.com/FAU-CDI/wisski-distillery/core"
"github.com/tkw1536/goprogram/exit"
"github.com/tkw1536/goprogram/parser"
)
@ -20,7 +20,7 @@ type mysql struct {
func (mysql) Description() wisski_distillery.Description {
return wisski_distillery.Description{
Requirements: env.Requirements{
Requirements: core.Requirements{
NeedsDistillery: true,
},
ParserConfig: parser.Config{

View file

@ -2,7 +2,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/core"
"github.com/FAU-CDI/wisski-distillery/internal/fsx"
"github.com/FAU-CDI/wisski-distillery/internal/logging"
"github.com/tkw1536/goprogram/exit"
@ -19,7 +19,7 @@ type provision struct {
func (provision) Description() wisski_distillery.Description {
return wisski_distillery.Description{
Requirements: env.Requirements{
Requirements: core.Requirements{
NeedsDistillery: true,
},
Command: "provision",

View file

@ -4,6 +4,7 @@ import (
"os"
wisski_distillery "github.com/FAU-CDI/wisski-distillery"
"github.com/FAU-CDI/wisski-distillery/core"
"github.com/FAU-CDI/wisski-distillery/env"
"github.com/FAU-CDI/wisski-distillery/internal/logging"
"github.com/tkw1536/goprogram/exit"
@ -21,7 +22,7 @@ type purge struct {
func (purge) Description() wisski_distillery.Description {
return wisski_distillery.Description{
Requirements: env.Requirements{
Requirements: core.Requirements{
NeedsDistillery: true,
},
Command: "purge",

View file

@ -2,7 +2,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/core"
"github.com/FAU-CDI/wisski-distillery/internal/logging"
"github.com/FAU-CDI/wisski-distillery/internal/stack"
"github.com/tkw1536/goprogram/exit"
@ -19,7 +19,7 @@ type rebuild struct {
func (rebuild) Description() wisski_distillery.Description {
return wisski_distillery.Description{
Requirements: env.Requirements{
Requirements: core.Requirements{
NeedsDistillery: true,
},
Command: "rebuild",

View file

@ -2,7 +2,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/core"
"github.com/FAU-CDI/wisski-distillery/internal/fsx"
"github.com/FAU-CDI/wisski-distillery/internal/logging"
"github.com/FAU-CDI/wisski-distillery/internal/stack"
@ -20,7 +20,7 @@ type reserve struct {
func (reserve) Description() wisski_distillery.Description {
return wisski_distillery.Description{
Requirements: env.Requirements{
Requirements: core.Requirements{
NeedsDistillery: true,
},
Command: "reserve",

View file

@ -4,7 +4,7 @@ import (
"fmt"
wisski_distillery "github.com/FAU-CDI/wisski-distillery"
"github.com/FAU-CDI/wisski-distillery/env"
"github.com/FAU-CDI/wisski-distillery/core"
"github.com/tkw1536/goprogram/exit"
"github.com/tkw1536/goprogram/parser"
)
@ -21,7 +21,7 @@ type shell struct {
func (shell) Description() wisski_distillery.Description {
return wisski_distillery.Description{
Requirements: env.Requirements{
Requirements: core.Requirements{
NeedsDistillery: true,
},
ParserConfig: parser.Config{

View file

@ -5,6 +5,7 @@ import (
"os"
wisski_distillery "github.com/FAU-CDI/wisski-distillery"
"github.com/FAU-CDI/wisski-distillery/core"
"github.com/FAU-CDI/wisski-distillery/env"
"github.com/FAU-CDI/wisski-distillery/internal/logging"
"github.com/FAU-CDI/wisski-distillery/internal/targz"
@ -26,7 +27,7 @@ type snapshot struct {
func (snapshot) Description() wisski_distillery.Description {
return wisski_distillery.Description{
Requirements: env.Requirements{
Requirements: core.Requirements{
NeedsDistillery: true,
},
Command: "snapshot",

View file

@ -5,8 +5,8 @@ import (
"path/filepath"
wisski_distillery "github.com/FAU-CDI/wisski-distillery"
"github.com/FAU-CDI/wisski-distillery/core"
"github.com/FAU-CDI/wisski-distillery/distillery"
"github.com/FAU-CDI/wisski-distillery/env"
"github.com/FAU-CDI/wisski-distillery/internal/execx"
"github.com/FAU-CDI/wisski-distillery/internal/logging"
"github.com/FAU-CDI/wisski-distillery/internal/stack"
@ -26,7 +26,7 @@ type systemupdate struct {
func (systemupdate) Description() wisski_distillery.Description {
return wisski_distillery.Description{
Requirements: env.Requirements{
Requirements: core.Requirements{
NeedsDistillery: true,
},
ParserConfig: parser.Config{
@ -124,6 +124,7 @@ func (si systemupdate) Run(context wisski_distillery.Context) error {
if err := logging.LogOperation(func() error {
for _, component := range dis.Components() {
stack := component.Stack()
ctx := component.Context(ctx)
if err := logging.LogOperation(func() error {
return stack.Install(context.IOStream, ctx)
}, context.IOStream, "Installing docker stack %q", component.Name()); err != nil {

View file

@ -5,7 +5,7 @@ import (
"os"
wisski_distillery "github.com/FAU-CDI/wisski-distillery"
"github.com/FAU-CDI/wisski-distillery/env"
"github.com/FAU-CDI/wisski-distillery/core"
"github.com/FAU-CDI/wisski-distillery/internal/logging"
"github.com/tkw1536/goprogram/exit"
)
@ -17,7 +17,7 @@ type updateprefixconfig struct{}
func (updateprefixconfig) Description() wisski_distillery.Description {
return wisski_distillery.Description{
Requirements: env.Requirements{
Requirements: core.Requirements{
NeedsDistillery: true,
},
Command: "update_prefix_config",

View file

@ -8,7 +8,7 @@ import (
wisski_distillery "github.com/FAU-CDI/wisski-distillery"
"github.com/FAU-CDI/wisski-distillery/cmd"
"github.com/FAU-CDI/wisski-distillery/env"
"github.com/FAU-CDI/wisski-distillery/core"
"github.com/tkw1536/goprogram/exit"
"github.com/tkw1536/goprogram/stream"
)
@ -48,6 +48,9 @@ func init() {
wdcli.Register(cmd.Backup)
wdcli.Register(cmd.Cron)
wdcli.Register(cmd.Monday)
// servers
wdcli.Register(cmd.DisServer)
}
// an error when no arguments are provided.
@ -83,7 +86,7 @@ func main() {
// creat a new set of parameters
// and then use them to execute the main command
err := func() error {
params, err := env.ParamsFromEnv()
params, err := core.ParamsFromEnv()
if err != nil {
return streams.Die(err)
}