checkpoint: update config refactor
This commit is contained in:
parent
8d5bde3c2f
commit
649ee06c63
4 changed files with 140 additions and 128 deletions
|
@ -6,68 +6,6 @@ import (
|
|||
"io/ioutil"
|
||||
)
|
||||
|
||||
// Config is the whole configuration for the forge platform deployment.
|
||||
type Config struct {
|
||||
ProjectName string `json:"project"`
|
||||
Domain string `json:"domain"`
|
||||
Docker DockerConfig `json:"docker"`
|
||||
Services ServicesConfig `json:"services"`
|
||||
}
|
||||
|
||||
// DockerConfig contains the configuration for docker specific components.
|
||||
type DockerConfig struct {
|
||||
Network DockerNetworkConfig `json:"network"`
|
||||
SharedVolume DockerSharedVolumeConfig `json:"sharedVolume"`
|
||||
SharedGroupId int `json:"sharedGroupId"`
|
||||
}
|
||||
|
||||
// DockerNetworkConfig contains configuration for creating the docker network.
|
||||
type DockerNetworkConfig struct {
|
||||
Name string `json:"name"`
|
||||
Subnet string `json:"subnet"`
|
||||
Driver string `json:"driver"`
|
||||
}
|
||||
|
||||
// DockerSharedVolumeConfig contains configuration for creating the shared volume.
|
||||
type DockerSharedVolumeConfig struct {
|
||||
Name string `json:"name"`
|
||||
MountPath string `json:"mountPath"`
|
||||
}
|
||||
|
||||
// Services contains a list of services and their configuration.
|
||||
type ServicesConfig struct {
|
||||
Traefik TraefikConfig `json:"traefik"`
|
||||
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"`
|
||||
}
|
||||
|
||||
// GiteaConfig contains configuration for the Gitea container.
|
||||
type GiteaConfig struct {
|
||||
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"`
|
||||
}
|
||||
|
||||
// NewConfig creates a new Config value from a given JSON file.
|
||||
func NewConfig(file string) (Config, error) {
|
||||
var err error
|
||||
|
@ -83,5 +21,63 @@ func NewConfig(file string) (Config, error) {
|
|||
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
|
||||
}
|
||||
|
|
|
@ -37,22 +37,22 @@ func TestValidConfig(t *testing.T) {
|
|||
Version: "v2.4.9",
|
||||
},
|
||||
Gitea: GiteaConfig{
|
||||
AppName: "A git hosting platform",
|
||||
BaseUri: "git",
|
||||
ContainerIp: "172.17.1.3",
|
||||
AppName: "A git hosting platform",
|
||||
BaseUri: "git",
|
||||
ContainerIp: "172.17.1.3",
|
||||
DataDirectory: "/helix/data/gitea",
|
||||
Domain: "forge.test.local",
|
||||
GroupId: 0,
|
||||
HttpPort: 3000,
|
||||
Domain: "forge.test.local",
|
||||
GroupId: 0,
|
||||
HttpPort: 3000,
|
||||
InternalToken: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYmYiOjE2MjY0ODQxNjV9.Lp2v7vluALZtAng1jte5-SvF69iAUoh9pFBxf-IJ1a0",
|
||||
LogLevel: "info",
|
||||
RootUrl: "https://forge.test.local/git",
|
||||
RunMode: "test",
|
||||
SecretKey: "gBFbTiV4GTwzonAyyHNKghc9lmWvaTmFqZs5u0h14Qgx5yp1OKlrZKgw1e5LfCiE",
|
||||
SshDomain: "forge.test.local",
|
||||
SshPort: 2222,
|
||||
UserId: 0,
|
||||
Version: "1.14.4",
|
||||
LogLevel: "info",
|
||||
RootUrl: "https://forge.test.local/git",
|
||||
RunMode: "test",
|
||||
SecretKey: "gBFbTiV4GTwzonAyyHNKghc9lmWvaTmFqZs5u0h14Qgx5yp1OKlrZKgw1e5LfCiE",
|
||||
SshDomain: "forge.test.local",
|
||||
SshPort: 2222,
|
||||
UserId: 0,
|
||||
Version: "1.14.4",
|
||||
},
|
||||
},
|
||||
},
|
||||
|
|
|
@ -1,52 +0,0 @@
|
|||
package config
|
||||
|
||||
func defaultConfig() Config {
|
||||
domain := "localhost"
|
||||
|
||||
c := Config{
|
||||
ProjectName: "",
|
||||
Domain: domain,
|
||||
|
||||
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",
|
||||
},
|
||||
SharedGroupId: 12239,
|
||||
},
|
||||
|
||||
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: "",
|
||||
SshDomain: domain,
|
||||
SshPort: 2222,
|
||||
UserId: 12000,
|
||||
Version: "1.50.0",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
return c
|
||||
}
|
68
internal/config/types.go
Normal file
68
internal/config/types.go
Normal file
|
@ -0,0 +1,68 @@
|
|||
package config
|
||||
|
||||
// Config is the whole configuration for the forge platform deployment.
|
||||
type Config struct {
|
||||
ProjectName string `json:"project"`
|
||||
Domain string `json:"domain"`
|
||||
SharedGroupId int `json:"sharedGroupId"`
|
||||
Docker DockerConfig `json:"docker"`
|
||||
Services ServicesConfig `json:"services"`
|
||||
}
|
||||
|
||||
// DockerConfig contains the configuration for docker specific components.
|
||||
type DockerConfig struct {
|
||||
Network DockerNetworkConfig `json:"network"`
|
||||
SharedVolume DockerSharedVolumeConfig `json:"sharedVolume"`
|
||||
}
|
||||
|
||||
// DockerNetworkConfig contains configuration for creating the docker network.
|
||||
type DockerNetworkConfig struct {
|
||||
Name string `json:"name"`
|
||||
Subnet string `json:"subnet"`
|
||||
Driver string `json:"driver"`
|
||||
}
|
||||
|
||||
// DockerSharedVolumeConfig contains configuration for creating the shared volume.
|
||||
type DockerSharedVolumeConfig struct {
|
||||
Name string `json:"name"`
|
||||
MountPath string `json:"mountPath"`
|
||||
}
|
||||
|
||||
// Services contains a list of services and their configuration.
|
||||
type ServicesConfig struct {
|
||||
Traefik TraefikConfig `json:"traefik"`
|
||||
Gitea GiteaConfig `json:"gitea"`
|
||||
}
|
||||
|
||||
// TraefikConfig contains configuration for the Traefik container.
|
||||
type TraefikConfig struct {
|
||||
CheckNewVersion bool `json:"checkNewVersion"`
|
||||
SendAnonymousUsage bool `json:"sendAnonymousUsage"`
|
||||
GroupId int
|
||||
ContainerIp string `json:"containerIp"`
|
||||
Domain string
|
||||
LogLevel string `json:"logLevel"`
|
||||
Version string `json:"version"`
|
||||
}
|
||||
|
||||
// GiteaConfig contains configuration for the Gitea container.
|
||||
type GiteaConfig struct {
|
||||
AppName string `json:"appName"`
|
||||
BaseUri string `json:"baseUri"`
|
||||
ContainerIp string `json:"containerIp"`
|
||||
ContainerDataDirectory string `json:"containerDataDirectory"`
|
||||
ContainerTemporaryDirectory string `json:"containerTemporaryDirectory"`
|
||||
Domain string
|
||||
HostDataDirectory string `json:"hostDataDirectory"`
|
||||
HttpPort int `json:"httpPort"`
|
||||
InternalToken string `json:"internalToken"`
|
||||
LogLevel string `json:"logLevel"`
|
||||
RootUrl string `json:"rootUrl"`
|
||||
RunMode string `json:"runMode"`
|
||||
SecretKey string `json:"secretKey"`
|
||||
SshDomain string
|
||||
SshPort int `json:"sshPort"`
|
||||
UserId int `json:"userId"`
|
||||
GroupId int
|
||||
Version string `json:"version"`
|
||||
}
|
Reference in a new issue