Remove environment.Environment struct
This commit completely removes the environment struct as it is no longer used.
This commit is contained in:
parent
3263920d6b
commit
473040a69f
40 changed files with 91 additions and 146 deletions
|
|
@ -6,7 +6,6 @@ import (
|
|||
"path/filepath"
|
||||
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/models"
|
||||
"github.com/FAU-CDI/wisski-distillery/pkg/environment"
|
||||
"github.com/FAU-CDI/wisski-distillery/pkg/fsx"
|
||||
"github.com/FAU-CDI/wisski-distillery/pkg/logging"
|
||||
"github.com/pkg/errors"
|
||||
|
|
@ -66,10 +65,9 @@ type StagingContext interface {
|
|||
}
|
||||
|
||||
// NewStagingContext returns a new [StagingContext]
|
||||
func NewStagingContext(ctx context.Context, env environment.Environment, progress io.Writer, path string, manifest chan<- string) StagingContext {
|
||||
func NewStagingContext(ctx context.Context, progress io.Writer, path string, manifest chan<- string) StagingContext {
|
||||
return &stagingContext{
|
||||
ctx: ctx,
|
||||
env: env,
|
||||
progress: progress,
|
||||
path: path,
|
||||
manifest: manifest,
|
||||
|
|
@ -79,10 +77,9 @@ func NewStagingContext(ctx context.Context, env environment.Environment, progres
|
|||
// stagingContext implements [components.StagingContext]
|
||||
type stagingContext struct {
|
||||
ctx context.Context
|
||||
env environment.Environment // environment
|
||||
progress io.Writer // writer to direct progress to
|
||||
path string // path to send files to
|
||||
manifest chan<- string // channel the manifest is sent to
|
||||
progress io.Writer // writer to direct progress to
|
||||
path string // path to send files to
|
||||
manifest chan<- string // channel the manifest is sent to
|
||||
}
|
||||
|
||||
func (bc *stagingContext) sendPath(path string) {
|
||||
|
|
|
|||
|
|
@ -6,7 +6,6 @@ import (
|
|||
"strings"
|
||||
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/config"
|
||||
"github.com/FAU-CDI/wisski-distillery/pkg/environment"
|
||||
)
|
||||
|
||||
// Components represents a logical subsystem of the distillery.
|
||||
|
|
@ -64,6 +63,5 @@ func (cb Base) ID() string {
|
|||
// 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
|
||||
Config *config.Config // the configuration of the distillery
|
||||
}
|
||||
|
|
|
|||
|
|
@ -94,7 +94,6 @@ func (backup *Backup) run(ctx context.Context, progress io.Writer, exporter *Exp
|
|||
return bc.Backup(
|
||||
component.NewStagingContext(
|
||||
ctx,
|
||||
exporter.Environment,
|
||||
writer,
|
||||
filepath.Join(backup.Description.Dest, bc.BackupName()),
|
||||
manifest,
|
||||
|
|
|
|||
|
|
@ -147,7 +147,7 @@ func (exporter *Exporter) MakeExport(ctx context.Context, progress io.Writer, ta
|
|||
st.Start()
|
||||
defer st.Stop()
|
||||
|
||||
count, err = targz.Package(exporter.Environment, archivePath, stagingDir, func(dst, src string) {
|
||||
count, err = targz.Package(archivePath, stagingDir, func(dst, src string) {
|
||||
st.Set(0, dst)
|
||||
})
|
||||
|
||||
|
|
|
|||
|
|
@ -124,7 +124,6 @@ func (snapshot *Snapshot) makeParts(ctx context.Context, progress io.Writer, sna
|
|||
instance.Instance,
|
||||
component.NewStagingContext(
|
||||
ctx,
|
||||
snapshots.Environment,
|
||||
writer,
|
||||
filepath.Join(snapshot.Description.Dest, sc.SnapshotName()),
|
||||
manifest,
|
||||
|
|
|
|||
|
|
@ -3,8 +3,6 @@ package component
|
|||
import (
|
||||
"context"
|
||||
"io"
|
||||
|
||||
"github.com/FAU-CDI/wisski-distillery/pkg/environment"
|
||||
)
|
||||
|
||||
// Installable implements an installable component.
|
||||
|
|
@ -18,7 +16,7 @@ type Installable interface {
|
|||
// Stack can be used to gain access to the "docker compose" stack.
|
||||
//
|
||||
// This should internally call [ComponentBase.MakeStack]
|
||||
Stack(env environment.Environment) StackWithResources
|
||||
Stack() StackWithResources
|
||||
|
||||
// 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.
|
||||
|
|
@ -26,8 +24,7 @@ type Installable interface {
|
|||
}
|
||||
|
||||
// MakeStack registers the Installable as a stack
|
||||
func MakeStack(component Installable, env environment.Environment, stack StackWithResources) StackWithResources {
|
||||
stack.Env = env
|
||||
func MakeStack(component Installable, stack StackWithResources) StackWithResources {
|
||||
stack.Dir = component.Path()
|
||||
return stack
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ var runtimeResources embed.FS
|
|||
|
||||
// Update installs or updates runtime components needed by this component.
|
||||
func (instances *Instances) Update(ctx context.Context, progress io.Writer) error {
|
||||
err := unpack.InstallDir(instances.Still.Environment, instances.Config.Paths.RuntimeDir(), "runtime", runtimeResources, func(dst, src string) {
|
||||
err := unpack.InstallDir(instances.Config.Paths.RuntimeDir(), "runtime", runtimeResources, func(dst, src string) {
|
||||
logging.ProgressF(progress, ctx, "[copy] %s\n", dst)
|
||||
})
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -9,7 +9,6 @@ import (
|
|||
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/bootstrap"
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/dis/component"
|
||||
"github.com/FAU-CDI/wisski-distillery/pkg/environment"
|
||||
)
|
||||
|
||||
func (control Server) Path() string {
|
||||
|
|
@ -19,8 +18,8 @@ func (control Server) Path() string {
|
|||
//go:embed all:server server.env
|
||||
var resources embed.FS
|
||||
|
||||
func (server *Server) Stack(env environment.Environment) component.StackWithResources {
|
||||
return component.MakeStack(server, env, component.StackWithResources{
|
||||
func (server *Server) Stack() component.StackWithResources {
|
||||
return component.MakeStack(server, component.StackWithResources{
|
||||
Resources: resources,
|
||||
ContextPath: "server",
|
||||
EnvPath: "server.env",
|
||||
|
|
@ -44,12 +43,12 @@ func (server *Server) Stack(env environment.Environment) component.StackWithReso
|
|||
}
|
||||
|
||||
// Trigger triggers the active cron run to immediatly invoke cron.
|
||||
func (server *Server) Trigger(ctx context.Context, env environment.Environment) error {
|
||||
return server.Stack(env).Kill(ctx, io.Discard, "control", syscall.SIGHUP)
|
||||
func (server *Server) Trigger(ctx context.Context) error {
|
||||
return server.Stack().Kill(ctx, io.Discard, "control", syscall.SIGHUP)
|
||||
}
|
||||
|
||||
func (server *Server) Context(parent component.InstallationContext) component.InstallationContext {
|
||||
return component.InstallationContext{
|
||||
bootstrap.Executable: server.Config.Paths.CurrentExecutable(server.Environment), // TODO: Does this make sense?
|
||||
bootstrap.Executable: server.Config.Paths.CurrentExecutable(), // TODO: Does this make sense?
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,6 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/dis/component"
|
||||
"github.com/FAU-CDI/wisski-distillery/pkg/environment"
|
||||
)
|
||||
|
||||
type Solr struct {
|
||||
|
|
@ -33,8 +32,8 @@ func (*Solr) Context(parent component.InstallationContext) component.Installatio
|
|||
//go:embed solr.env
|
||||
var resources embed.FS
|
||||
|
||||
func (solr *Solr) Stack(env environment.Environment) component.StackWithResources {
|
||||
return component.MakeStack(solr, env, component.StackWithResources{
|
||||
func (solr *Solr) Stack() component.StackWithResources {
|
||||
return component.MakeStack(solr, component.StackWithResources{
|
||||
Resources: resources,
|
||||
ContextPath: "solr",
|
||||
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ func (*SQL) BackupName() string {
|
|||
// Backup makes a backup of all SQL databases into the path dest.
|
||||
func (sql *SQL) Backup(scontext component.StagingContext) error {
|
||||
return scontext.AddFile("", func(ctx context.Context, file io.Writer) error {
|
||||
code := sql.Stack(sql.Environment).Exec(ctx, stream.NonInteractive(scontext.Progress()), "sql", "mysqldump", "--all-databases")()
|
||||
code := sql.Stack().Exec(ctx, stream.NonInteractive(scontext.Progress()), "sql", "mysqldump", "--all-databases")()
|
||||
if code != 0 {
|
||||
return errSQLBackup
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ func (sql *SQL) Snapshot(wisski models.Instance, scontext component.StagingConte
|
|||
|
||||
// SnapshotDB makes a backup of the sql database into dest.
|
||||
func (sql *SQL) SnapshotDB(ctx context.Context, progress io.Writer, dest io.Writer, database string) error {
|
||||
code := sql.Stack(sql.Environment).Exec(ctx, stream.NonInteractive(progress), "sql", "mysqldump", "--databases", database)()
|
||||
code := sql.Stack().Exec(ctx, stream.NonInteractive(progress), "sql", "mysqldump", "--databases", database)()
|
||||
if code != 0 {
|
||||
return errSQLBackup
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,6 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/dis/component"
|
||||
"github.com/FAU-CDI/wisski-distillery/pkg/environment"
|
||||
"github.com/FAU-CDI/wisski-distillery/pkg/fsx"
|
||||
"github.com/tkw1536/pkglib/lazy"
|
||||
)
|
||||
|
|
@ -43,8 +42,8 @@ func (*SQL) Context(parent component.InstallationContext) component.Installation
|
|||
//go:embed sql.env
|
||||
var resources embed.FS
|
||||
|
||||
func (sql *SQL) Stack(env environment.Environment) component.StackWithResources {
|
||||
return component.MakeStack(sql, env, component.StackWithResources{
|
||||
func (sql *SQL) Stack() component.StackWithResources {
|
||||
return component.MakeStack(sql, component.StackWithResources{
|
||||
Resources: resources,
|
||||
ContextPath: "sql",
|
||||
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ import (
|
|||
//
|
||||
// NOTE(twiesing): This command should not be used to connect to the database or execute queries except in known situations.
|
||||
func (sql *SQL) Shell(ctx context.Context, io stream.IOStream, argv ...string) int {
|
||||
return sql.Stack(sql.Environment).Exec(ctx, io, "sql", "mysql", argv...)()
|
||||
return sql.Stack().Exec(ctx, io, "sql", "mysql", argv...)()
|
||||
}
|
||||
|
||||
// unsafeWaitShell waits for a connection via the database shell to succeed
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@ import (
|
|||
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/bootstrap"
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/dis/component"
|
||||
"github.com/FAU-CDI/wisski-distillery/pkg/environment"
|
||||
)
|
||||
|
||||
func (ssh SSH2) Path() string {
|
||||
|
|
@ -17,8 +16,8 @@ func (ssh SSH2) Path() string {
|
|||
//go:embed all:ssh2 ssh2.env
|
||||
var resources embed.FS
|
||||
|
||||
func (ssh *SSH2) Stack(env environment.Environment) component.StackWithResources {
|
||||
stt := component.MakeStack(ssh, env, component.StackWithResources{
|
||||
func (ssh *SSH2) Stack() component.StackWithResources {
|
||||
stt := component.MakeStack(ssh, component.StackWithResources{
|
||||
Resources: resources,
|
||||
ContextPath: "ssh2",
|
||||
EnvPath: "ssh2.env",
|
||||
|
|
@ -44,6 +43,6 @@ func (ssh *SSH2) Stack(env environment.Environment) component.StackWithResources
|
|||
|
||||
func (ssh SSH2) Context(parent component.InstallationContext) component.InstallationContext {
|
||||
return component.InstallationContext{
|
||||
bootstrap.Executable: ssh.Config.Paths.CurrentExecutable(ssh.Environment), // TODO: Does this make sense?
|
||||
bootstrap.Executable: ssh.Config.Paths.CurrentExecutable(), // TODO: Does this make sense?
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,7 +9,6 @@ import (
|
|||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/FAU-CDI/wisski-distillery/pkg/environment"
|
||||
"github.com/FAU-CDI/wisski-distillery/pkg/execx"
|
||||
"github.com/FAU-CDI/wisski-distillery/pkg/fsx"
|
||||
"github.com/FAU-CDI/wisski-distillery/pkg/logging"
|
||||
|
|
@ -27,7 +26,6 @@ import (
|
|||
type Stack struct {
|
||||
Dir string // Directory this Stack is located in
|
||||
|
||||
Env environment.Environment
|
||||
DockerExecutable string // Path to the native docker executable to use
|
||||
}
|
||||
|
||||
|
|
@ -210,11 +208,9 @@ type InstallationContext map[string]string
|
|||
// Installation is non-interactive, but will provide debugging output onto io.
|
||||
// InstallationContext
|
||||
func (is StackWithResources) Install(ctx context.Context, progress io.Writer, context InstallationContext) error {
|
||||
env := is.Stack.Env
|
||||
if is.ContextPath != "" {
|
||||
// setup the base files
|
||||
if err := unpack.InstallDir(
|
||||
env,
|
||||
is.Dir,
|
||||
is.ContextPath,
|
||||
is.Resources,
|
||||
|
|
@ -231,7 +227,6 @@ func (is StackWithResources) Install(ctx context.Context, progress io.Writer, co
|
|||
if is.EnvPath != "" && is.EnvContext != nil {
|
||||
logging.ProgressF(progress, ctx, "[config] %s\n", envDest)
|
||||
if err := unpack.InstallTemplate(
|
||||
env,
|
||||
envDest,
|
||||
is.EnvContext,
|
||||
is.EnvPath,
|
||||
|
|
|
|||
|
|
@ -6,7 +6,6 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/dis/component"
|
||||
"github.com/FAU-CDI/wisski-distillery/pkg/environment"
|
||||
)
|
||||
|
||||
type Triplestore struct {
|
||||
|
|
@ -36,8 +35,8 @@ func (Triplestore) Context(parent component.InstallationContext) component.Insta
|
|||
//go:embed triplestore.env
|
||||
var resources embed.FS
|
||||
|
||||
func (ts *Triplestore) Stack(env environment.Environment) component.StackWithResources {
|
||||
return component.MakeStack(ts, env, component.StackWithResources{
|
||||
func (ts *Triplestore) Stack() component.StackWithResources {
|
||||
return component.MakeStack(ts, component.StackWithResources{
|
||||
Resources: resources,
|
||||
ContextPath: "triplestore",
|
||||
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@ import (
|
|||
"path/filepath"
|
||||
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/dis/component"
|
||||
"github.com/FAU-CDI/wisski-distillery/pkg/environment"
|
||||
)
|
||||
|
||||
// Web implements the ingress gateway for the distillery.
|
||||
|
|
@ -27,11 +26,11 @@ func (*Web) Context(parent component.InstallationContext) component.Installation
|
|||
return parent
|
||||
}
|
||||
|
||||
func (web Web) Stack(env environment.Environment) component.StackWithResources {
|
||||
func (web Web) Stack() component.StackWithResources {
|
||||
if web.Config.HTTP.HTTPSEnabled() {
|
||||
return web.stackHTTPS(env)
|
||||
return web.stackHTTPS()
|
||||
} else {
|
||||
return web.stackHTTP(env)
|
||||
return web.stackHTTP()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -39,8 +38,8 @@ func (web Web) Stack(env environment.Environment) component.StackWithResources {
|
|||
//go:embed web.env
|
||||
var httpsResources embed.FS
|
||||
|
||||
func (web *Web) stackHTTPS(env environment.Environment) component.StackWithResources {
|
||||
return component.MakeStack(web, env, component.StackWithResources{
|
||||
func (web *Web) stackHTTPS() component.StackWithResources {
|
||||
return component.MakeStack(web, component.StackWithResources{
|
||||
Resources: httpsResources,
|
||||
ContextPath: "web-https",
|
||||
EnvPath: "web.env",
|
||||
|
|
@ -58,8 +57,8 @@ func (web *Web) stackHTTPS(env environment.Environment) component.StackWithResou
|
|||
//go:embed web.env
|
||||
var httpResources embed.FS
|
||||
|
||||
func (web *Web) stackHTTP(env environment.Environment) component.StackWithResources {
|
||||
return component.MakeStack(web, env, component.StackWithResources{
|
||||
func (web *Web) stackHTTP() component.StackWithResources {
|
||||
return component.MakeStack(web, component.StackWithResources{
|
||||
Resources: httpResources,
|
||||
ContextPath: "web-http",
|
||||
EnvPath: "web.env",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue