From 8d5bde3c2f06b1a0d3ac5925400994691785f217 Mon Sep 17 00:00:00 2001 From: Dan Anglin Date: Tue, 7 Sep 2021 02:01:13 +0100 Subject: [PATCH] checkpoint: default config --- internal/config/config.go | 45 ++++++++++++++++---------------- internal/config/defaults.go | 52 +++++++++++++++++++++++++++++++++++++ internal/stacks/docker.go | 18 ++++--------- 3 files changed, 80 insertions(+), 35 deletions(-) create mode 100644 internal/config/defaults.go diff --git a/internal/config/config.go b/internal/config/config.go index 152a86b..e2b885d 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -9,14 +9,16 @@ import ( // 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"` + Network DockerNetworkConfig `json:"network"` + SharedVolume DockerSharedVolumeConfig `json:"sharedVolume"` + SharedGroupId int `json:"sharedGroupId"` } // DockerNetworkConfig contains configuration for creating the docker network. @@ -28,7 +30,8 @@ type DockerNetworkConfig struct { // DockerSharedVolumeConfig contains configuration for creating the shared volume. type DockerSharedVolumeConfig struct { - Name string `json:"name"` + Name string `json:"name"` + MountPath string `json:"mountPath"` } // Services contains a list of services and their configuration. @@ -41,8 +44,6 @@ type ServicesConfig struct { type TraefikConfig struct { CheckNewVersion bool `json:"checkNewVersion"` ContainerIp string `json:"containerIp"` - Domain string `json:"domain"` - GroupId int LogLevel string `json:"logLevel"` SendAnonymousUsage bool `json:"sendAnonymousUsage"` Version string `json:"version"` @@ -50,29 +51,29 @@ type TraefikConfig struct { // GiteaConfig contains configuration for the Gitea container. type GiteaConfig struct { - AppName string `json:"appName"` - BaseUri string `json:"baseUri"` - ContainerIp string `json:"containerIp"` - DataDirectory string `json:"dataDirectory"` - Domain string `json:"domain"` - GroupId int - 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 `json:"sshDomain"` - SshPort int `json:"sshPort"` - UserId int - Version string `json:"version"` + 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 c Config 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) diff --git a/internal/config/defaults.go b/internal/config/defaults.go new file mode 100644 index 0000000..465520d --- /dev/null +++ b/internal/config/defaults.go @@ -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 +} diff --git a/internal/stacks/docker.go b/internal/stacks/docker.go index c4cf6b3..3794460 100644 --- a/internal/stacks/docker.go +++ b/internal/stacks/docker.go @@ -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. 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 { // 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{ { 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 + // TODO: Template the data directory. if err = renderTemplates(services.Gitea, "gitea", projectCacheRoot); err != nil { return err } @@ -179,13 +171,13 @@ func deployDockerStack(project string, dockerConfig config.DockerConfig, service DockerVolumes: []docker.DockerVolume{ { Name: sharedVolume.Name, - MountPath: pulumi.String(sharedVolumeMountPath), + MountPath: pulumi.String(dockerConfig.SharedVolume.MountPath), }, }, HostPathVolumes: []docker.HostPathVolume{ { - HostPath: pulumi.String(services.Gitea.DataDirectory), - MountPath: pulumi.String("/helix/gitea/data"), + HostPath: pulumi.String(services.Gitea.HostDataDirectory), + MountPath: pulumi.String(services.Gitea.ContainerDataDirectory), }, }, UniqueLabel: "gitea-container",