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

84 lines
2.2 KiB
Go
Raw Normal View History

2021-06-30 06:03:02 +01:00
package config
import (
"encoding/json"
"fmt"
"io/ioutil"
)
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)
}
2021-09-07 22:55:52 +01:00
// Propagate the domain to the services as appropriate
c.Services.Gitea.Domain = c.Domain
c.Services.Traefik.Domain = c.Domain
c.Services.Gitea.RootUrl = fmt.Sprintf("https://%s/%s", c.Domain, c.Services.Gitea.BaseUri)
c.Services.Gitea.SshDomain = c.Domain
// Propagate the shared Group ID to the serivces as appropriate
c.Services.Traefik.GroupId = c.SharedGroupId
c.Services.Gitea.GroupId = c.SharedGroupId
2021-06-30 06:03:02 +01:00
return c, nil
}
2021-09-07 22:55:52 +01:00
func defaultConfig() Config {
c := Config{
ProjectName: "",
Domain: "localhost",
SharedGroupId: 2239,
Docker: DockerConfig{
Network: DockerNetworkConfig{
Name: "forge-platform-network",
Subnet: "172.20.0.0/24",
Driver: "default",
},
SharedVolume: DockerSharedVolumeConfig{
Name: "forge-platform-shared-volume",
MountPath: "/forge-platform/shared",
},
},
Services: ServicesConfig{
Traefik: TraefikConfig{
CheckNewVersion: false,
ContainerIp: "172.20.0.2",
LogLevel: "info",
SendAnonymousUsage: false,
Version: "v2.5.2",
},
Gitea: GiteaConfig{
AppName: "Gitea",
BaseUri: "git",
ContainerIp: "172.20.0.3",
ContainerDataDirectory: "/forge-platform/data",
ContainerTemporaryDirectory: "/forge-platform/tmp",
HostDataDirectory: "/mnt/forge-platform/gitea",
HttpPort: 3000,
InternalToken: "",
LogLevel: "info",
RunMode: "prod",
SecretKey: "",
SshPort: 2222,
UserId: 2000,
Version: "1.50.0",
},
},
}
return c
}