Add local.settings.php to every instance

This commit adds a new file 'local.settings.php' to each distillery
instance. This file can be used to automatically edit global distillery
settings.
This commit is contained in:
Tom Wiesing 2024-04-01 16:41:11 +02:00
parent 6eab3ac311
commit 24ff81f7cd
No known key found for this signature in database
13 changed files with 98 additions and 42 deletions

View file

@ -22,4 +22,7 @@ const (
OntologyDirectory = SitesDirectory + "/default/files/ontology"
SitesDirectory = WebDirectory + "/sites"
WissKIDirectory = WebDirectory + "/modules/contrib/wisski"
LocalSettingsPath = "/settings/local.php"
GlobalSettingsPath = "/settings/global.php"
)

View file

@ -1,3 +1,4 @@
# THIS FILE IS GENERATED AUTOMATICALLY. DO NOT EDIT.
version: "3.7"
services:
@ -43,6 +44,7 @@ services:
- ${DATA_PATH}/data:/var/www/data:rw
- ${DATA_PATH}/home:/var/www:rw
- ${DATA_PATH}/hostkeys:/ssh/hostkeys:rw
- ${LOCAL_SETTINGS_PATH}:${LOCAL_SETTINGS_MOUNT}:ro
networks:
default:

View file

@ -0,0 +1,16 @@
<?php
// Use this file to manually tweak setttings of this instance in an update-agnostic way.
// This file will not be updated by future distillery updates.
//
// The settings.php file contains settings in the following order:
//
// - settings generated by the drupal installer
// - global distillery settings files
// - distillery generated configuration files
// - this file
//
// Because of caching, changes may require an instance restart to take effect.
// // e.g. to turn on verbose logging, uncomment the following line:
// $config["system.logging"]["error_level"] = "verbose";

View file

@ -23,7 +23,7 @@ import (
// Provision applies defaults to flags, to ensure some values are set
func (manager *Manager) Provision(ctx context.Context, progress io.Writer, system models.System, flags Profile) error {
// Force building and applying the system!
if err := manager.dependencies.SystemManager.Apply(ctx, progress, system, false); err != nil {
if err := manager.dependencies.SystemManager.ApplyInitial(ctx, progress, system); err != nil {
return err
}
@ -130,7 +130,7 @@ func (provision *Manager) bootstrap(ctx context.Context, progress io.Writer, fla
// Rebuild the settings file
logging.LogMessage(progress, "Rebuilding Settings")
{
if err := provision.dependencies.SystemManager.RebuildSettings(ctx, progress); err != nil {
if err := provision.dependencies.SystemManager.BuildSettings(ctx, progress); err != nil {
return err
}
}

View file

@ -4,12 +4,19 @@ import (
"embed"
"path/filepath"
_ "embed"
"github.com/FAU-CDI/wisski-distillery/internal/dis/component"
)
//go:embed all:barrel
var barrelResources embed.FS
const localSettingsName = "settings.local.php"
//go:embed local.settings.php
var localSettingsTemplate string
// Barrel returns a stack representing the running WissKI Instance
func (barrel *Barrel) Stack() component.StackWithResources {
return component.StackWithResources{
@ -20,6 +27,10 @@ func (barrel *Barrel) Stack() component.StackWithResources {
Resources: barrelResources,
ContextPath: filepath.Join("barrel"),
CreateFiles: map[string]string{
localSettingsName: localSettingsTemplate,
},
EnvContext: map[string]string{
"DOCKER_NETWORK_NAME": barrel.Malt.Config.Docker.Network(),
@ -31,6 +42,9 @@ func (barrel *Barrel) Stack() component.StackWithResources {
"DATA_PATH": filepath.Join(barrel.FilesystemBase, "data"),
"RUNTIME_DIR": barrel.Malt.Config.Paths.RuntimeDir(),
"LOCAL_SETTINGS_PATH": filepath.Join(barrel.FilesystemBase, localSettingsName),
"LOCAL_SETTINGS_MOUNT": LocalSettingsPath,
"BARREL_BASE_IMAGE": barrel.GetDockerBaseImage(),
"IIP_SERVER_ENABLED": barrel.GetIIPServerEnabled(),
"OPCACHE_MODE": barrel.OpCacheMode(),

View file

@ -7,8 +7,9 @@ import (
"github.com/FAU-CDI/wisski-distillery/pkg/logging"
)
// RebuildSettings (re-)configures settings.php for the provided running instance
func (smanager *SystemManager) RebuildSettings(ctx context.Context, progress io.Writer) (err error) {
// BuildSettings sets up global settings.php configuration settings.php for the provided running instance
// This doesn't need to be called manually.
func (smanager *SystemManager) BuildSettings(ctx context.Context, progress io.Writer) (err error) {
logging.LogMessage(progress, "Updating TRUSTED_HOST_PATTERNS in settings.php")
{
if err := smanager.dependencies.Settings.SetTrustedDomain(ctx, nil, smanager.Domain()); err != nil {

View file

@ -21,19 +21,33 @@ type SystemManager struct {
}
}
// Apply applies a specific system version to this barrel.
// If start is true, also starts the container.
func (smanager *SystemManager) Apply(ctx context.Context, progress io.Writer, system models.System, start bool) (err error) {
// setup the new docker image
smanager.Instance.System = system
// Apply applies the given system configuration to this instance and (re-)starts the system.
func (smanager *SystemManager) Apply(ctx context.Context, progress io.Writer, system models.System) (err error) {
if err := smanager.apply(ctx, progress, system, true); err != nil {
return err
}
// save in bookkeeping
if err := smanager.BuildSettings(ctx, progress); err != nil {
return err
}
return nil
}
// ApplyInitial builds the base image, but does not start it
func (smanager *SystemManager) ApplyInitial(ctx context.Context, progress io.Writer, system models.System) error {
return smanager.apply(ctx, progress, system, false)
}
// apply stores the new configuration and builds the base image
// start inidicates if the image should be started afterwards
func (smanager *SystemManager) apply(ctx context.Context, progress io.Writer, system models.System, start bool) error {
// store the new system configuration
smanager.Instance.System = system
if err := smanager.dependencies.Bookkeeping.Save(ctx); err != nil {
return err
}
// TODO: Apply Content-Security-Policy!
// and rebuild
// build and start the barrel
return smanager.dependencies.Barrel.Build(ctx, progress, start)
}