From d061f29699e9b39b8780e16d458cee017e136601c80454727a65dd1a9a1ed564 Mon Sep 17 00:00:00 2001 From: Adam Majer Date: Mon, 6 Oct 2025 13:21:51 +0200 Subject: [PATCH] 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. --- autogits.spec | 14 ++++++++++++++ obs-status-service/README.md | 11 +++++++++++ obs-status-service/main.go | 29 +++++++++++++++++++++-------- systemd/obs-status-service.service | 16 ++++++++++++++++ 4 files changed, 62 insertions(+), 8 deletions(-) create mode 100644 systemd/obs-status-service.service diff --git a/autogits.spec b/autogits.spec index 8aa3cad..a80bf74 100644 --- a/autogits.spec +++ b/autogits.spec @@ -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 -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 -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-pr/workflow-pr %{buildroot}%{_bindir}/workflow-pr install -D -m0755 hujson/hujson %{buildroot}%{_bindir}/hujson @@ -150,6 +151,18 @@ install -D -m0755 hujson/hujson %postun -n obs-staging-bot %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 %license COPYING %doc gitea-events-rabbitmq-publisher/README.md @@ -180,6 +193,7 @@ install -D -m0755 hujson/hujson %license COPYING %doc obs-status-service/README.md %{_bindir}/obs-status-service +%{_unitdir}/obs-status-service.service %files -n workflow-direct %license COPYING diff --git a/obs-status-service/README.md b/obs-status-service/README.md index 5e61b68..36da331 100644 --- a/obs-status-service/README.md +++ b/obs-status-service/README.md @@ -31,3 +31,14 @@ Target Usage * README.md of package git or project git * 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 diff --git a/obs-status-service/main.go b/obs-status-service/main.go index 80c1f51..060095b 100644 --- a/obs-status-service/main.go +++ b/obs-status-service/main.go @@ -208,22 +208,35 @@ func WriteJson(data any, res http.ResponseWriter) { var ObsUrl *string func main() { - cert := flag.String("cert-file", "", "TLS certificates file") - key := flag.String("key-file", "", "Private key for the TLS certificate") - listen := flag.String("listen", "[::1]:8080", "Listening string") + obsUrlDef := os.Getenv("OBS_STATUS_SERVICE_OBS_URL") + if len(obsUrlDef) == 0 { + 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") - 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") - // RabbitMQHost := flag.String("rabbit-mq", "amqps://rabbit.opensuse.org", "RabbitMQ message bus server") - // Topic := flag.String("topic", "opensuse.obs", "RabbitMQ topic prefix") flag.Parse() if *debug { common.SetLoggingLevel(common.LogLevelDebug) } - // common.PanicOnError(common.RequireObsSecretToken()) - if redisUrl := os.Getenv("REDIS"); len(redisUrl) > 0 { RedisConnect(redisUrl) } else { diff --git a/systemd/obs-status-service.service b/systemd/obs-status-service.service new file mode 100644 index 0000000..925771d --- /dev/null +++ b/systemd/obs-status-service.service @@ -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 +