From 51287ea57e1031cc034812b5f39981d7608131f2 Mon Sep 17 00:00:00 2001 From: Achilleas Koutsou Date: Wed, 30 Oct 2024 15:19:57 +0100 Subject: [PATCH] osbuild-composer/config: new option: ignore_missing_repos osbuild/images added an error type that's returned when the reporegistry loader doesn't find any repository configurations to load [1]. This lets callers decide whether to stop or continue execution based on whether repository configurations are required. A new top-level configuration option is added for osbuild-composer that makes it possible to start the service without having static rpm repositories configured. This is useful in certain (SaaS) modes where build requests specify their own repository configurations. --- cmd/osbuild-composer/composer.go | 24 +++++++++++++++++++----- cmd/osbuild-composer/config.go | 32 +++++++++++++++++--------------- 2 files changed, 36 insertions(+), 20 deletions(-) diff --git a/cmd/osbuild-composer/composer.go b/cmd/osbuild-composer/composer.go index 485248d6f..9926e7a94 100644 --- a/cmd/osbuild-composer/composer.go +++ b/cmd/osbuild-composer/composer.go @@ -78,16 +78,30 @@ func NewComposer(config *ComposerConfigFile, stateDir, cacheDir string) (*Compos } repoConfigs, err := reporegistry.LoadAllRepositories(repositoryConfigs) - if err != nil { - return nil, fmt.Errorf("error loading repository definitions: %v", err) + switch err.(type) { + case *reporegistry.NoReposLoadedError: + if !c.config.IgnoreMissingRepos { + return nil, fmt.Errorf("error loading repository definitions: %w", err) + } + // running without repositories is allowed: log message and continue + logrus.Info(err.Error()) + logrus.Info("ignore_missing_repos enabled: continuing") + case nil: + c.repos = reporegistry.NewFromDistrosRepoConfigs(repoConfigs) + default: + return nil, fmt.Errorf("error loading repository definitions: %w", err) } - c.repos = reporegistry.NewFromDistrosRepoConfigs(repoConfigs) c.solver = dnfjson.NewBaseSolver(path.Join(c.cacheDir, "rpmmd")) c.solver.SetDNFJSONPath(c.config.DNFJson) - // Clean up the cache, removes unknown distros and files - c.solver.CleanupOldCacheDirs(c.repos.ListDistros()) + // Clean up the cache, removes unknown distros and files. + // If no repos are configured, the cache is cleared out completely. + var repoDistros []string + if c.repos != nil { + repoDistros = c.repos.ListDistros() + } + c.solver.CleanupOldCacheDirs(repoDistros) var jobs jobqueue.JobQueue if config.Worker.PGDatabase != "" { diff --git a/cmd/osbuild-composer/config.go b/cmd/osbuild-composer/config.go index 4bed222cf..e62be6537 100644 --- a/cmd/osbuild-composer/config.go +++ b/cmd/osbuild-composer/config.go @@ -12,18 +12,19 @@ import ( ) type ComposerConfigFile struct { - Koji KojiAPIConfig `toml:"koji"` - Worker WorkerAPIConfig `toml:"worker"` - WeldrAPI WeldrAPIConfig `toml:"weldr_api"` - DistroAliases map[string]string `toml:"distro_aliases" env:"DISTRO_ALIASES"` - LogLevel string `toml:"log_level"` - LogFormat string `toml:"log_format"` - DNFJson string `toml:"dnf-json"` - SplunkHost string `env:"SPLUNK_HEC_HOST"` - SplunkPort string `env:"SPLUNK_HEC_PORT"` - SplunkToken string `env:"SPLUNK_HEC_TOKEN"` - GlitchTipDSN string `env:"GLITCHTIP_DSN"` - DeploymentChannel string `env:"CHANNEL"` + Koji KojiAPIConfig `toml:"koji"` + Worker WorkerAPIConfig `toml:"worker"` + WeldrAPI WeldrAPIConfig `toml:"weldr_api"` + DistroAliases map[string]string `toml:"distro_aliases" env:"DISTRO_ALIASES"` + LogLevel string `toml:"log_level"` + LogFormat string `toml:"log_format"` + DNFJson string `toml:"dnf-json"` + IgnoreMissingRepos bool `toml:"ignore_missing_repos"` + SplunkHost string `env:"SPLUNK_HEC_HOST"` + SplunkPort string `env:"SPLUNK_HEC_PORT"` + SplunkToken string `env:"SPLUNK_HEC_TOKEN"` + GlitchTipDSN string `env:"GLITCHTIP_DSN"` + DeploymentChannel string `env:"CHANNEL"` } type KojiAPIConfig struct { @@ -129,9 +130,10 @@ func GetDefaultConfig() *ComposerConfigFile { "rhel-9": "rhel-9.5", "rhel-10": "rhel-10.0", }, - LogLevel: "info", - LogFormat: "journal", - DNFJson: "/usr/libexec/osbuild-depsolve-dnf", + LogLevel: "info", + LogFormat: "journal", + DNFJson: "/usr/libexec/osbuild-depsolve-dnf", + IgnoreMissingRepos: false, } }