Move code into new component package

This commit cleans up the resources in the 'embed' package, and instead
moves them into subpackages of a new 'compose' package. This makes sure
that '.env' templates and docker compose contexts are located in the
same location.
This commit is contained in:
Tom Wiesing 2022-09-11 15:41:11 +02:00
parent 2ee90bf462
commit 7b2f79bea1
No known key found for this signature in database
44 changed files with 579 additions and 559 deletions

78
env/component.go vendored
View file

@ -2,15 +2,27 @@ package env
import (
"path/filepath"
"time"
"github.com/FAU-CDI/wisski-distillery/component"
"github.com/FAU-CDI/wisski-distillery/component/dis"
"github.com/FAU-CDI/wisski-distillery/component/resolver"
"github.com/FAU-CDI/wisski-distillery/component/self"
"github.com/FAU-CDI/wisski-distillery/component/sql"
"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
type Component = component.Component
// TODO: Move everything into specific subpackages
// Stacks returns the Stacks of this distillery
func (dis *Distillery) Components() []Component {
func (dis *Distillery) Components() []component.Component {
// TODO: Do we want to cache these components?
return []Component{
dis.Web(),
@ -23,17 +35,69 @@ func (dis *Distillery) Components() []Component {
}
}
// Component represents a component of the distillery
type Component interface {
Name() string // Name is the name of this component
// Web returns the web component belonging to this distillery
func (dis *Distillery) Web() (web web.Web) {
dis.makeComponent(web, &web.ComponentBase)
return
}
Stack() stack.Installable // Stack returns the installable stack representing this component
Context(parent stack.InstallationContext) stack.InstallationContext // context for installation
// Self returns the self component belonging to this distillery
func (dis *Distillery) Self() (self self.Self) {
dis.makeComponent(self, &self.ComponentBase)
return
}
Path() string // Path returns the path to this component
// Resolver returns the resolver component belonging to this distillery
func (dis *Distillery) Resolver() (resolver resolver.Resolver) {
resolver.ConfigName = "prefix.cfg" // TODO: Move into core?
resolver.Executable = dis.CurrentExecutable()
dis.makeComponent(resolver, &resolver.ComponentBase)
return
}
// Dis returns the dis component belonging to this distillery
func (dis *Distillery) Dis() (ddis dis.Dis) {
ddis.Executable = dis.CurrentExecutable()
dis.makeComponent(ddis, &ddis.ComponentBase)
return
}
// SSH returns the SSH component belonging to this distillery
func (dis *Distillery) SSH() (ssh ssh.SSH) {
dis.makeComponent(ssh, &ssh.ComponentBase)
return
}
// SQL returns the SQL component belonging to this distillery
func (dis *Distillery) SQL() (sql sql.SQL) {
sql.ServerURL = dis.Upstream.SQL
sql.PollContext = dis.Context()
sql.PollInterval = time.Second
dis.makeComponent(sql, &sql.ComponentBase)
return
}
// Triplestore returns the TriplestoreComponent belonging to this distillery
func (dis *Distillery) Triplestore() (ts triplestore.Triplestore) {
ts.BaseURL = "http://" + dis.Upstream.Triplestore
ts.PollContext = dis.Context()
ts.PollInterval = time.Second
dis.makeComponent(ts, &ts.ComponentBase)
return
}
// 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)