checkpoint: default config

This commit is contained in:
Dan Anglin 2021-09-07 02:01:13 +01:00
parent 528a30476e
commit 8d5bde3c2f
Signed by: dananglin
GPG key ID: 0C1D44CFBEE68638
3 changed files with 80 additions and 35 deletions

View file

@ -9,14 +9,16 @@ import (
// Config is the whole configuration for the forge platform deployment. // Config is the whole configuration for the forge platform deployment.
type Config struct { type Config struct {
ProjectName string `json:"project"` ProjectName string `json:"project"`
Domain string `json:"domain"`
Docker DockerConfig `json:"docker"` Docker DockerConfig `json:"docker"`
Services ServicesConfig `json:"services"` Services ServicesConfig `json:"services"`
} }
// DockerConfig contains the configuration for docker specific components. // DockerConfig contains the configuration for docker specific components.
type DockerConfig struct { type DockerConfig struct {
Network DockerNetworkConfig `json:"network"` Network DockerNetworkConfig `json:"network"`
SharedVolume DockerSharedVolumeConfig `json:"sharedVolume"` SharedVolume DockerSharedVolumeConfig `json:"sharedVolume"`
SharedGroupId int `json:"sharedGroupId"`
} }
// DockerNetworkConfig contains configuration for creating the docker network. // DockerNetworkConfig contains configuration for creating the docker network.
@ -28,7 +30,8 @@ type DockerNetworkConfig struct {
// DockerSharedVolumeConfig contains configuration for creating the shared volume. // DockerSharedVolumeConfig contains configuration for creating the shared volume.
type DockerSharedVolumeConfig struct { type DockerSharedVolumeConfig struct {
Name string `json:"name"` Name string `json:"name"`
MountPath string `json:"mountPath"`
} }
// Services contains a list of services and their configuration. // Services contains a list of services and their configuration.
@ -41,8 +44,6 @@ type ServicesConfig struct {
type TraefikConfig struct { type TraefikConfig struct {
CheckNewVersion bool `json:"checkNewVersion"` CheckNewVersion bool `json:"checkNewVersion"`
ContainerIp string `json:"containerIp"` ContainerIp string `json:"containerIp"`
Domain string `json:"domain"`
GroupId int
LogLevel string `json:"logLevel"` LogLevel string `json:"logLevel"`
SendAnonymousUsage bool `json:"sendAnonymousUsage"` SendAnonymousUsage bool `json:"sendAnonymousUsage"`
Version string `json:"version"` Version string `json:"version"`
@ -50,29 +51,29 @@ type TraefikConfig struct {
// GiteaConfig contains configuration for the Gitea container. // GiteaConfig contains configuration for the Gitea container.
type GiteaConfig struct { type GiteaConfig struct {
AppName string `json:"appName"` AppName string `json:"appName"`
BaseUri string `json:"baseUri"` BaseUri string `json:"baseUri"`
ContainerIp string `json:"containerIp"` ContainerIp string `json:"containerIp"`
DataDirectory string `json:"dataDirectory"` ContainerDataDirectory string `json:"containerDataDirectory"`
Domain string `json:"domain"` ContainerTemporaryDirectory string `json:"containerTemporaryDirectory"`
GroupId int HostDataDirectory string `json:"hostDataDirectory"`
HttpPort int `json:"httpPort"` HttpPort int `json:"httpPort"`
InternalToken string `json:"internalToken"` InternalToken string `json:"internalToken"`
LogLevel string `json:"logLevel"` LogLevel string `json:"logLevel"`
RootUrl string `json:"rootUrl"` RunMode string `json:"runMode"`
RunMode string `json:"runMode"` SecretKey string `json:"secretKey"`
SecretKey string `json:"secretKey"` SshDomain string `json:"sshDomain"`
SshDomain string `json:"sshDomain"` SshPort int `json:"sshPort"`
SshPort int `json:"sshPort"` UserId int `json:"userId"`
UserId int Version string `json:"version"`
Version string `json:"version"`
} }
// NewConfig creates a new Config value from a given JSON file. // NewConfig creates a new Config value from a given JSON file.
func NewConfig(file string) (Config, error) { func NewConfig(file string) (Config, error) {
var c Config
var err error var err error
c := defaultConfig()
data, err := ioutil.ReadFile(file) data, err := ioutil.ReadFile(file)
if err != nil { if err != nil {
return c, fmt.Errorf("unable to read data from %s...\n%v", file, err) return c, fmt.Errorf("unable to read data from %s...\n%v", file, err)

View file

@ -0,0 +1,52 @@
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
}

View file

@ -75,15 +75,6 @@ func (c *DockerStack) Destroy(ctx context.Context) error {
// deployDockerStack returns a Pulumi run function that is used to deploy the docker stack. // deployDockerStack returns a Pulumi run function that is used to deploy the docker stack.
func deployDockerStack(project string, dockerConfig config.DockerConfig, services config.ServicesConfig) pulumi.RunFunc { func deployDockerStack(project string, dockerConfig config.DockerConfig, services config.ServicesConfig) pulumi.RunFunc {
sharedVolumeMountPath := "/helix/shared"
groupId := 2239
services.Traefik.GroupId = groupId
services.Gitea.GroupId = groupId
services.Gitea.UserId = 2000
return func(ctx *pulumi.Context) error { return func(ctx *pulumi.Context) error {
// TODO: Create the provider when we start playing with remote hosts // TODO: Create the provider when we start playing with remote hosts
@ -144,7 +135,7 @@ func deployDockerStack(project string, dockerConfig config.DockerConfig, service
DockerVolumes: []docker.DockerVolume{ DockerVolumes: []docker.DockerVolume{
{ {
Name: sharedVolume.Name, Name: sharedVolume.Name,
MountPath: pulumi.String(sharedVolumeMountPath), MountPath: pulumi.String(dockerConfig.SharedVolume.MountPath),
}, },
}, },
} }
@ -154,6 +145,7 @@ func deployDockerStack(project string, dockerConfig config.DockerConfig, service
} }
// Gitea service // Gitea service
// TODO: Template the data directory.
if err = renderTemplates(services.Gitea, "gitea", projectCacheRoot); err != nil { if err = renderTemplates(services.Gitea, "gitea", projectCacheRoot); err != nil {
return err return err
} }
@ -179,13 +171,13 @@ func deployDockerStack(project string, dockerConfig config.DockerConfig, service
DockerVolumes: []docker.DockerVolume{ DockerVolumes: []docker.DockerVolume{
{ {
Name: sharedVolume.Name, Name: sharedVolume.Name,
MountPath: pulumi.String(sharedVolumeMountPath), MountPath: pulumi.String(dockerConfig.SharedVolume.MountPath),
}, },
}, },
HostPathVolumes: []docker.HostPathVolume{ HostPathVolumes: []docker.HostPathVolume{
{ {
HostPath: pulumi.String(services.Gitea.DataDirectory), HostPath: pulumi.String(services.Gitea.HostDataDirectory),
MountPath: pulumi.String("/helix/gitea/data"), MountPath: pulumi.String(services.Gitea.ContainerDataDirectory),
}, },
}, },
UniqueLabel: "gitea-container", UniqueLabel: "gitea-container",