diff --git a/cmd/system_update.go b/cmd/system_update.go index 774b733..64567cc 100644 --- a/cmd/system_update.go +++ b/cmd/system_update.go @@ -135,18 +135,20 @@ func (si systemupdate) Run(context wisski_distillery.Context) (err error) { } } - // create the docker network + // create the docker networks { logging.LogMessage(context.Stderr, context.Context, "Configuring docker networks") - name := dis.Config.Docker.Network - id, existed, err := dis.Docker().CreateNetwork(context.Context, name) - if err != nil { - return errNetworkCreateFailed.Wrap(err) - } - if existed { - context.Printf("Network %s (id %s) already existed\n", name, id) - } else { - context.Printf("Network %s (id %s) created\n", name, id) + + for _, name := range dis.Config.Docker.Networks() { + id, existed, err := dis.Docker().CreateNetwork(context.Context, name) + if err != nil { + return errNetworkCreateFailed.Wrap(err) + } + if existed { + context.Printf("Network %s (id %s) already existed\n", name, id) + } else { + context.Printf("Network %s (id %s) created\n", name, id) + } } } diff --git a/internal/config/config.yml b/internal/config/config.yml index 458cda3..7dab9a4 100644 --- a/internal/config/config.yml +++ b/internal/config/config.yml @@ -45,7 +45,8 @@ theme: home: null docker: - # The name of the (global) docker network to run the distillery services in. + # The distillery uses several global docker networks. + # This determines the prefix to use for those networks. network: null # Configuration of the sql backend diff --git a/internal/config/docker.go b/internal/config/docker.go index bb8a699..420e321 100644 --- a/internal/config/docker.go +++ b/internal/config/docker.go @@ -1,6 +1,15 @@ package config type DockerConfig struct { - // name of docker network to use - Network string `yaml:"network" default:"distillery" validate:"nonempty"` + NetworkPrefix string `yaml:"network" default:"distillery" validate:"nonempty"` +} + +// Networks returns a list of all docker networks to be created for purposes of the distillery. +func (dc DockerConfig) Networks() []string { + return []string{dc.Network()} +} + +// Network returns the name of the default network to attach all docker containers to. +func (dc DockerConfig) Network() string { + return dc.NetworkPrefix } diff --git a/internal/config/template.go b/internal/config/template.go index 72b7f92..cfc841b 100644 --- a/internal/config/template.go +++ b/internal/config/template.go @@ -22,8 +22,8 @@ type Template struct { SQLAdminUsername string SQLAdminPassword string - DockerNetworkName string - SessionSecret string + DockerNetworkPrefix string + SessionSecret string } // SetDefaults sets defaults on the template @@ -58,12 +58,12 @@ func (tpl *Template) SetDefaults() (err error) { } } - if tpl.DockerNetworkName == "" { - tpl.DockerNetworkName, err = password.Generate(rand.Reader, 10, passwordx.Identifier) + if tpl.DockerNetworkPrefix == "" { + tpl.DockerNetworkPrefix, err = password.Generate(rand.Reader, 10, passwordx.Identifier) if err != nil { return err } - tpl.DockerNetworkName = `distillery-` + tpl.DockerNetworkName + tpl.DockerNetworkPrefix = `distillery-` + tpl.DockerNetworkPrefix } if tpl.SessionSecret == "" { @@ -93,7 +93,7 @@ func (tpl Template) Generate() Config { ExtraDomains: []string{}, }, Docker: DockerConfig{ - tpl.DockerNetworkName, + NetworkPrefix: tpl.DockerNetworkPrefix, }, SQL: SQLConfig{ DatabaseConfig: DatabaseConfig{ diff --git a/internal/dis/component/binder/binder.go b/internal/dis/component/binder/binder.go index 0c308dd..7545b0a 100644 --- a/internal/dis/component/binder/binder.go +++ b/internal/dis/component/binder/binder.go @@ -82,7 +82,7 @@ func (binder *Binder) Stack() component.StackWithResources { }, EnvContext: map[string]string{ - "DOCKER_NETWORK_NAME": binder.Config.Docker.Network, + "DOCKER_NETWORK_NAME": binder.Config.Docker.Network(), }, }) } diff --git a/internal/dis/component/server/stack.go b/internal/dis/component/server/stack.go index c0c0ea6..addfe6d 100644 --- a/internal/dis/component/server/stack.go +++ b/internal/dis/component/server/stack.go @@ -25,7 +25,7 @@ func (server *Server) Stack() component.StackWithResources { EnvPath: "server.env", EnvContext: map[string]string{ - "DOCKER_NETWORK_NAME": server.Config.Docker.Network, + "DOCKER_NETWORK_NAME": server.Config.Docker.Network(), "HOST_RULE": server.Config.HTTP.DefaultHostRule(), "HTTPS_ENABLED": server.Config.HTTP.HTTPSEnabledEnv(), diff --git a/internal/dis/component/solr/solr.go b/internal/dis/component/solr/solr.go index b2441a7..cb706a0 100644 --- a/internal/dis/component/solr/solr.go +++ b/internal/dis/component/solr/solr.go @@ -39,7 +39,7 @@ func (solr *Solr) Stack() component.StackWithResources { EnvPath: "solr.env", EnvContext: map[string]string{ - "DOCKER_NETWORK_NAME": solr.Config.Docker.Network, + "DOCKER_NETWORK_NAME": solr.Config.Docker.Network(), }, MakeDirs: []string{ diff --git a/internal/dis/component/sql/sql.go b/internal/dis/component/sql/sql.go index 22f0113..b5c6779 100644 --- a/internal/dis/component/sql/sql.go +++ b/internal/dis/component/sql/sql.go @@ -46,7 +46,7 @@ func (sql *SQL) Stack() component.StackWithResources { EnvPath: "sql.env", EnvContext: map[string]string{ - "DOCKER_NETWORK_NAME": sql.Config.Docker.Network, + "DOCKER_NETWORK_NAME": sql.Config.Docker.Network(), "HTTPS_ENABLED": sql.Config.HTTP.HTTPSEnabledEnv(), }, diff --git a/internal/dis/component/ssh2/stack.go b/internal/dis/component/ssh2/stack.go index 9a4e1df..fa7b82a 100644 --- a/internal/dis/component/ssh2/stack.go +++ b/internal/dis/component/ssh2/stack.go @@ -22,7 +22,7 @@ func (ssh *SSH2) Stack() component.StackWithResources { EnvPath: "ssh2.env", EnvContext: map[string]string{ - "DOCKER_NETWORK_NAME": ssh.Config.Docker.Network, + "DOCKER_NETWORK_NAME": ssh.Config.Docker.Network(), "HOST_RULE": ssh.Config.HTTP.DefaultHostRule(), "CONFIG_PATH": ssh.Config.ConfigPath, diff --git a/internal/dis/component/triplestore/triplestore.go b/internal/dis/component/triplestore/triplestore.go index 06de7ca..7094449 100644 --- a/internal/dis/component/triplestore/triplestore.go +++ b/internal/dis/component/triplestore/triplestore.go @@ -44,7 +44,7 @@ func (ts *Triplestore) Stack() component.StackWithResources { EnvPath: "triplestore.env", EnvContext: map[string]string{ - "DOCKER_NETWORK_NAME": ts.Config.Docker.Network, + "DOCKER_NETWORK_NAME": ts.Config.Docker.Network(), }, MakeDirs: []string{ diff --git a/internal/dis/component/web/web.go b/internal/dis/component/web/web.go index c3decf4..fd0ec84 100644 --- a/internal/dis/component/web/web.go +++ b/internal/dis/component/web/web.go @@ -43,7 +43,7 @@ func (web *Web) Stack() component.StackWithResources { stack.EnvPath = "web.env" stack.EnvContext = map[string]string{ - "DOCKER_NETWORK_NAME": web.Config.Docker.Network, + "DOCKER_NETWORK_NAME": web.Config.Docker.Network(), "CERT_EMAIL": web.Config.HTTP.CertbotEmail, } diff --git a/internal/wisski/ingredient/barrel/stack.go b/internal/wisski/ingredient/barrel/stack.go index aeb932c..20991ad 100644 --- a/internal/wisski/ingredient/barrel/stack.go +++ b/internal/wisski/ingredient/barrel/stack.go @@ -22,7 +22,7 @@ func (barrel *Barrel) Stack() component.StackWithResources { EnvPath: filepath.Join("barrel.env"), EnvContext: map[string]string{ - "DOCKER_NETWORK_NAME": barrel.Malt.Config.Docker.Network, + "DOCKER_NETWORK_NAME": barrel.Malt.Config.Docker.Network(), "SLUG": barrel.Slug, "VIRTUAL_HOST": barrel.Domain(), diff --git a/internal/wisski/ingredient/reserve/reserve.go b/internal/wisski/ingredient/reserve/reserve.go index 29b3488..172cdc8 100644 --- a/internal/wisski/ingredient/reserve/reserve.go +++ b/internal/wisski/ingredient/reserve/reserve.go @@ -29,7 +29,7 @@ func (reserve *Reserve) Stack() component.StackWithResources { EnvPath: filepath.Join("reserve.env"), EnvContext: map[string]string{ - "DOCKER_NETWORK_NAME": reserve.Malt.Config.Docker.Network, + "DOCKER_NETWORK_NAME": reserve.Malt.Config.Docker.Network(), "SLUG": reserve.Slug, "VIRTUAL_HOST": reserve.Domain(),