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/instance/instance.go

89 lines
2.3 KiB
Go
Raw Normal View History

2021-09-09 00:04:08 +01:00
package instance
2021-06-30 06:03:02 +01:00
import (
2021-09-09 00:04:08 +01:00
"errors"
2021-06-30 06:03:02 +01:00
"encoding/json"
"fmt"
"io/ioutil"
)
2021-09-09 00:04:08 +01:00
// ReadInstance reads an instance's details from a given JSON file.
func ReadInstance(file string) (Instance, error) {
2021-06-30 06:03:02 +01:00
var err error
2021-09-09 00:04:08 +01:00
i := defaultInstance()
2021-09-07 02:01:13 +01:00
2021-06-30 06:03:02 +01:00
data, err := ioutil.ReadFile(file)
if err != nil {
2021-09-09 00:04:08 +01:00
return i, fmt.Errorf("unable to read data from %s...\n%v", file, err)
2021-06-30 06:03:02 +01:00
}
2021-09-09 00:04:08 +01:00
if err = json.Unmarshal(data, &i); err != nil {
return i, fmt.Errorf("unable to decode the JSON configuration from %s...\n%v", file, err)
}
if len(i.Project) == 0 {
return i, errors.New("the value for 'project' must not be empty")
2021-06-30 06:03:02 +01:00
}
2021-09-07 22:55:52 +01:00
// Propagate the domain to the services as appropriate
2021-09-09 00:04:08 +01:00
i.Services.Gitea.Domain = i.Domain
i.Services.Traefik.Domain = i.Domain
i.Services.Gitea.RootUrl = fmt.Sprintf("https://%s/%s", i.Domain, i.Services.Gitea.BaseUri)
i.Services.Gitea.SshDomain = i.Domain
2021-09-07 22:55:52 +01:00
// Propagate the shared Group ID to the serivces as appropriate
2021-09-09 00:04:08 +01:00
i.Services.Traefik.GroupId = i.SharedGroupId
i.Services.Gitea.GroupId = i.SharedGroupId
2021-09-07 22:55:52 +01:00
2021-09-09 00:04:08 +01:00
return i, nil
2021-06-30 06:03:02 +01:00
}
2021-09-07 22:55:52 +01:00
2021-09-09 00:04:08 +01:00
func defaultInstance() Instance {
c := Instance{
Project: "",
2021-09-07 22:55:52 +01:00
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
}