package config import ( "encoding/json" "fmt" "io/ioutil" ) // NewConfig creates a new Config value from a given JSON file. func NewConfig(file string) (Config, error) { var err error c := defaultConfig() 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) } // 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 return c, nil } 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 }