mirror of
https://github.com/Icinga/docker-icingaweb2.git
synced 2025-10-23 21:11:00 +02:00
entrypoint/: let Icinga Web render its config files, not a Go lib
It knows best what they have to look like to be interpreted correctly. Especially the proper quoting of special characters is important.
This commit is contained in:
parent
60579f5c9d
commit
05c135f2f7
16
entrypoint/db-init/application/clicommands/ConfigCommand.php
Normal file
16
entrypoint/db-init/application/clicommands/ConfigCommand.php
Normal file
@ -0,0 +1,16 @@
|
||||
<?php
|
||||
// Icinga Web 2 Docker image | (c) 2024 Icinga GmbH | GPLv2+
|
||||
|
||||
namespace Icinga\Module\Dockerentrypoint\Clicommands;
|
||||
|
||||
use Icinga\Application\Config;
|
||||
use Icinga\Cli\Command;
|
||||
use Icinga\Util\Json;
|
||||
|
||||
class ConfigCommand extends Command
|
||||
{
|
||||
public function renderAction(): void
|
||||
{
|
||||
echo Config::fromArray(Json::decode(file_get_contents('php://stdin'), true));
|
||||
}
|
||||
}
|
@ -1,8 +1,3 @@
|
||||
module entrypoint
|
||||
|
||||
go 1.14
|
||||
|
||||
require (
|
||||
github.com/go-ini/ini v1.67.0
|
||||
github.com/stretchr/testify v1.7.0 // indirect
|
||||
)
|
||||
|
@ -1,13 +0,0 @@
|
||||
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/go-ini/ini v1.67.0 h1:z6ZrTEZqSWOTyH2FlglNbNgARyHG8oLW9gMELqKr06A=
|
||||
github.com/go-ini/ini v1.67.0/go.mod h1:ByCAeIL28uOIIG0E3PJtZPDL8WnHpFKFOtgjp+3Ies8=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
|
||||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
@ -7,7 +7,6 @@ import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/go-ini/ini"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"os/exec"
|
||||
@ -47,9 +46,18 @@ func entrypoint() error {
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
enMod := path.Join(enModsDir, "dockerentrypoint")
|
||||
if errSl := os.Symlink("/entrypoint-db-init", enMod); errSl != nil && !os.IsExist(errSl) {
|
||||
return errSl
|
||||
}
|
||||
|
||||
defer os.Remove(enMod)
|
||||
}
|
||||
|
||||
logf("debug", "Translating env vars to .ini config")
|
||||
|
||||
cfgs := map[string]*ini.File{}
|
||||
cfgs := map[string]map[string]map[string]string{}
|
||||
var enabledModules map[string]struct{} = nil
|
||||
passwords := map[string]map[string]string{}
|
||||
|
||||
@ -91,16 +99,19 @@ func entrypoint() error {
|
||||
cfg, ok := cfgs[file]
|
||||
|
||||
if !ok {
|
||||
cfg = ini.Empty()
|
||||
cfg = map[string]map[string]string{}
|
||||
cfgs[file] = cfg
|
||||
}
|
||||
|
||||
_, errNK := cfg.Section(directive[len(directive)-2]).NewKey(
|
||||
directive[len(directive)-1], kv[1],
|
||||
)
|
||||
if errNK != nil {
|
||||
return errNK
|
||||
sectionName := directive[len(directive)-2]
|
||||
section, hasSection := cfg[sectionName]
|
||||
|
||||
if !hasSection {
|
||||
section = map[string]string{}
|
||||
cfg[sectionName] = section
|
||||
}
|
||||
|
||||
section[directive[len(directive)-1]] = kv[1]
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -116,7 +127,23 @@ func entrypoint() error {
|
||||
return errMA
|
||||
}
|
||||
|
||||
if errST := cfg.SaveTo(file); errST != nil {
|
||||
jsn := &bytes.Buffer{}
|
||||
ini := &bytes.Buffer{}
|
||||
|
||||
if err := json.NewEncoder(jsn).Encode(cfg); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
cmd := exec.Command("icingacli", "dockerentrypoint", "config", "render")
|
||||
cmd.Stdin = jsn
|
||||
cmd.Stdout = ini
|
||||
cmd.Stderr = os.Stderr
|
||||
|
||||
if errRn := cmd.Run(); errRn != nil {
|
||||
return errRn
|
||||
}
|
||||
|
||||
if errST := os.WriteFile(file, ini.Bytes(), 0o640); errST != nil {
|
||||
return errST
|
||||
}
|
||||
}
|
||||
@ -129,6 +156,8 @@ func entrypoint() error {
|
||||
return errRD
|
||||
}
|
||||
|
||||
enabledModules["dockerentrypoint"] = struct{}{}
|
||||
|
||||
for _, mod := range mods {
|
||||
mod := mod.Name()
|
||||
if _, ok := enabledModules[mod]; ok {
|
||||
@ -175,15 +204,6 @@ func entrypoint() error {
|
||||
func initDb(passwords map[string]map[string]string) error {
|
||||
logf("info", "Checking database resources used as backends")
|
||||
|
||||
{
|
||||
enMod := path.Join(enModsDir, "dockerentrypoint")
|
||||
if errSl := os.Symlink("/entrypoint-db-init", enMod); errSl != nil {
|
||||
return errSl
|
||||
}
|
||||
|
||||
defer os.Remove(enMod)
|
||||
}
|
||||
|
||||
{
|
||||
enMod := path.Join(enModsDir, "setup")
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user