services/magefiles/config.go
Dan Anglin 3340ddc475
build: automation with Go and Mage
We shall now use Go and Mage to manage the Flow services. The templates
have been converted to Go templates, Mage has replaced Make and the
helper bash scripts have been rewritten in Go.
2023-02-12 20:59:55 +00:00

90 lines
3.2 KiB
Go

//go:build mage
// +build mage
package main
import (
"encoding/json"
"fmt"
"os"
)
type config struct {
RootDomain string `json:"rootDomain"`
FlowGID int32 `json:"flowGID"`
DockerNetworkSubnet string `json:"dockerNetworkSubnet"`
DockerHost string `json:"dockerHost"`
Traefik traefikConfig `json:"traefik"`
Forgejo forgejoConfig `json:"forgejo"`
GoToSocial gotosocialConfig `json:"gotosocial"`
}
type traefikConfig struct {
Version string `json:"version"`
CheckNewVersion bool `json:"checkNewVersion"`
ExternalSSHPort int32 `json:"externalSSHPort"`
LogLevel string `json:"logLevel"`
SendAnonymousUsage bool `json:"sendAnonymousUsage"`
ContainerIpv4Address string `json:"containerIpv4Address"`
AcmeEmail string `json:"acmeEmail"`
SharedMountPoint string `json:"sharedMountPoint"`
TlsHostDirectory string `json:"tlsHostDirectory"`
TlsContainerDirectory string `json:"tlsContainerDirectory"`
PilotToken string `json:"pilotToken"`
}
type forgejoConfig struct {
Version string `json:"version"`
Name string `json:"name"`
Subdomain string `json:"subdomain"`
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"`
}
type gotosocialConfig struct {
Version string `json:"version"`
DockerImageDigest string `json:"dockerImageDigest"`
Name string `json:"name"`
LogLevel string `json:"logLevel"`
LinuxUID int32 `json:"linuxUID"`
Subdomain string `json:"subdomain"`
ContainerIpv4Address string `json:"containerIpv4Address"`
Port int32 `json:"port"`
DataHostDirectory string `json:"dataHostDirectory"`
DataContainerDirectory string `json:"dataContainerDirectory"`
}
func newConfig(path string) (config, error) {
var c config
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
}