stack: Do not use templates for env files
This commit removes the templating logic for writing .env files. Instead it simply writes a key-value directory directly to the destined file.
This commit is contained in:
parent
46b16e5700
commit
588cb7ebaa
22 changed files with 180 additions and 121 deletions
|
|
@ -1 +0,0 @@
|
|||
DOCKER_NETWORK_NAME=${DOCKER_NETWORK_NAME}
|
||||
|
|
@ -2,13 +2,14 @@ package binder
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"embed"
|
||||
"io"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/dis/component"
|
||||
"github.com/tkw1536/pkglib/yamlx"
|
||||
"gopkg.in/yaml.v3"
|
||||
|
||||
_ "embed"
|
||||
)
|
||||
|
||||
type Binder struct {
|
||||
|
|
@ -66,13 +67,8 @@ func (binder *Binder) buildYML() ([]byte, error) {
|
|||
return yaml.Marshal(dockerCompose)
|
||||
}
|
||||
|
||||
//go:embed binder.env
|
||||
var resources embed.FS
|
||||
|
||||
func (binder *Binder) Stack() component.StackWithResources {
|
||||
return component.MakeStack(binder, component.StackWithResources{
|
||||
Resources: resources,
|
||||
EnvPath: "binder.env",
|
||||
ReadComposeFile: func() (io.Reader, error) {
|
||||
data, err := binder.buildYML()
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -1,11 +0,0 @@
|
|||
HOST_RULE=${HOST_RULE}
|
||||
|
||||
CONFIG_PATH=${CONFIG_PATH}
|
||||
DEPLOY_ROOT=${DEPLOY_ROOT}
|
||||
SELF_OVERRIDES_FILE=${SELF_OVERRIDES_FILE}
|
||||
SELF_RESOLVER_BLOCK_FILE=${SELF_RESOLVER_BLOCK_FILE}
|
||||
|
||||
DOCKER_NETWORK_NAME=${DOCKER_NETWORK_NAME}
|
||||
HTTPS_ENABLED=${HTTPS_ENABLED}
|
||||
|
||||
CUSTOM_ASSETS_PATH=${CUSTOM_ASSETS_PATH}
|
||||
|
|
@ -15,14 +15,13 @@ func (control Server) Path() string {
|
|||
return filepath.Join(control.Still.Config.Paths.Root, "core", "dis")
|
||||
}
|
||||
|
||||
//go:embed all:server server.env
|
||||
//go:embed all:server
|
||||
var resources embed.FS
|
||||
|
||||
func (server *Server) Stack() component.StackWithResources {
|
||||
return component.MakeStack(server, component.StackWithResources{
|
||||
Resources: resources,
|
||||
ContextPath: "server",
|
||||
EnvPath: "server.env",
|
||||
|
||||
EnvContext: map[string]string{
|
||||
"DOCKER_NETWORK_NAME": server.Config.Docker.Network(),
|
||||
|
|
|
|||
|
|
@ -1 +0,0 @@
|
|||
DOCKER_NETWORK_NAME=${DOCKER_NETWORK_NAME}
|
||||
|
|
@ -29,7 +29,6 @@ func (*Solr) Context(parent component.InstallationContext) component.Installatio
|
|||
}
|
||||
|
||||
//go:embed all:solr
|
||||
//go:embed solr.env
|
||||
var resources embed.FS
|
||||
|
||||
func (solr *Solr) Stack() component.StackWithResources {
|
||||
|
|
@ -37,7 +36,6 @@ func (solr *Solr) Stack() component.StackWithResources {
|
|||
Resources: resources,
|
||||
ContextPath: "solr",
|
||||
|
||||
EnvPath: "solr.env",
|
||||
EnvContext: map[string]string{
|
||||
"DOCKER_NETWORK_NAME": solr.Config.Docker.Network(),
|
||||
},
|
||||
|
|
|
|||
|
|
@ -1,2 +0,0 @@
|
|||
DOCKER_NETWORK_NAME=${DOCKER_NETWORK_NAME}
|
||||
HTTPS_ENABLED=${HTTPS_ENABLED}
|
||||
|
|
@ -37,7 +37,6 @@ func (*SQL) Context(parent component.InstallationContext) component.Installation
|
|||
}
|
||||
|
||||
//go:embed all:sql
|
||||
//go:embed sql.env
|
||||
var resources embed.FS
|
||||
|
||||
func (sql *SQL) Stack() component.StackWithResources {
|
||||
|
|
@ -45,7 +44,6 @@ func (sql *SQL) Stack() component.StackWithResources {
|
|||
Resources: resources,
|
||||
ContextPath: "sql",
|
||||
|
||||
EnvPath: "sql.env",
|
||||
EnvContext: map[string]string{
|
||||
"DOCKER_NETWORK_NAME": sql.Config.Docker.Network(),
|
||||
"HTTPS_ENABLED": sql.Config.HTTP.HTTPSEnabledEnv(),
|
||||
|
|
|
|||
|
|
@ -1,8 +0,0 @@
|
|||
HOST_RULE=${HOST_RULE}
|
||||
|
||||
CONFIG_PATH=${CONFIG_PATH}
|
||||
DEPLOY_ROOT=${DEPLOY_ROOT}
|
||||
SELF_OVERRIDES_FILE=${SELF_OVERRIDES_FILE}
|
||||
SELF_RESOLVER_BLOCK_FILE=${SELF_RESOLVER_BLOCK_FILE}
|
||||
|
||||
DOCKER_NETWORK_NAME=${DOCKER_NETWORK_NAME}
|
||||
|
|
@ -12,14 +12,13 @@ func (ssh *SSH2) Path() string {
|
|||
return filepath.Join(ssh.Still.Config.Paths.Root, "core", "ssh2")
|
||||
}
|
||||
|
||||
//go:embed all:ssh2 ssh2.env
|
||||
//go:embed all:ssh2
|
||||
var resources embed.FS
|
||||
|
||||
func (ssh *SSH2) Stack() component.StackWithResources {
|
||||
return component.MakeStack(ssh, component.StackWithResources{
|
||||
Resources: resources,
|
||||
ContextPath: "ssh2",
|
||||
EnvPath: "ssh2.env",
|
||||
|
||||
EnvContext: map[string]string{
|
||||
"DOCKER_NETWORK_NAME": ssh.Config.Docker.Network(),
|
||||
|
|
|
|||
|
|
@ -176,10 +176,12 @@ type StackWithResources struct {
|
|||
// These all refer to paths within the Resource filesystem.
|
||||
Resources fs.FS
|
||||
|
||||
ContextPath string // the 'docker compose' stack context. Can, but does not have to, contain 'docker-compose.yml'
|
||||
ContextPath string // the 'docker compose' stack context. Can, but does not have to, contain 'docker-compose.yml'
|
||||
|
||||
// TODO: Make this nicer to replace variables
|
||||
ReadComposeFile func() (io.Reader, error) // read the 'docker-compose.yml' (if not contained in context)
|
||||
|
||||
EnvPath string // the '.env' template, will be installed using [unpack.InstallTemplate].
|
||||
// EnvPath string // the '.env' template, will be installed using [unpack.InstallTemplate]. If empty, use new syntax
|
||||
EnvContext map[string]string // context when instantiating the '.env' template
|
||||
|
||||
CopyContextFiles []string // Files to copy from the installation context
|
||||
|
|
@ -253,14 +255,10 @@ func (is StackWithResources) Install(ctx context.Context, progress io.Writer, co
|
|||
|
||||
// configure .env
|
||||
envDest := filepath.Join(is.Dir, ".env")
|
||||
if is.EnvPath != "" && is.EnvContext != nil {
|
||||
if is.EnvContext != nil {
|
||||
fmt.Fprintf(progress, "[config] %s\n", envDest)
|
||||
if err := unpack.InstallTemplate(
|
||||
envDest,
|
||||
is.EnvContext,
|
||||
is.EnvPath,
|
||||
is.Resources,
|
||||
); err != nil {
|
||||
|
||||
if err := writeEnvFile(envDest, is.TouchFilesPerm, is.EnvContext); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
|
@ -319,3 +317,22 @@ func (is StackWithResources) Install(ctx context.Context, progress io.Writer, co
|
|||
|
||||
return nil
|
||||
}
|
||||
|
||||
// writeEnvFile writes an environment file
|
||||
func writeEnvFile(path string, perm fs.FileMode, variables map[string]string) error {
|
||||
// create the environment file
|
||||
file, err := umaskfree.Create(path, perm)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
// write the file!
|
||||
_, err = compose.WriteEnvFile(file, variables)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// and return nil
|
||||
return nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1 +0,0 @@
|
|||
DOCKER_NETWORK_NAME=${DOCKER_NETWORK_NAME}
|
||||
|
|
@ -32,7 +32,6 @@ func (Triplestore) Context(parent component.InstallationContext) component.Insta
|
|||
}
|
||||
|
||||
//go:embed all:triplestore
|
||||
//go:embed triplestore.env
|
||||
var resources embed.FS
|
||||
|
||||
func (ts *Triplestore) Stack() component.StackWithResources {
|
||||
|
|
@ -42,7 +41,6 @@ func (ts *Triplestore) Stack() component.StackWithResources {
|
|||
|
||||
CopyContextFiles: []string{"graphdb.zip"}, // TODO: Move into constant?
|
||||
|
||||
EnvPath: "triplestore.env",
|
||||
EnvContext: map[string]string{
|
||||
"DOCKER_NETWORK_NAME": ts.Config.Docker.Network(),
|
||||
},
|
||||
|
|
|
|||
|
|
@ -1,2 +0,0 @@
|
|||
DOCKER_NETWORK_NAME=${DOCKER_NETWORK_NAME}
|
||||
CERT_EMAIL=${CERT_EMAIL}
|
||||
|
|
@ -2,11 +2,12 @@ package web
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"embed"
|
||||
"io"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/dis/component"
|
||||
|
||||
_ "embed"
|
||||
)
|
||||
|
||||
// Web implements the ingress gateway for the distillery.
|
||||
|
|
@ -28,9 +29,6 @@ func (*Web) Context(parent component.InstallationContext) component.Installation
|
|||
return parent
|
||||
}
|
||||
|
||||
//go:embed web.env
|
||||
var webEnv embed.FS
|
||||
|
||||
//go:embed docker-compose-http.yml
|
||||
var dockerComposeHTTP []byte
|
||||
|
||||
|
|
@ -39,8 +37,6 @@ var dockerComposeHTTPS []byte
|
|||
|
||||
func (web *Web) Stack() component.StackWithResources {
|
||||
var stack component.StackWithResources
|
||||
stack.Resources = webEnv
|
||||
stack.EnvPath = "web.env"
|
||||
|
||||
stack.EnvContext = map[string]string{
|
||||
"DOCKER_NETWORK_NAME": web.Config.Docker.Network(),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue