Merge internal/stack => component

This commit is contained in:
Tom Wiesing 2022-09-11 16:03:13 +02:00
parent 7b2f79bea1
commit 91a088a56a
No known key found for this signature in database
16 changed files with 40 additions and 72 deletions

View file

@ -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

View file

@ -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
}

View file

@ -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,
}

View file

@ -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
}

View file

@ -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,
}
}

View file

@ -1,4 +1,4 @@
package stack
package component
import (
"io/fs"

View file

@ -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,
}
}

View file

@ -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",

View file

@ -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",

View file

@ -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",
})

View file

@ -1,5 +1,5 @@
// Package stack implements a docker compose stack
package stack
package component
import (
"errors"

View file

@ -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",

View file

@ -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",

26
env/component.go vendored
View file

@ -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())
}

2
env/distillery.go vendored
View file

@ -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.

16
env/instances.go vendored
View file

@ -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
}