diff --git a/cmd/system_update.go b/cmd/system_update.go index b338485..e11819f 100644 --- a/cmd/system_update.go +++ b/cmd/system_update.go @@ -72,6 +72,7 @@ func (si systemupdate) Run(context wisski_distillery.Context) error { dis.Instances().Path(), dis.Exporter().StagingPath(), dis.Exporter().ArchivePath(), + dis.Custom().CustomAssetsPath(), } { context.Println(d) if err := dis.Still.Environment.MkdirAll(d, environment.DefaultDirPerm); err != nil { diff --git a/internal/dis/component/control/control.env b/internal/dis/component/control/control.env index 2b65aa7..6a42245 100644 --- a/internal/dis/component/control/control.env +++ b/internal/dis/component/control/control.env @@ -7,4 +7,6 @@ SELF_OVERRIDES_FILE=${SELF_OVERRIDES_FILE} SELF_RESOLVER_BLOCK_FILE=${SELF_RESOLVER_BLOCK_FILE} DOCKER_NETWORK_NAME=${DOCKER_NETWORK_NAME} -HTTPS_ENABLED=${HTTPS_ENABLED} \ No newline at end of file +HTTPS_ENABLED=${HTTPS_ENABLED} + +CUSTOM_ASSETS_PATH=${CUSTOM_ASSETS_PATH} \ No newline at end of file diff --git a/internal/dis/component/control/control.go b/internal/dis/component/control/control.go index 516a9a1..9dd9c12 100644 --- a/internal/dis/component/control/control.go +++ b/internal/dis/component/control/control.go @@ -9,6 +9,7 @@ import ( "github.com/FAU-CDI/wisski-distillery/internal/bootstrap" "github.com/FAU-CDI/wisski-distillery/internal/dis/component" + "github.com/FAU-CDI/wisski-distillery/internal/dis/component/control/static/custom" "github.com/FAU-CDI/wisski-distillery/pkg/environment" ) @@ -18,6 +19,8 @@ type Control struct { Dependencies struct { Routeables []component.Routeable Cronables []component.Cronable + + Custom *custom.Custom } } @@ -49,6 +52,8 @@ func (control *Control) Stack(env environment.Environment) component.StackWithRe "GLOBAL_AUTHORIZED_KEYS_FILE": control.Config.GlobalAuthorizedKeysFile, "SELF_OVERRIDES_FILE": control.Config.SelfOverridesFile, "SELF_RESOLVER_BLOCK_FILE": control.Config.SelfResolverBlockFile, + + "CUSTOM_ASSETS_PATH": control.Dependencies.Custom.CustomAssetsPath(), }, CopyContextFiles: []string{bootstrap.Executable}, diff --git a/internal/dis/component/control/control/docker-compose.yml b/internal/dis/component/control/control/docker-compose.yml index 83c31ed..b1f15c0 100644 --- a/internal/dis/component/control/control/docker-compose.yml +++ b/internal/dis/component/control/control/docker-compose.yml @@ -28,6 +28,7 @@ services: - "${GLOBAL_AUTHORIZED_KEYS_FILE}:${GLOBAL_AUTHORIZED_KEYS_FILE}:ro" - "${SELF_OVERRIDES_FILE}:${SELF_OVERRIDES_FILE}:ro" - "${SELF_RESOLVER_BLOCK_FILE}:${SELF_RESOLVER_BLOCK_FILE}:ro" + - "${CUSTOM_ASSETS_PATH}:${CUSTOM_ASSETS_PATH}:ro" networks: default: diff --git a/internal/dis/component/control/static/custom/assets.go b/internal/dis/component/control/static/custom/assets.go new file mode 100644 index 0000000..7efe957 --- /dev/null +++ b/internal/dis/component/control/static/custom/assets.go @@ -0,0 +1,22 @@ +package custom + +import ( + "path/filepath" + + "github.com/FAU-CDI/wisski-distillery/internal/dis/component" +) + +// CustomAssetsPath is the path custom assets are stored at +func (custom *Custom) CustomAssetsPath() string { + return filepath.Join(custom.Config.DeployRoot, "core", "assets") +} + +func (custom *Custom) FooterPath() string { + return filepath.Join(custom.CustomAssetsPath(), "footer.html") +} + +func (custom *Custom) BackupName() string { return "custom" } + +func (custom *Custom) Backup(context component.StagingContext) error { + return context.CopyDirectory("", custom.CustomAssetsPath()) +} diff --git a/internal/dis/component/control/static/custom/custom.go b/internal/dis/component/control/static/custom/custom.go index 5f1473c..a745c32 100644 --- a/internal/dis/component/control/static/custom/custom.go +++ b/internal/dis/component/control/static/custom/custom.go @@ -1,6 +1,8 @@ package custom -import "github.com/FAU-CDI/wisski-distillery/internal/dis/component" +import ( + "github.com/FAU-CDI/wisski-distillery/internal/dis/component" +) // Custom implements theme and page customization. type Custom struct { @@ -9,3 +11,7 @@ type Custom struct { // nothing yet } } + +var ( + _ component.Backupable = (*Custom)(nil) +) diff --git a/internal/dis/component/control/static/custom/template.go b/internal/dis/component/control/static/custom/template.go index 9544d9b..52d076f 100644 --- a/internal/dis/component/control/static/custom/template.go +++ b/internal/dis/component/control/static/custom/template.go @@ -3,6 +3,9 @@ package custom import ( _ "embed" "html/template" + "text/template/parse" + + "github.com/FAU-CDI/wisski-distillery/pkg/environment" ) const footerName = "footer" @@ -14,9 +17,26 @@ var defaultTemplate = template.Must(template.New("footer.html").Parse(defaultTem // Template creates a copy of template with shared template parts updated accordingly. // Any template using this should use one of the template contexts in this package. func (custom *Custom) Template(tpl *template.Template) *template.Template { - tree := defaultTemplate.Tree.Copy() + tree := custom.footerTemplate() clone := template.Must(tpl.Clone()) // create a clone of the template template.Must(clone.AddParseTree(footerName, tree)) // add the parse tree to it return clone // and return the tree } + +// footerTemplate returns a new copy of the footer template +func (custom *Custom) footerTemplate() *parse.Tree { + footer, err := (func() (*template.Template, error) { + data, err := environment.ReadFile(custom.Environment, custom.FooterPath()) + if err != nil { + return nil, err + } + return template.New("footer.html").Parse(string(data)) + })() + + if err != nil { + return defaultTemplate.Tree.Copy() + } + + return footer.Tree +}