88 lines
2.3 KiB
Go
88 lines
2.3 KiB
Go
package instance
|
|
|
|
import (
|
|
"errors"
|
|
"encoding/json"
|
|
"fmt"
|
|
"io/ioutil"
|
|
)
|
|
|
|
// ReadInstance reads an instance's details from a given JSON file.
|
|
func ReadInstance(file string) (Instance, error) {
|
|
var err error
|
|
|
|
i := defaultInstance()
|
|
|
|
data, err := ioutil.ReadFile(file)
|
|
if err != nil {
|
|
return i, fmt.Errorf("unable to read data from %s...\n%v", file, err)
|
|
}
|
|
|
|
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")
|
|
}
|
|
|
|
// Propagate the domain to the services as appropriate
|
|
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
|
|
|
|
// Propagate the shared Group ID to the serivces as appropriate
|
|
i.Services.Traefik.GroupId = i.SharedGroupId
|
|
i.Services.Gitea.GroupId = i.SharedGroupId
|
|
|
|
return i, nil
|
|
}
|
|
|
|
func defaultInstance() Instance {
|
|
c := Instance{
|
|
Project: "",
|
|
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
|
|
}
|