wisski-cloud-distillery/internal/dis/component/web/web.go
Tom 588cb7ebaa 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.
2023-07-14 14:06:10 +02:00

59 lines
1.3 KiB
Go

package web
import (
"bytes"
"io"
"path/filepath"
"github.com/FAU-CDI/wisski-distillery/internal/dis/component"
_ "embed"
)
// Web implements the ingress gateway for the distillery.
//
// It consists of an nginx docker container and an optional letsencrypt container.
type Web struct {
component.Base
}
var (
_ component.Installable = (*Web)(nil)
)
func (web *Web) Path() string {
return filepath.Join(web.Still.Config.Paths.Root, "core", "web")
}
func (*Web) Context(parent component.InstallationContext) component.InstallationContext {
return parent
}
//go:embed docker-compose-http.yml
var dockerComposeHTTP []byte
//go:embed docker-compose-https.yml
var dockerComposeHTTPS []byte
func (web *Web) Stack() component.StackWithResources {
var stack component.StackWithResources
stack.EnvContext = map[string]string{
"DOCKER_NETWORK_NAME": web.Config.Docker.Network(),
"CERT_EMAIL": web.Config.HTTP.CertbotEmail,
}
if web.Config.HTTP.HTTPSEnabled() {
stack.ReadComposeFile = func() (io.Reader, error) {
return bytes.NewReader(dockerComposeHTTPS), nil
}
stack.TouchFilesPerm = 0600
stack.TouchFiles = []string{"acme.json"}
} else {
stack.ReadComposeFile = func() (io.Reader, error) {
return bytes.NewReader(dockerComposeHTTP), nil
}
}
return component.MakeStack(web, stack)
}