Files
server/config/config.go
T
2023-01-13 23:25:41 -07:00

103 lines
2.0 KiB
Go

package config
import (
"fmt"
"git.ohea.xyz/golang/config"
)
type WebhookSender string
const (
Gitea WebhookSender = "gitea"
)
type Webhook struct {
Sender WebhookSender
Secret string
}
type Job struct {
URL string
Webhook *Webhook
Cron *string
PollInterval uint64
}
type Runner struct {
Secret string
}
type DBConfig struct {
Address string
Port int
Username string
Password string
Name string
}
type MountType string
const (
Bind MountType = "bind"
Volume = "volume"
)
type MountConf struct {
Type MountType
Source string
}
type PipelineConf struct {
AccessURL string // URL that the pipeline runner can access the server at
DockerNetwork *string // Name of the docker network that should be assigned to the pipeline script runner
WorkingDir string
MountConf MountConf // This script describes how to mount WorkingDir into the pipeline executor container
}
type Config struct {
Address string
Port int
DBConfig DBConfig
PipelineConf PipelineConf
Jobs map[string]Job
Runners map[string]Runner
}
func GetConfig() (config.Config[Config], error) {
defaultNetworkName := "cursorius"
configData := config.Config[Config]{
Name: "cursorius",
Filename: "server",
Config: Config{
Address: "127.0.0.1",
Port: 45420,
DBConfig: DBConfig{
Address: "DB_ADDRESS",
Port: 5432,
Username: "USERNAME",
Password: "PASSWORD",
Name: "cursorius",
},
PipelineConf: PipelineConf{
AccessURL: "cursorius-server:45420",
DockerNetwork: &defaultNetworkName,
WorkingDir: "/opt/cursorius/working",
MountConf: MountConf{
Type: Bind,
Source: "/opt/cursorius/working",
},
},
Jobs: make(map[string]Job),
Runners: make(map[string]Runner),
},
}
_, err := configData.Get()
if err != nil {
return configData, fmt.Errorf("Could not read config file: %w", err)
}
return configData, nil
}