services/magefiles/config.go
Dan Anglin dd339eb3d6
fix: template updates and code fixes
This commit comes after provisioning the development environment.

Changes:

- templates: template the container name.
- mage: update the deploy target to deploy to specific environments.
- compose: fix network ref.
- traefik: merge all dynamic templates into one file.
- woodpecker(dockerfile): remove commands to copy entrypoint to the
  docker container since the entrypoint has been removed.
- traefik: add support for using existing TLS certificates.
2023-08-28 04:04:40 +01:00

150 lines
5.6 KiB
Go

//go:build mage
package main
import (
"encoding/json"
"fmt"
"os"
"path/filepath"
)
type config struct {
RootDomain string `json:"rootDomain"`
FlowGID int32 `json:"flowGID"`
Docker dockerConfig `json:"docker"`
Traefik traefikConfig `json:"traefik"`
Forgejo forgejoConfig `json:"forgejo"`
GoToSocial gotosocialConfig `json:"gotosocial"`
Woodpecker woodpeckerConfig `json:"woodpecker"`
Landing landingConfig `json:"landing"`
}
type dockerConfig struct {
Host string `json:"host"`
Network dockerNetworkConfig `json:"network"`
}
type dockerNetworkConfig struct {
Name string `json:"name"`
Subnet string `json:"subnet"`
}
type traefikConfig struct {
Version string `json:"version"`
CheckNewVersion bool `json:"checkNewVersion"`
ExternalSSHPort int32 `json:"externalSSHPort"`
LogLevel string `json:"logLevel"`
SendAnonymousUsage bool `json:"sendAnonymousUsage"`
ContainerName string `json:"containerName"`
ContainerIpv4Address string `json:"containerIpv4Address"`
GenerateAcmeCertificates bool `json:"generateAcmeCertificates"`
AcmeEmail string `json:"acmeEmail"`
SharedMountPoint string `json:"sharedMountPoint"`
TlsHostDirectory string `json:"tlsHostDirectory"`
TlsContainerDirectory string `json:"tlsContainerDirectory"`
StaticConfigDirectory string `json:"staticConfigDirectory"`
DynamicConfigDirectory string `json:"dynamicConfigDirectory"`
}
type forgejoConfig struct {
Version string `json:"version"`
Name string `json:"name"`
Subdomain string `json:"subdomain"`
ContainerName string `json:"containerName"`
ContainerIpv4Address string `json:"containerIpv4Address"`
SshPort int32 `json:"sshPort"`
HttpPort int32 `json:"httpPort"`
RunMode string `json:"runMode"`
LogLevel string `json:"logLevel"`
LinuxUID int32 `json:"linuxUID"`
DataHostDirectory string `json:"dataHostDirectory"`
DataContainerDirectory string `json:"dataContainerDirectory"`
Home string `json:"home"`
Work string `json:"work"`
Custom string `json:"custom"`
AppIni string `json:"appIni"`
Bin string `json:"bin"`
Tmp string `json:"tmp"`
SecretHostDirectory string `json:"secretHostDirectory"`
SecretContainerDirectory string `json:"secretContainerDirectory"`
SecretKey string `json:"secretKey"`
InternalToken string `json:"internalToken"`
LfsJwtSecret string `json:"lfsJwtSecret"`
Oauth2Enable bool `json:"oauth2Enable"`
Oauth2JwtSigningAlgo string `json:"oauth2JwtSigningAlgo"`
Oauth2JwtSecret string `json:"oauth2JwtSecret"`
}
type gotosocialConfig struct {
Version string `json:"version"`
Name string `json:"name"`
LogLevel string `json:"logLevel"`
LinuxUID int32 `json:"linuxUID"`
Subdomain string `json:"subdomain"`
ContainerName string `json:"containerName"`
ContainerIpv4Address string `json:"containerIpv4Address"`
Port int32 `json:"port"`
DataHostDirectory string `json:"dataHostDirectory"`
DataContainerDirectory string `json:"dataContainerDirectory"`
AccountsRegistrationOpen bool `json:"accountsRegistrationOpen"`
AccountsAllowCustomCss bool `json:"accountsAllowCustomCss"`
LandingPageUser string `json:"landingPageUser"`
WebBaseDirectory string `json:"webBaseDirectory"`
TZ string `json:"tz"`
}
type woodpeckerConfig struct {
Version string `json:"version"`
LogLevel string `json:"logLevel"`
LinuxUID int32 `json:"linuxUID"`
Subdomain string `json:"subdomain"`
GrpcSubdomain string `json:"grpcSubdomain"`
ContainerName string `json:"containerName"`
ContainerIpv4Address string `json:"containerIpv4Address"`
HttpPort int32 `json:"httpPort"`
GrpcPort int32 `json:"grpcPort"`
DataHostDirectory string `json:"dataHostDirectory"`
DataContainerDirectory string `json:"dataContainerDirectory"`
Admin string `json:"admin"`
Open bool `json:"open"`
AgentSecret string `json:"agentSecret"`
ForgejoClientID string `json:"forgejoClientID"`
ForgejoClientSecret string `json:"forgejoClientSecret"`
}
type landingConfig struct {
Version string `json:"version"`
ContainerName string `json:"containerName"`
ContainerIpv4Address string `json:"containerIpv4Address"`
Services []landingConfigLinks `json:"services"`
Profiles []landingConfigLinks `json:"profiles"`
Port int32 `json:"port"`
ImageDigest string `json:"imageDigest"`
}
type landingConfigLinks struct {
Title string `json:"title"`
URL string `json:"url"`
Rel string `json:"rel"`
}
func newConfig(environment string) (config, error) {
var c config
path := filepath.Join(configDir, environment, configFileName)
f, err := os.Open(path)
if err != nil {
return c, fmt.Errorf("unable to open the file; %w", err)
}
defer f.Close()
decoder := json.NewDecoder(f)
if err = decoder.Decode(&c); err != nil {
return c, fmt.Errorf("unable to decode JSON data; %w", err)
}
return c, nil
}