diff --git a/cmd/rebuild.go b/cmd/rebuild.go index f1ed46b..ca1442d 100644 --- a/cmd/rebuild.go +++ b/cmd/rebuild.go @@ -2,9 +2,9 @@ package cmd import ( wisski_distillery "github.com/FAU-CDI/wisski-distillery" + "github.com/FAU-CDI/wisski-distillery/component" "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" ) @@ -44,7 +44,7 @@ func (rb rebuild) Run(context wisski_distillery.Context) error { logging.LogOperation(func() error { s := instance.Stack() if err := logging.LogOperation(func() error { - return s.Install(context.IOStream, stack.InstallationContext{}) + return s.Install(context.IOStream, component.InstallationContext{}) }, context.IOStream, "Installing docker stack"); err != nil { globalErr = err return err diff --git a/cmd/reserve.go b/cmd/reserve.go index f729ba0..52eef37 100644 --- a/cmd/reserve.go +++ b/cmd/reserve.go @@ -2,10 +2,10 @@ package cmd import ( wisski_distillery "github.com/FAU-CDI/wisski-distillery" + "github.com/FAU-CDI/wisski-distillery/component" "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" "github.com/tkw1536/goprogram/exit" ) @@ -66,7 +66,7 @@ func (r reserve) Run(context wisski_distillery.Context) error { s := instance.ReserveStack() { if err := logging.LogOperation(func() error { - return s.Install(context.IOStream, stack.InstallationContext{}) + return s.Install(context.IOStream, component.InstallationContext{}) }, context.IOStream, "Installing docker stack"); err != nil { return err } diff --git a/cmd/system_update.go b/cmd/system_update.go index 4067a96..149ddbd 100644 --- a/cmd/system_update.go +++ b/cmd/system_update.go @@ -5,11 +5,11 @@ import ( "path/filepath" wisski_distillery "github.com/FAU-CDI/wisski-distillery" + "github.com/FAU-CDI/wisski-distillery/component" "github.com/FAU-CDI/wisski-distillery/core" "github.com/FAU-CDI/wisski-distillery/embed" "github.com/FAU-CDI/wisski-distillery/internal/execx" "github.com/FAU-CDI/wisski-distillery/internal/logging" - "github.com/FAU-CDI/wisski-distillery/internal/stack" "github.com/FAU-CDI/wisski-distillery/internal/unpack" "github.com/tkw1536/goprogram/exit" "github.com/tkw1536/goprogram/parser" @@ -118,7 +118,7 @@ func (si systemupdate) Run(context wisski_distillery.Context) error { si.mustExec(context, "", "docker", "network", "create", "distillery") // install and update the various stacks! - ctx := stack.InstallationContext{ + ctx := component.InstallationContext{ "graphdb.zip": si.Positionals.GraphdbZip, } diff --git a/component/component.go b/component/component.go index bc19fbc..4cb26de 100644 --- a/component/component.go +++ b/component/component.go @@ -3,7 +3,6 @@ package component import ( "github.com/FAU-CDI/wisski-distillery/internal/config" - "github.com/FAU-CDI/wisski-distillery/internal/stack" ) // Component represents a logical subsystem of the distillery. @@ -30,11 +29,11 @@ type Component interface { // Stack can be used to gain access to the "docker compose" stack. // // This should internally call - Stack() stack.Installable + Stack() Installable // Context returns a new InstallationContext to be used during installation from the command line. // Typically this should just pass through the parent, but might perform other tasks. - Context(parent stack.InstallationContext) stack.InstallationContext + Context(parent InstallationContext) InstallationContext } // ComponentBase implements base functionality for a component @@ -50,12 +49,12 @@ func (cb ComponentBase) Path() string { } // Context passes through the parent context -func (ComponentBase) Context(parent stack.InstallationContext) stack.InstallationContext { +func (ComponentBase) Context(parent InstallationContext) InstallationContext { return parent } // MakeStack registers the Installable as a stack -func (cb ComponentBase) MakeStack(stack stack.Installable) stack.Installable { +func (cb ComponentBase) MakeStack(stack Installable) Installable { stack.Dir = cb.Dir return stack } diff --git a/component/dis/dis.go b/component/dis/dis.go index 387bad1..ff83ec0 100644 --- a/component/dis/dis.go +++ b/component/dis/dis.go @@ -5,7 +5,6 @@ import ( "github.com/FAU-CDI/wisski-distillery/component" "github.com/FAU-CDI/wisski-distillery/core" - "github.com/FAU-CDI/wisski-distillery/internal/stack" ) type Dis struct { @@ -23,8 +22,8 @@ func (dis Dis) Name() string { //go:embed all:stack dis.env var resources embed.FS -func (dis Dis) Stack() stack.Installable { - return dis.ComponentBase.MakeStack(stack.Installable{ +func (dis Dis) Stack() component.Installable { + return dis.ComponentBase.MakeStack(component.Installable{ Resources: resources, ContextPath: "stack", EnvPath: "dis.env", @@ -44,8 +43,8 @@ func (dis Dis) Stack() stack.Installable { }) } -func (dis Dis) Context(parent stack.InstallationContext) stack.InstallationContext { - return stack.InstallationContext{ +func (dis Dis) Context(parent component.InstallationContext) component.InstallationContext { + return component.InstallationContext{ core.Executable: dis.Executable, } } diff --git a/internal/stack/installable.go b/component/installable.go similarity index 99% rename from internal/stack/installable.go rename to component/installable.go index 8605773..bcf2eb2 100644 --- a/internal/stack/installable.go +++ b/component/installable.go @@ -1,4 +1,4 @@ -package stack +package component import ( "io/fs" diff --git a/component/resolver/resolver.go b/component/resolver/resolver.go index e95378c..90b078a 100644 --- a/component/resolver/resolver.go +++ b/component/resolver/resolver.go @@ -11,7 +11,6 @@ import ( "github.com/FAU-CDI/wdresolve/resolvers" "github.com/FAU-CDI/wisski-distillery/component" "github.com/FAU-CDI/wisski-distillery/core" - "github.com/FAU-CDI/wisski-distillery/internal/stack" "github.com/tkw1536/goprogram/stream" ) @@ -35,8 +34,8 @@ func (resolver Resolver) ConfigPath() string { //go:embed all:stack resolver.env var resources embed.FS -func (resolver Resolver) Stack() stack.Installable { - return resolver.ComponentBase.MakeStack(stack.Installable{ +func (resolver Resolver) Stack() component.Installable { + return resolver.ComponentBase.MakeStack(component.Installable{ Resources: resources, ContextPath: "stack", EnvPath: "resolver.env", @@ -58,8 +57,8 @@ func (resolver Resolver) Stack() stack.Installable { }) } -func (resolver Resolver) Context(parent stack.InstallationContext) stack.InstallationContext { - return stack.InstallationContext{ +func (resolver Resolver) Context(parent component.InstallationContext) component.InstallationContext { + return component.InstallationContext{ core.Executable: resolver.Executable, } } diff --git a/component/self/self.go b/component/self/self.go index 1479103..fb04235 100644 --- a/component/self/self.go +++ b/component/self/self.go @@ -4,7 +4,6 @@ import ( "embed" "github.com/FAU-CDI/wisski-distillery/component" - "github.com/FAU-CDI/wisski-distillery/internal/stack" ) type Self struct { @@ -19,14 +18,14 @@ func (Self) Name() string { //go:embed self.env var resources embed.FS -func (self Self) Stack() stack.Installable { +func (self Self) Stack() component.Installable { // TODO: Move me into config! TARGET := "https://github.com/FAU-CDI/wisski-distillery" if self.Config.SelfRedirect != nil { // TODO: move to config! TARGET = self.Config.SelfRedirect.String() } - return self.ComponentBase.MakeStack(stack.Installable{ + return self.ComponentBase.MakeStack(component.Installable{ Resources: resources, ContextPath: "stack", diff --git a/component/sql/sql.go b/component/sql/sql.go index da6c18d..52471e6 100644 --- a/component/sql/sql.go +++ b/component/sql/sql.go @@ -7,7 +7,6 @@ import ( "time" "github.com/FAU-CDI/wisski-distillery/component" - "github.com/FAU-CDI/wisski-distillery/internal/stack" ) type SQL struct { @@ -26,8 +25,8 @@ func (SQL) Name() string { //go:embed all:stack var resources embed.FS -func (ssh SQL) Stack() stack.Installable { - return ssh.ComponentBase.MakeStack(stack.Installable{ +func (ssh SQL) Stack() component.Installable { + return ssh.ComponentBase.MakeStack(component.Installable{ Resources: resources, ContextPath: "stack", diff --git a/component/ssh/ssh.go b/component/ssh/ssh.go index 7f99de7..dc9d2d6 100644 --- a/component/ssh/ssh.go +++ b/component/ssh/ssh.go @@ -4,7 +4,6 @@ import ( "embed" "github.com/FAU-CDI/wisski-distillery/component" - "github.com/FAU-CDI/wisski-distillery/internal/stack" ) type SSH struct { @@ -18,8 +17,8 @@ func (SSH) Name() string { //go:embed all:stack var resources embed.FS -func (ssh SSH) Stack() stack.Installable { - return ssh.ComponentBase.MakeStack(stack.Installable{ +func (ssh SSH) Stack() component.Installable { + return ssh.ComponentBase.MakeStack(component.Installable{ Resources: resources, ContextPath: "stack", }) diff --git a/internal/stack/stack.go b/component/stack.go similarity index 99% rename from internal/stack/stack.go rename to component/stack.go index 3b0f7c4..dbe979d 100644 --- a/internal/stack/stack.go +++ b/component/stack.go @@ -1,5 +1,5 @@ // Package stack implements a docker compose stack -package stack +package component import ( "errors" diff --git a/component/triplestore/triplestore.go b/component/triplestore/triplestore.go index 5f82b4c..b5da9f8 100644 --- a/component/triplestore/triplestore.go +++ b/component/triplestore/triplestore.go @@ -8,7 +8,6 @@ import ( "time" "github.com/FAU-CDI/wisski-distillery/component" - "github.com/FAU-CDI/wisski-distillery/internal/stack" ) type Triplestore struct { @@ -27,8 +26,8 @@ func (Triplestore) Name() string { //go:embed all:stack var resources embed.FS -func (ts Triplestore) Stack() stack.Installable { - return ts.ComponentBase.MakeStack(stack.Installable{ +func (ts Triplestore) Stack() component.Installable { + return ts.ComponentBase.MakeStack(component.Installable{ Resources: resources, ContextPath: "stack", diff --git a/component/web/web.go b/component/web/web.go index d264d77..df6a8ee 100644 --- a/component/web/web.go +++ b/component/web/web.go @@ -4,7 +4,6 @@ import ( "embed" "github.com/FAU-CDI/wisski-distillery/component" - "github.com/FAU-CDI/wisski-distillery/internal/stack" ) // Web implements the web component @@ -20,13 +19,13 @@ func (Web) Name() string { //go:embed web.env var resources embed.FS -func (web Web) Stack() stack.Installable { +func (web Web) Stack() component.Installable { HTTPS_METHOD := "nohttp" if web.Config.HTTPSEnabled() { HTTPS_METHOD = "redirect" } - return web.MakeStack(stack.Installable{ + return web.MakeStack(component.Installable{ Resources: resources, ContextPath: "stack", EnvPath: "web.env", diff --git a/env/component.go b/env/component.go index 55c18e2..866576d 100644 --- a/env/component.go +++ b/env/component.go @@ -12,8 +12,6 @@ import ( "github.com/FAU-CDI/wisski-distillery/component/ssh" "github.com/FAU-CDI/wisski-distillery/component/triplestore" "github.com/FAU-CDI/wisski-distillery/component/web" - "github.com/FAU-CDI/wisski-distillery/embed" - "github.com/FAU-CDI/wisski-distillery/internal/stack" ) // TODO: Remove me when migration is complete @@ -92,28 +90,6 @@ func (dis *Distillery) Triplestore() (ts triplestore.Triplestore) { // makeComponent updates the baseComponent belonging to component func (dis *Distillery) makeComponent(component component.Component, base *component.ComponentBase) { - base.Dir = dis.getComponentPath(component) base.Config = dis.Config -} - -// asCoreStack treats the provided stack as a core component of this distillery. -// TODO: this should no longer be used -func (dis *Distillery) makeComponentStack(component Component, stack stack.Installable) stack.Installable { - stack.Dir = dis.getComponentPath(component) - - name := component.Name() - - // TODO: This writes out resources. - // Should migrate this directly! - if stack.Resources == nil { - stack.Resources = embed.ResourceEmbed - stack.ContextPath = filepath.Join("resources", "compose", name) - stack.EnvPath = filepath.Join("resources", "templates", "docker-env", name) - } - - return stack -} - -func (dis *Distillery) getComponentPath(component Component) string { - return filepath.Join(dis.Config.DeployRoot, "core", component.Name()) + base.Dir = filepath.Join(dis.Config.DeployRoot, "core", component.Name()) } diff --git a/env/distillery.go b/env/distillery.go index cc2ac78..d7381f9 100644 --- a/env/distillery.go +++ b/env/distillery.go @@ -12,7 +12,7 @@ import ( // Distillery represents a running instance for the distillery type Distillery struct { Config *config.Config - Upstream Upstream + Upstream Upstream // TODO: not sure this belongs here } // Upstream are the upstream urls connecting to the various external components. diff --git a/env/instances.go b/env/instances.go index bd6b292..199b202 100644 --- a/env/instances.go +++ b/env/instances.go @@ -11,10 +11,10 @@ import ( "path/filepath" "strings" + "github.com/FAU-CDI/wisski-distillery/component" "github.com/FAU-CDI/wisski-distillery/embed" "github.com/FAU-CDI/wisski-distillery/internal/bookkeeping" "github.com/FAU-CDI/wisski-distillery/internal/fsx" - "github.com/FAU-CDI/wisski-distillery/internal/stack" "github.com/alessio/shellescape" "github.com/pkg/errors" "github.com/tkw1536/goprogram/exit" @@ -229,9 +229,9 @@ func (instance Instance) URL() *url.URL { } // Stack represents a stack representing this instance -func (instance Instance) Stack() stack.Installable { - return stack.Installable{ - Stack: stack.Stack{ +func (instance Instance) Stack() component.Installable { + return component.Installable{ + Stack: component.Stack{ Dir: instance.FilesystemBase, }, Resources: embed.ResourceEmbed, // TODO: Move this over @@ -260,9 +260,9 @@ func (instance Instance) Stack() stack.Installable { } } -func (instance Instance) ReserveStack() stack.Installable { - return stack.Installable{ - Stack: stack.Stack{ +func (instance Instance) ReserveStack() component.Installable { + return component.Installable{ + Stack: component.Stack{ Dir: instance.FilesystemBase, }, ContextPath: filepath.Join("resources", "compose", "reserve"), @@ -282,7 +282,7 @@ func (instance Instance) Provision(io stream.IOStream) error { // create the basic st! st := instance.Stack() - if err := st.Install(io, stack.InstallationContext{}); err != nil { + if err := st.Install(io, component.InstallationContext{}); err != nil { return err }