This repository has been archived on 2023-05-06. You can view files and clone it, but cannot push or open issues or pull requests.
helix/internal/config/config.go

88 lines
2.9 KiB
Go
Raw Normal View History

2021-06-30 06:03:02 +01:00
package config
import (
"encoding/json"
"fmt"
"io/ioutil"
)
// Config is the whole configuration for the forge platform deployment.
2021-06-30 06:03:02 +01:00
type Config struct {
ProjectName string `json:"project"`
2021-09-07 02:01:13 +01:00
Domain string `json:"domain"`
Docker DockerConfig `json:"docker"`
Services ServicesConfig `json:"services"`
2021-06-30 06:03:02 +01:00
}
// DockerConfig contains the configuration for docker specific components.
2021-06-30 06:03:02 +01:00
type DockerConfig struct {
2021-09-07 02:01:13 +01:00
Network DockerNetworkConfig `json:"network"`
SharedVolume DockerSharedVolumeConfig `json:"sharedVolume"`
SharedGroupId int `json:"sharedGroupId"`
2021-06-30 06:03:02 +01:00
}
// DockerNetworkConfig contains configuration for creating the docker network.
2021-06-30 06:03:02 +01:00
type DockerNetworkConfig struct {
Name string `json:"name"`
Subnet string `json:"subnet"`
Driver string `json:"driver"`
}
2021-09-01 22:04:40 +01:00
// DockerSharedVolumeConfig contains configuration for creating the shared volume.
type DockerSharedVolumeConfig struct {
2021-09-07 02:01:13 +01:00
Name string `json:"name"`
MountPath string `json:"mountPath"`
}
// Services contains a list of services and their configuration.
type ServicesConfig struct {
Traefik TraefikConfig `json:"traefik"`
2021-09-01 22:04:40 +01:00
Gitea GiteaConfig `json:"gitea"`
}
// TraefikConfig contains configuration for the Traefik container.
type TraefikConfig struct {
CheckNewVersion bool `json:"checkNewVersion"`
ContainerIp string `json:"containerIp"`
LogLevel string `json:"logLevel"`
SendAnonymousUsage bool `json:"sendAnonymousUsage"`
Version string `json:"version"`
}
2021-09-01 22:04:40 +01:00
// GiteaConfig contains configuration for the Gitea container.
type GiteaConfig struct {
2021-09-07 02:01:13 +01:00
AppName string `json:"appName"`
BaseUri string `json:"baseUri"`
ContainerIp string `json:"containerIp"`
ContainerDataDirectory string `json:"containerDataDirectory"`
ContainerTemporaryDirectory string `json:"containerTemporaryDirectory"`
HostDataDirectory string `json:"hostDataDirectory"`
HttpPort int `json:"httpPort"`
InternalToken string `json:"internalToken"`
LogLevel string `json:"logLevel"`
RunMode string `json:"runMode"`
SecretKey string `json:"secretKey"`
SshDomain string `json:"sshDomain"`
SshPort int `json:"sshPort"`
UserId int `json:"userId"`
Version string `json:"version"`
2021-09-01 22:04:40 +01:00
}
// NewConfig creates a new Config value from a given JSON file.
2021-06-30 06:03:02 +01:00
func NewConfig(file string) (Config, error) {
var err error
2021-09-07 02:01:13 +01:00
c := defaultConfig()
2021-06-30 06:03:02 +01:00
data, err := ioutil.ReadFile(file)
if err != nil {
return c, fmt.Errorf("unable to read data from %s...\n%v", file, err)
}
if err = json.Unmarshal(data, &c); err != nil {
return c, fmt.Errorf("unable to decode the JSON configuration from %s...\n%v", file, err)
}
return c, nil
}