component: Automatically determine names
This commit is contained in:
parent
10df1c3243
commit
e320bb37bb
31 changed files with 84 additions and 113 deletions
|
|
@ -71,7 +71,7 @@ func (p purge) Run(context wisski_distillery.Context) error {
|
||||||
|
|
||||||
// remove the filesystem
|
// remove the filesystem
|
||||||
logging.LogMessage(context.IOStream, "Removing from filesystem %s", instance.FilesystemBase)
|
logging.LogMessage(context.IOStream, "Removing from filesystem %s", instance.FilesystemBase)
|
||||||
if err := dis.Core.Environment.RemoveAll(instance.FilesystemBase); err != nil {
|
if err := dis.Still.Environment.RemoveAll(instance.FilesystemBase); err != nil {
|
||||||
context.EPrintln(err)
|
context.EPrintln(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -41,7 +41,7 @@ func (s server) Run(context wisski_distillery.Context) error {
|
||||||
context.Printf("Listening on %s\n", s.Bind)
|
context.Printf("Listening on %s\n", s.Bind)
|
||||||
|
|
||||||
// make a new listener
|
// make a new listener
|
||||||
listener, err := dis.Core.Environment.Listen("tcp", s.Bind)
|
listener, err := dis.Still.Environment.Listen("tcp", s.Bind)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errServerListen.Wrap(err)
|
return errServerListen.Wrap(err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -74,7 +74,7 @@ func (si systemupdate) Run(context wisski_distillery.Context) error {
|
||||||
dis.Exporter().ArchivePath(),
|
dis.Exporter().ArchivePath(),
|
||||||
} {
|
} {
|
||||||
context.Println(d)
|
context.Println(d)
|
||||||
if err := dis.Core.Environment.MkdirAll(d, environment.DefaultDirPerm); err != nil {
|
if err := dis.Still.Environment.MkdirAll(d, environment.DefaultDirPerm); err != nil {
|
||||||
return errBoostrapFailedToCreateDirectory.WithMessageF(d, err)
|
return errBoostrapFailedToCreateDirectory.WithMessageF(d, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -166,7 +166,7 @@ func (si systemupdate) mustExec(context wisski_distillery.Context, workdir strin
|
||||||
if workdir == "" {
|
if workdir == "" {
|
||||||
workdir = context.Environment.Config.DeployRoot
|
workdir = context.Environment.Config.DeployRoot
|
||||||
}
|
}
|
||||||
code := dis.Core.Environment.Exec(context.IOStream, workdir, exe, argv...)
|
code := dis.Still.Environment.Exec(context.IOStream, workdir, exe, argv...)
|
||||||
if code != 0 {
|
if code != 0 {
|
||||||
err := errMustExecFailed.WithMessageF(code)
|
err := errMustExecFailed.WithMessageF(code)
|
||||||
err.ExitCode = exit.ExitCode(code)
|
err.ExitCode = exit.ExitCode(code)
|
||||||
|
|
|
||||||
|
|
@ -10,20 +10,11 @@ package component
|
||||||
//
|
//
|
||||||
// Components are initialized using a [Pool].
|
// Components are initialized using a [Pool].
|
||||||
type Component interface {
|
type Component interface {
|
||||||
// Name returns the name of this component.
|
// Name returns the name of this component
|
||||||
// It should correspond to the appropriate subpackage.
|
// Name should be implemented by the [ComponentBase] struct.
|
||||||
Name() string
|
Name() string
|
||||||
|
|
||||||
// getBase returns the embedded ComponentBase struct.
|
// getComponentBase returns the underlying ComponentBase object of this Component.
|
||||||
getBase() *ComponentBase
|
// It is used internally during initialization
|
||||||
}
|
getComponentBase() *ComponentBase
|
||||||
|
|
||||||
// ComponentBase should be embedded into every component
|
|
||||||
type ComponentBase struct {
|
|
||||||
Core // the underlying stillage of the distillery
|
|
||||||
}
|
|
||||||
|
|
||||||
//lint:ignore U1000 used to implement the private methods of [Component]
|
|
||||||
func (cb *ComponentBase) getBase() *ComponentBase {
|
|
||||||
return cb
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,12 +16,8 @@ type Control struct {
|
||||||
Servables []component.Servable
|
Servables []component.Servable
|
||||||
}
|
}
|
||||||
|
|
||||||
func (control Control) Name() string {
|
|
||||||
return "dis" // TODO: Rename this to control!
|
|
||||||
}
|
|
||||||
|
|
||||||
func (control Control) Path() string {
|
func (control Control) Path() string {
|
||||||
return filepath.Join(control.Core.Config.DeployRoot, "core", control.Name())
|
return filepath.Join(control.Still.Config.DeployRoot, "core", "dis")
|
||||||
}
|
}
|
||||||
|
|
||||||
//go:embed all:control control.env
|
//go:embed all:control control.env
|
||||||
|
|
|
||||||
|
|
@ -1,11 +0,0 @@
|
||||||
package component
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/FAU-CDI/wisski-distillery/internal/config"
|
|
||||||
"github.com/FAU-CDI/wisski-distillery/pkg/environment"
|
|
||||||
)
|
|
||||||
|
|
||||||
type Core struct {
|
|
||||||
Environment environment.Environment // environment to use for reading / writing to and from the distillery
|
|
||||||
Config *config.Config // the configuration of the distillery
|
|
||||||
}
|
|
||||||
|
|
@ -27,8 +27,6 @@ type Exporter struct {
|
||||||
Backupable []component.Backupable
|
Backupable []component.Backupable
|
||||||
}
|
}
|
||||||
|
|
||||||
func (Exporter) Name() string { return "snapshots" }
|
|
||||||
|
|
||||||
// Path returns the path that contains all snapshot related data.
|
// Path returns the path that contains all snapshot related data.
|
||||||
func (dis *Exporter) Path() string {
|
func (dis *Exporter) Path() string {
|
||||||
return filepath.Join(dis.Config.DeployRoot, "snapshots")
|
return filepath.Join(dis.Config.DeployRoot, "snapshots")
|
||||||
|
|
@ -74,7 +72,7 @@ func (*Exporter) newSnapshotName(prefix string) string {
|
||||||
func (dis *Exporter) NewStagingDir(prefix string) (path string, err error) {
|
func (dis *Exporter) NewStagingDir(prefix string) (path string, err error) {
|
||||||
for path == "" || environment.IsExist(err) {
|
for path == "" || environment.IsExist(err) {
|
||||||
path = filepath.Join(dis.StagingPath(), dis.newSnapshotName(prefix))
|
path = filepath.Join(dis.StagingPath(), dis.newSnapshotName(prefix))
|
||||||
err = dis.Core.Environment.Mkdir(path, environment.DefaultFilePerm)
|
err = dis.Still.Environment.Mkdir(path, environment.DefaultFilePerm)
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
path = ""
|
path = ""
|
||||||
|
|
|
||||||
|
|
@ -12,8 +12,6 @@ type Bookkeeping struct {
|
||||||
component.ComponentBase
|
component.ComponentBase
|
||||||
}
|
}
|
||||||
|
|
||||||
func (Bookkeeping) Name() string { return "bookkeeping" }
|
|
||||||
|
|
||||||
// SnapshotNeedsRunning returns if this Snapshotable requires a running instance.
|
// SnapshotNeedsRunning returns if this Snapshotable requires a running instance.
|
||||||
func (Bookkeeping) SnapshotNeedsRunning() bool { return false }
|
func (Bookkeeping) SnapshotNeedsRunning() bool { return false }
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -11,8 +11,6 @@ type Config struct {
|
||||||
component.ComponentBase
|
component.ComponentBase
|
||||||
}
|
}
|
||||||
|
|
||||||
func (Config) Name() string { return "config" }
|
|
||||||
|
|
||||||
func (*Config) BackupName() string {
|
func (*Config) BackupName() string {
|
||||||
return "config"
|
return "config"
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,8 +10,6 @@ type Filesystem struct {
|
||||||
component.ComponentBase
|
component.ComponentBase
|
||||||
}
|
}
|
||||||
|
|
||||||
func (Filesystem) Name() string { return "filesystem" }
|
|
||||||
|
|
||||||
// SnapshotNeedsRunning returns if this Snapshotable requires a running instance.
|
// SnapshotNeedsRunning returns if this Snapshotable requires a running instance.
|
||||||
func (Filesystem) SnapshotNeedsRunning() bool { return false }
|
func (Filesystem) SnapshotNeedsRunning() bool { return false }
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -13,8 +13,6 @@ type Pathbuilders struct {
|
||||||
Instances *instances.Instances
|
Instances *instances.Instances
|
||||||
}
|
}
|
||||||
|
|
||||||
func (Pathbuilders) Name() string { return "pathbuilders" }
|
|
||||||
|
|
||||||
func (Pathbuilders) SnapshotNeedsRunning() bool { return true }
|
func (Pathbuilders) SnapshotNeedsRunning() bool { return true }
|
||||||
|
|
||||||
func (Pathbuilders) SnapshotName() string { return "pathbuilders" }
|
func (Pathbuilders) SnapshotName() string { return "pathbuilders" }
|
||||||
|
|
|
||||||
|
|
@ -15,8 +15,6 @@ type Logger struct {
|
||||||
SQL *sql.SQL
|
SQL *sql.SQL
|
||||||
}
|
}
|
||||||
|
|
||||||
func (*Logger) Name() string { return "snapshots-log" }
|
|
||||||
|
|
||||||
// For retrieves (and prunes) the ExportLog.
|
// For retrieves (and prunes) the ExportLog.
|
||||||
// Slug determines if entries for Backups (empty slug)
|
// Slug determines if entries for Backups (empty slug)
|
||||||
// or a specific Instance (non-empty slug) are returned.
|
// or a specific Instance (non-empty slug) are returned.
|
||||||
|
|
@ -48,7 +46,7 @@ func (log *Logger) Log() ([]models.Export, error) {
|
||||||
|
|
||||||
// partition out the exports that have been deleted!
|
// partition out the exports that have been deleted!
|
||||||
parts := collection.Partition(exports, func(s models.Export) bool {
|
parts := collection.Partition(exports, func(s models.Export) bool {
|
||||||
_, err := log.Core.Environment.Stat(s.Path)
|
_, err := log.Still.Environment.Stat(s.Path)
|
||||||
return !environment.IsNotExist(err)
|
return !environment.IsNotExist(err)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ func (exporter *Exporter) PruneExports(io stream.IOStream) error {
|
||||||
sPath := exporter.ArchivePath()
|
sPath := exporter.ArchivePath()
|
||||||
|
|
||||||
// list all the files
|
// list all the files
|
||||||
entries, err := exporter.Core.Environment.ReadDir(sPath)
|
entries, err := exporter.Still.Environment.ReadDir(sPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
@ -44,7 +44,7 @@ func (exporter *Exporter) PruneExports(io stream.IOStream) error {
|
||||||
path := filepath.Join(sPath, entry.Name())
|
path := filepath.Join(sPath, entry.Name())
|
||||||
io.Printf("Removing %s cause it is older than %d days", path, exporter.Config.MaxBackupAge)
|
io.Printf("Removing %s cause it is older than %d days", path, exporter.Config.MaxBackupAge)
|
||||||
|
|
||||||
if err := exporter.Core.Environment.Remove(path); err != nil {
|
if err := exporter.Still.Environment.Remove(path); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -24,8 +24,6 @@ type Home struct {
|
||||||
homeBytes lazy.Lazy[[]byte]
|
homeBytes lazy.Lazy[[]byte]
|
||||||
}
|
}
|
||||||
|
|
||||||
func (*Home) Name() string { return "home" }
|
|
||||||
|
|
||||||
func (*Home) Routes() []string { return []string{"/"} }
|
func (*Home) Routes() []string { return []string{"/"} }
|
||||||
|
|
||||||
func (home *Home) Handler(route string, context context.Context, io stream.IOStream) (http.Handler, error) {
|
func (home *Home) Handler(route string, context context.Context, io stream.IOStream) (http.Handler, error) {
|
||||||
|
|
|
||||||
|
|
@ -21,8 +21,6 @@ type Info struct {
|
||||||
SnapshotsLog *logger.Logger
|
SnapshotsLog *logger.Logger
|
||||||
}
|
}
|
||||||
|
|
||||||
func (Info) Name() string { return "control-info" }
|
|
||||||
|
|
||||||
func (*Info) Routes() []string { return []string{"/dis/"} }
|
func (*Info) Routes() []string { return []string{"/dis/"} }
|
||||||
|
|
||||||
func (info *Info) Handler(route string, context context.Context, io stream.IOStream) (http.Handler, error) {
|
func (info *Info) Handler(route string, context context.Context, io stream.IOStream) (http.Handler, error) {
|
||||||
|
|
|
||||||
|
|
@ -27,12 +27,8 @@ type Instances struct {
|
||||||
ExporterLog *logger.Logger
|
ExporterLog *logger.Logger
|
||||||
}
|
}
|
||||||
|
|
||||||
func (Instances) Name() string {
|
|
||||||
return "instances"
|
|
||||||
}
|
|
||||||
|
|
||||||
func (instances *Instances) Path() string {
|
func (instances *Instances) Path() string {
|
||||||
return filepath.Join(instances.Core.Config.DeployRoot, instances.Name())
|
return filepath.Join(instances.Still.Config.DeployRoot, "instances")
|
||||||
}
|
}
|
||||||
|
|
||||||
// ErrWissKINotFound is returned when a WissKI is not found
|
// ErrWissKINotFound is returned when a WissKI is not found
|
||||||
|
|
@ -45,7 +41,7 @@ var errSQL = exit.Error{
|
||||||
|
|
||||||
// use uses the non-nil wisski instance with this instances
|
// use uses the non-nil wisski instance with this instances
|
||||||
func (instances *Instances) use(wisski *wisski.WissKI) {
|
func (instances *Instances) use(wisski *wisski.WissKI) {
|
||||||
wisski.Core = instances.Core
|
wisski.Core = instances.Still
|
||||||
wisski.SQL = instances.SQL
|
wisski.SQL = instances.SQL
|
||||||
wisski.TS = instances.TS
|
wisski.TS = instances.TS
|
||||||
wisski.Meta = instances.Meta
|
wisski.Meta = instances.Meta
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@ var runtimeResources embed.FS
|
||||||
|
|
||||||
// Update installs or updates runtime components needed by this component.
|
// Update installs or updates runtime components needed by this component.
|
||||||
func (instances *Instances) Update(stream stream.IOStream) error {
|
func (instances *Instances) Update(stream stream.IOStream) error {
|
||||||
err := unpack.InstallDir(instances.Core.Environment, instances.Config.RuntimeDir(), "runtime", runtimeResources, func(dst, src string) {
|
err := unpack.InstallDir(instances.Still.Environment, instances.Config.RuntimeDir(), "runtime", runtimeResources, func(dst, src string) {
|
||||||
stream.Printf("[copy] %s\n", dst)
|
stream.Printf("[copy] %s\n", dst)
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
|
|
@ -17,8 +17,6 @@ type Meta struct {
|
||||||
sc map[string]*Storage
|
sc map[string]*Storage
|
||||||
}
|
}
|
||||||
|
|
||||||
func (*Meta) Name() string { return "metadata" }
|
|
||||||
|
|
||||||
// Storage returns a Storage for the instance with the given slug.
|
// Storage returns a Storage for the instance with the given slug.
|
||||||
// When slug is nil, returns a global storage.
|
// When slug is nil, returns a global storage.
|
||||||
func (meta *Meta) Storage(slug string) *Storage {
|
func (meta *Meta) Storage(slug string) *Storage {
|
||||||
|
|
|
||||||
|
|
@ -7,14 +7,16 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type ComponentPool struct {
|
type ComponentPool struct {
|
||||||
pool lazy.Pool[Component, Core]
|
pool lazy.Pool[Component, Still]
|
||||||
poolInit sync.Once
|
poolInit sync.Once
|
||||||
}
|
}
|
||||||
|
|
||||||
func (pool *ComponentPool) init() {
|
func (pool *ComponentPool) init() {
|
||||||
pool.poolInit.Do(func() {
|
pool.poolInit.Do(func() {
|
||||||
pool.pool.Init = func(component Component, core Core) Component {
|
pool.pool.Init = func(component Component, core Still) Component {
|
||||||
component.getBase().Core = core
|
base := component.getComponentBase()
|
||||||
|
base.Still = core
|
||||||
|
base.name = nameOf(component)
|
||||||
return component
|
return component
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
@ -23,7 +25,7 @@ func (pool *ComponentPool) init() {
|
||||||
type ComponentPoolContext = *lazy.PoolContext[Component]
|
type ComponentPoolContext = *lazy.PoolContext[Component]
|
||||||
type ComponentAllFunc = func(context ComponentPoolContext) []Component
|
type ComponentAllFunc = func(context ComponentPoolContext) []Component
|
||||||
|
|
||||||
func (pool *ComponentPool) All(core Core, init func(context ComponentPoolContext) []Component) []Component {
|
func (pool *ComponentPool) All(core Still, init func(context ComponentPoolContext) []Component) []Component {
|
||||||
pool.init()
|
pool.init()
|
||||||
return pool.pool.All(core, init)
|
return pool.pool.All(core, init)
|
||||||
}
|
}
|
||||||
|
|
@ -43,7 +45,7 @@ func (pool *ComponentPool) All(core Core, init func(context ComponentPoolContext
|
||||||
// Furthermore, the init function may not cause other components to be initialized.
|
// Furthermore, the init function may not cause other components to be initialized.
|
||||||
//
|
//
|
||||||
// The init function may be nil, indicating that no additional initialization is required.
|
// The init function may be nil, indicating that no additional initialization is required.
|
||||||
func MakeComponent[C Component](context ComponentPoolContext, core Core, init func(component C)) C {
|
func MakeComponent[C Component](context ComponentPoolContext, core Still, init func(component C)) C {
|
||||||
return lazy.Make(context, init)
|
return lazy.Make(context, init)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -51,16 +53,16 @@ func MakeComponent[C Component](context ComponentPoolContext, core Core, init fu
|
||||||
//
|
//
|
||||||
// All should be the function of the core that initializes all components.
|
// All should be the function of the core that initializes all components.
|
||||||
// All should only make calls to [InitComponent].
|
// All should only make calls to [InitComponent].
|
||||||
func ExportComponents[C Component](pool *ComponentPool, core Core, All ComponentAllFunc) []C {
|
func ExportComponents[C Component](pool *ComponentPool, core Still, All ComponentAllFunc) []C {
|
||||||
pool.init()
|
pool.init()
|
||||||
return lazy.ExportComponents[Component, Core, C](&pool.pool, core, All)
|
return lazy.ExportComponents[Component, Still, C](&pool.pool, core, All)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ExportComponent exports the first component that is a C from the pool.
|
// ExportComponent exports the first component that is a C from the pool.
|
||||||
//
|
//
|
||||||
// All should be the function of the core that initializes all components.
|
// All should be the function of the core that initializes all components.
|
||||||
// All should only make calls to [InitComponent].
|
// All should only make calls to [InitComponent].
|
||||||
func ExportComponent[C Component](pool *ComponentPool, core Core, All ComponentAllFunc) C {
|
func ExportComponent[C Component](pool *ComponentPool, core Still, All ComponentAllFunc) C {
|
||||||
pool.init()
|
pool.init()
|
||||||
return lazy.ExportComponent[Component, Core, C](&pool.pool, core, All)
|
return lazy.ExportComponent[Component, Still, C](&pool.pool, core, All)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -26,8 +26,6 @@ type Resolver struct {
|
||||||
handler lazy.Lazy[wdresolve.ResolveHandler] // handler
|
handler lazy.Lazy[wdresolve.ResolveHandler] // handler
|
||||||
}
|
}
|
||||||
|
|
||||||
func (*Resolver) Name() string { return "resolver" }
|
|
||||||
|
|
||||||
func (resolver *Resolver) Routes() []string { return []string{"/go/", "/wisski/get/"} }
|
func (resolver *Resolver) Routes() []string { return []string{"/go/", "/wisski/get/"} }
|
||||||
|
|
||||||
func (resolver *Resolver) Handler(route string, context context.Context, io stream.IOStream) (http.Handler, error) {
|
func (resolver *Resolver) Handler(route string, context context.Context, io stream.IOStream) (http.Handler, error) {
|
||||||
|
|
|
||||||
|
|
@ -133,7 +133,7 @@ func (sql *SQL) network() string {
|
||||||
// this seems like a bit of a hack, but it works for now.
|
// this seems like a bit of a hack, but it works for now.
|
||||||
name = fmt.Sprintf("sql-network-%d", atomic.AddUint64(&proxyNameCounter, 1))
|
name = fmt.Sprintf("sql-network-%d", atomic.AddUint64(&proxyNameCounter, 1))
|
||||||
mysqldriver.RegisterDialContext(name, func(ctx context.Context, addr string) (net.Conn, error) {
|
mysqldriver.RegisterDialContext(name, func(ctx context.Context, addr string) (net.Conn, error) {
|
||||||
return sql.Core.Environment.DialContext(ctx, network, addr)
|
return sql.Still.Environment.DialContext(ctx, network, addr)
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -22,12 +22,8 @@ type SQL struct {
|
||||||
lazyNetwork lazy.Lazy[string]
|
lazyNetwork lazy.Lazy[string]
|
||||||
}
|
}
|
||||||
|
|
||||||
func (*SQL) Name() string {
|
|
||||||
return "sql"
|
|
||||||
}
|
|
||||||
|
|
||||||
func (sql *SQL) Path() string {
|
func (sql *SQL) Path() string {
|
||||||
return filepath.Join(sql.Core.Config.DeployRoot, "core", sql.Name())
|
return filepath.Join(sql.Still.Config.DeployRoot, "core", "sql")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (*SQL) Context(parent component.InstallationContext) component.InstallationContext {
|
func (*SQL) Context(parent component.InstallationContext) component.InstallationContext {
|
||||||
|
|
|
||||||
|
|
@ -12,15 +12,11 @@ type SSH struct {
|
||||||
component.ComponentBase
|
component.ComponentBase
|
||||||
}
|
}
|
||||||
|
|
||||||
func (SSH) Name() string {
|
func (ssh *SSH) Path() string {
|
||||||
return "ssh"
|
return filepath.Join(ssh.Still.Config.DeployRoot, "core", "ssh")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ssh SSH) Path() string {
|
func (*SSH) Context(parent component.InstallationContext) component.InstallationContext {
|
||||||
return filepath.Join(ssh.Core.Config.DeployRoot, "core", ssh.Name())
|
|
||||||
}
|
|
||||||
|
|
||||||
func (SSH) Context(parent component.InstallationContext) component.InstallationContext {
|
|
||||||
return parent
|
return parent
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -15,8 +15,6 @@ type Static struct {
|
||||||
component.ComponentBase
|
component.ComponentBase
|
||||||
}
|
}
|
||||||
|
|
||||||
func (*Static) Name() string { return "static" }
|
|
||||||
|
|
||||||
func (*Static) Routes() []string { return []string{"/static/"} }
|
func (*Static) Routes() []string { return []string{"/static/"} }
|
||||||
|
|
||||||
//go:embed dist
|
//go:embed dist
|
||||||
|
|
|
||||||
36
internal/component/still.go
Normal file
36
internal/component/still.go
Normal file
|
|
@ -0,0 +1,36 @@
|
||||||
|
package component
|
||||||
|
|
||||||
|
import (
|
||||||
|
"reflect"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/FAU-CDI/wisski-distillery/internal/config"
|
||||||
|
"github.com/FAU-CDI/wisski-distillery/pkg/environment"
|
||||||
|
)
|
||||||
|
|
||||||
|
// ComponentBase is embedded into every Component
|
||||||
|
type ComponentBase struct {
|
||||||
|
name string // name is the name of this component
|
||||||
|
Still // the underlying still of the distillery
|
||||||
|
}
|
||||||
|
|
||||||
|
//lint:ignore U1000 used to implement the private methods of [Component]
|
||||||
|
func (cb *ComponentBase) getComponentBase() *ComponentBase {
|
||||||
|
return cb
|
||||||
|
}
|
||||||
|
|
||||||
|
func (cb ComponentBase) Name() string {
|
||||||
|
return cb.name
|
||||||
|
}
|
||||||
|
|
||||||
|
// nameOf returns the name of the given component
|
||||||
|
func nameOf(component Component) string {
|
||||||
|
return strings.ToLower(reflect.TypeOf(component).Elem().Name())
|
||||||
|
}
|
||||||
|
|
||||||
|
// Still represents the central part of a distillery.
|
||||||
|
// It is used inside the main distillery struct, as well as every component via [ComponentBase].
|
||||||
|
type Still struct {
|
||||||
|
Environment environment.Environment // environment to use for reading / writing to and from the distillery
|
||||||
|
Config *config.Config // the configuration of the distillery
|
||||||
|
}
|
||||||
|
|
@ -19,12 +19,8 @@ type Triplestore struct {
|
||||||
PollInterval time.Duration // duration to wait for during wait
|
PollInterval time.Duration // duration to wait for during wait
|
||||||
}
|
}
|
||||||
|
|
||||||
func (Triplestore) Name() string {
|
func (ts *Triplestore) Path() string {
|
||||||
return "triplestore"
|
return filepath.Join(ts.Still.Config.DeployRoot, "core", "triplestore")
|
||||||
}
|
|
||||||
|
|
||||||
func (ts Triplestore) Path() string {
|
|
||||||
return filepath.Join(ts.Core.Config.DeployRoot, "core", ts.Name())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (Triplestore) Context(parent component.InstallationContext) component.InstallationContext {
|
func (Triplestore) Context(parent component.InstallationContext) component.InstallationContext {
|
||||||
|
|
|
||||||
|
|
@ -15,16 +15,11 @@ type Web struct {
|
||||||
component.ComponentBase
|
component.ComponentBase
|
||||||
}
|
}
|
||||||
|
|
||||||
func (Web) Name() string {
|
func (web *Web) Path() string {
|
||||||
return "web"
|
return filepath.Join(web.Still.Config.DeployRoot, "core", "web")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (web Web) Path() string {
|
func (*Web) Context(parent component.InstallationContext) component.InstallationContext {
|
||||||
res := filepath.Join(web.Core.Config.DeployRoot, "core", web.Name())
|
|
||||||
return res
|
|
||||||
}
|
|
||||||
|
|
||||||
func (Web) Context(parent component.InstallationContext) component.InstallationContext {
|
|
||||||
return parent
|
return parent
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -70,11 +70,11 @@ type initFunc = func(dis *Distillery, context component.ComponentPoolContext) co
|
||||||
// manual initializes a component from the provided distillery.
|
// manual initializes a component from the provided distillery.
|
||||||
func manual[C component.Component](init func(component C)) initFunc {
|
func manual[C component.Component](init func(component C)) initFunc {
|
||||||
return func(dis *Distillery, context component.ComponentPoolContext) component.Component {
|
return func(dis *Distillery, context component.ComponentPoolContext) component.Component {
|
||||||
return component.MakeComponent(context, dis.Core, init)
|
return component.MakeComponent(context, dis.Still, init)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// use is like r, but does not provided additional initialization
|
// use is like r, but does not provided additional initialization
|
||||||
func auto[C component.Component](dis *Distillery, context component.ComponentPoolContext) component.Component {
|
func auto[C component.Component](dis *Distillery, context component.ComponentPoolContext) component.Component {
|
||||||
return component.MakeComponent[C](context, dis.Core, nil)
|
return component.MakeComponent[C](context, dis.Still, nil)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@ import (
|
||||||
// It is the main structure used to interact with different components.
|
// It is the main structure used to interact with different components.
|
||||||
type Distillery struct {
|
type Distillery struct {
|
||||||
// core holds the core of the distillery
|
// core holds the core of the distillery
|
||||||
component.Core
|
component.Still
|
||||||
|
|
||||||
// internal context for the distillery
|
// internal context for the distillery
|
||||||
context context.Context
|
context context.Context
|
||||||
|
|
@ -54,7 +54,7 @@ func (dis *Distillery) Context() context.Context {
|
||||||
func e[C component.Component](dis *Distillery) C {
|
func e[C component.Component](dis *Distillery) C {
|
||||||
return component.ExportComponent[C](
|
return component.ExportComponent[C](
|
||||||
&dis.pool,
|
&dis.pool,
|
||||||
dis.Core,
|
dis.Still,
|
||||||
dis.register,
|
dis.register,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
@ -62,7 +62,7 @@ func e[C component.Component](dis *Distillery) C {
|
||||||
func ea[C component.Component](dis *Distillery) []C {
|
func ea[C component.Component](dis *Distillery) []C {
|
||||||
return component.ExportComponents[C](
|
return component.ExportComponents[C](
|
||||||
&dis.pool,
|
&dis.pool,
|
||||||
dis.Core,
|
dis.Still,
|
||||||
dis.register,
|
dis.register,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@ var errOpenConfig = exit.Error{
|
||||||
func NewDistillery(params cli.Params, flags cli.Flags, req cli.Requirements) (dis *Distillery, err error) {
|
func NewDistillery(params cli.Params, flags cli.Flags, req cli.Requirements) (dis *Distillery, err error) {
|
||||||
dis = &Distillery{
|
dis = &Distillery{
|
||||||
context: params.Context,
|
context: params.Context,
|
||||||
Core: component.Core{
|
Still: component.Still{
|
||||||
Environment: environment.Native{},
|
Environment: environment.Native{},
|
||||||
},
|
},
|
||||||
Upstream: Upstream{
|
Upstream: Upstream{
|
||||||
|
|
@ -38,7 +38,7 @@ func NewDistillery(params cli.Params, flags cli.Flags, req cli.Requirements) (di
|
||||||
if flags.InternalInDocker {
|
if flags.InternalInDocker {
|
||||||
dis.Upstream.SQL = "sql:3306"
|
dis.Upstream.SQL = "sql:3306"
|
||||||
dis.Upstream.Triplestore = "triplestore:7200"
|
dis.Upstream.Triplestore = "triplestore:7200"
|
||||||
params.ConfigPath = dis.Core.Environment.GetEnv("CONFIG_PATH")
|
params.ConfigPath = dis.Still.Environment.GetEnv("CONFIG_PATH")
|
||||||
}
|
}
|
||||||
|
|
||||||
// if we don't need to load the config, there is nothing to do
|
// if we don't need to load the config, there is nothing to do
|
||||||
|
|
@ -56,7 +56,7 @@ func NewDistillery(params cli.Params, flags cli.Flags, req cli.Requirements) (di
|
||||||
}
|
}
|
||||||
|
|
||||||
// open the config file!
|
// open the config file!
|
||||||
f, err := dis.Core.Environment.Open(params.ConfigPath)
|
f, err := dis.Still.Environment.Open(params.ConfigPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errOpenConfig.WithMessageF(err)
|
return nil, errOpenConfig.WithMessageF(err)
|
||||||
}
|
}
|
||||||
|
|
@ -66,6 +66,6 @@ func NewDistillery(params cli.Params, flags cli.Flags, req cli.Requirements) (di
|
||||||
dis.Config = &config.Config{
|
dis.Config = &config.Config{
|
||||||
ConfigPath: cfg,
|
ConfigPath: cfg,
|
||||||
}
|
}
|
||||||
err = dis.Config.Unmarshal(dis.Core.Environment, f)
|
err = dis.Config.Unmarshal(dis.Still.Environment, f)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@ type WissKI struct {
|
||||||
DrupalPassword string
|
DrupalPassword string
|
||||||
|
|
||||||
// references to components!
|
// references to components!
|
||||||
Core component.Core
|
Core component.Still
|
||||||
Meta *meta.Meta
|
Meta *meta.Meta
|
||||||
TS *triplestore.Triplestore
|
TS *triplestore.Triplestore
|
||||||
SQL *sql.SQL
|
SQL *sql.SQL
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue