checkpoint: default config
This commit is contained in:
parent
528a30476e
commit
8d5bde3c2f
3 changed files with 80 additions and 35 deletions
|
@ -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)
|
||||
|
|
52
internal/config/defaults.go
Normal file
52
internal/config/defaults.go
Normal 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
|
||||
}
|
|
@ -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",
|
||||
|
|
Reference in a new issue