status: use env as parameters to service

Instead of having to rewrite the service file with parameters,
leverage Env file to pass default parameters values.
This commit is contained in:
2025-10-06 13:21:51 +02:00
parent f6fd96881d
commit d061f29699
4 changed files with 62 additions and 8 deletions

View File

@@ -122,6 +122,7 @@ install -D -m0755 group-review/group-review
install -D -m0755 obs-staging-bot/obs-staging-bot %{buildroot}%{_bindir}/obs-staging-bot install -D -m0755 obs-staging-bot/obs-staging-bot %{buildroot}%{_bindir}/obs-staging-bot
install -D -m0644 systemd/obs-staging-bot.service %{buildroot}%{_unitdir}/obs-staging-bot.service install -D -m0644 systemd/obs-staging-bot.service %{buildroot}%{_unitdir}/obs-staging-bot.service
install -D -m0755 obs-status-service/obs-status-service %{buildroot}%{_bindir}/obs-status-service install -D -m0755 obs-status-service/obs-status-service %{buildroot}%{_bindir}/obs-status-service
install -D -m0644 systemd/obs-status-service.service %{buildroot}%{_unitdir}/obs-status-service.service
install -D -m0755 workflow-direct/workflow-direct %{buildroot}%{_bindir}/workflow-direct install -D -m0755 workflow-direct/workflow-direct %{buildroot}%{_bindir}/workflow-direct
install -D -m0755 workflow-pr/workflow-pr %{buildroot}%{_bindir}/workflow-pr install -D -m0755 workflow-pr/workflow-pr %{buildroot}%{_bindir}/workflow-pr
install -D -m0755 hujson/hujson %{buildroot}%{_bindir}/hujson install -D -m0755 hujson/hujson %{buildroot}%{_bindir}/hujson
@@ -150,6 +151,18 @@ install -D -m0755 hujson/hujson
%postun -n obs-staging-bot %postun -n obs-staging-bot
%service_del_postun obs-staging-bot.service %service_del_postun obs-staging-bot.service
%pre -n obs-status-service
%service_add_pre obs-status-service.service
%post -n obs-status-service
%service_add_post obs-status-service.service
%preun -n obs-status-service
%service_del_preun obs-status-service.service
%postun -n obs-status-service
%service_del_postun obs-status-service.service
%files -n gitea-events-rabbitmq-publisher %files -n gitea-events-rabbitmq-publisher
%license COPYING %license COPYING
%doc gitea-events-rabbitmq-publisher/README.md %doc gitea-events-rabbitmq-publisher/README.md
@@ -180,6 +193,7 @@ install -D -m0755 hujson/hujson
%license COPYING %license COPYING
%doc obs-status-service/README.md %doc obs-status-service/README.md
%{_bindir}/obs-status-service %{_bindir}/obs-status-service
%{_unitdir}/obs-status-service.service
%files -n workflow-direct %files -n workflow-direct
%license COPYING %license COPYING

View File

@@ -31,3 +31,14 @@ Target Usage
* README.md of package git or project git * README.md of package git or project git
* comment section of a Gitea PR * comment section of a Gitea PR
Running
-------
Default parameters can be changed by env variables
| Environment variable | Default | Description
|---------------------------------|-----------------------------|------------
| `OBS_STATUS_SERVICE_OBS_URL` | https://build.opensuse.org | Location for creating build logs and monitor page build results
| `OBS_STATUS_SERVICE_LISTEN` | [::1]:8080 | Listening address and port
| `OBS_STATUS_SERVICE_CERT` | /run/obs-status-service.pem | Location of certificate file for service
| `OBS_STATUS_SERVICE_KEY` | /run/obs-status-service.pem | Location of key file for service

View File

@@ -208,22 +208,35 @@ func WriteJson(data any, res http.ResponseWriter) {
var ObsUrl *string var ObsUrl *string
func main() { func main() {
cert := flag.String("cert-file", "", "TLS certificates file") obsUrlDef := os.Getenv("OBS_STATUS_SERVICE_OBS_URL")
key := flag.String("key-file", "", "Private key for the TLS certificate") if len(obsUrlDef) == 0 {
listen := flag.String("listen", "[::1]:8080", "Listening string") obsUrlDef = "https://build.opensuse.org"
}
listenDef := os.Getenv("OBS_STATUS_SERVICE_LISTEN")
if len(listenDef) == 0 {
listenDef = "[::1]:8080"
}
certDef := os.Getenv("OBS_STATUS_SERVICE_CERT")
if len(certDef) == 0 {
certDef = "/run/obs-status-service.pem"
}
keyDef := os.Getenv("OBS_STATUS_SERVICE_KEY")
if len(keyDef) == 0 {
keyDef = certDef
}
cert := flag.String("cert-file", certDef, "TLS certificates file")
key := flag.String("key-file", keyDef, "Private key for the TLS certificate")
listen := flag.String("listen", listenDef, "Listening string")
disableTls := flag.Bool("no-tls", false, "Disable TLS") disableTls := flag.Bool("no-tls", false, "Disable TLS")
ObsUrl = flag.String("obs-url", "https://http.opensuse.org", "OBS API endpoint for package buildlog information") ObsUrl = flag.String("obs-url", obsUrlDef, "OBS API endpoint for package buildlog information")
debug := flag.Bool("debug", false, "Enable debug logging") debug := flag.Bool("debug", false, "Enable debug logging")
// RabbitMQHost := flag.String("rabbit-mq", "amqps://rabbit.opensuse.org", "RabbitMQ message bus server")
// Topic := flag.String("topic", "opensuse.obs", "RabbitMQ topic prefix")
flag.Parse() flag.Parse()
if *debug { if *debug {
common.SetLoggingLevel(common.LogLevelDebug) common.SetLoggingLevel(common.LogLevelDebug)
} }
// common.PanicOnError(common.RequireObsSecretToken())
if redisUrl := os.Getenv("REDIS"); len(redisUrl) > 0 { if redisUrl := os.Getenv("REDIS"); len(redisUrl) > 0 {
RedisConnect(redisUrl) RedisConnect(redisUrl)
} else { } else {

View File

@@ -0,0 +1,16 @@
[Unit]
Description=OBS build status as SVG service
After=network-online.target
[Service]
Type=exec
Restart=on-failure
ExecStart=/usr/bin/obs-status-service
EnvironmentFile=-/etc/default/obs-status-service.env
DynamicUser=yes
NoNewPrivileges=yes
ProtectSystem=strict
[Install]
WantedBy=multi-user.target