diff --git a/magefiles/config.go b/magefiles/config.go index f7f441a..3a62923 100644 --- a/magefiles/config.go +++ b/magefiles/config.go @@ -48,32 +48,38 @@ type traefikConfig struct { } type forgejoConfig struct { - Version string `json:"version"` - Name string `json:"name"` - Subdomain string `json:"subdomain"` - ContainerName string `json:"containerName"` - ContainerIpv4Address string `json:"containerIpv4Address"` - SshPort int32 `json:"sshPort"` - HttpPort int32 `json:"httpPort"` - RunMode string `json:"runMode"` - LogLevel string `json:"logLevel"` - LinuxUID int32 `json:"linuxUID"` - DataHostDirectory string `json:"dataHostDirectory"` - DataContainerDirectory string `json:"dataContainerDirectory"` - Home string `json:"home"` - Work string `json:"work"` - Custom string `json:"custom"` - AppIni string `json:"appIni"` - Bin string `json:"bin"` - Tmp string `json:"tmp"` - SecretHostDirectory string `json:"secretHostDirectory"` - SecretContainerDirectory string `json:"secretContainerDirectory"` - SecretKey string `json:"secretKey"` - InternalToken string `json:"internalToken"` - LfsJwtSecret string `json:"lfsJwtSecret"` - Oauth2Enable bool `json:"oauth2Enable"` - Oauth2JwtSigningAlgo string `json:"oauth2JwtSigningAlgo"` - Oauth2JwtSecret string `json:"oauth2JwtSecret"` + Version string `json:"version"` + Name string `json:"name"` + Subdomain string `json:"subdomain"` + ContainerName string `json:"containerName"` + ContainerIpv4Address string `json:"containerIpv4Address"` + SshPort int32 `json:"sshPort"` + HttpPort int32 `json:"httpPort"` + RunMode string `json:"runMode"` + LogLevel string `json:"logLevel"` + LinuxUID int32 `json:"linuxUID"` + DataHostDirectory string `json:"dataHostDirectory"` + DataContainerDirectory string `json:"dataContainerDirectory"` + Home string `json:"home"` + Work string `json:"work"` + Custom string `json:"custom"` + AppIni string `json:"appIni"` + Bin string `json:"bin"` + Tmp string `json:"tmp"` + SecretHostDirectory string `json:"secretHostDirectory"` + SecretContainerDirectory string `json:"secretContainerDirectory"` + SecretKey string `json:"secretKey"` + InternalToken string `json:"internalToken"` + LfsJwtSecret string `json:"lfsJwtSecret"` + Oauth2Enable bool `json:"oauth2Enable"` + Oauth2JwtSigningAlgo string `json:"oauth2JwtSigningAlgo"` + Oauth2JwtSecret string `json:"oauth2JwtSecret"` + Actions forgejoActionsConfig `json:"actions"` +} + +type forgejoActionsConfig struct { + Enabled bool `json:"enabled"` + DefaultActionsURL string `json:"defaultActionsURL"` } type gotosocialConfig struct { diff --git a/magefiles/prepare.go b/magefiles/prepare.go index 4659c22..f01e4bc 100644 --- a/magefiles/prepare.go +++ b/magefiles/prepare.go @@ -110,6 +110,10 @@ func render(cfg config, environment, component string) error { return fmt.Errorf("unable to read files from %s; %w ", templateDirName, err) } + funcMap := template.FuncMap{ + "default": defaultValue, + } + for _, f := range files { err := func() error { templateFilename := f.Name() @@ -128,7 +132,7 @@ func render(cfg config, environment, component string) error { defer file.Close() templatePath := filepath.Join(templateDirName, templateFilename) - tmpl, err := template.New(templateFilename).ParseFiles(templatePath) + tmpl, err := template.New(templateFilename).Funcs(funcMap).ParseFiles(templatePath) if err != nil { return fmt.Errorf("unable to create a new template value from '%s'; %w", templateFilename, err) } @@ -205,3 +209,11 @@ func copyAssets(environment, service string) error { return nil } + +func defaultValue(value, defaultValue string) string { + if value == "" { + return defaultValue + } + + return value +} diff --git a/templates/forgejo/app.ini.gotmpl b/templates/forgejo/app.ini.gotmpl index d4ec137..e96e1a1 100644 --- a/templates/forgejo/app.ini.gotmpl +++ b/templates/forgejo/app.ini.gotmpl @@ -136,3 +136,7 @@ FILE_EXTENSIONS = .adoc,.asciidoc RENDER_COMMAND = "asciidoctor -s -a showtitle --out-file=- -" ; Input is not a standard input but a file IS_INPUT_FILE = false + +[actions] +ENABLED = {{ .Forgejo.Actions.Enabled }} +DEFAULT_ACTIONS_URL = {{ default .Forgejo.Actions.DefaultActionsURL "https://code.forgejo.org" }}