From 60b4fea6ab922fff8896f468632e4fb02b525c98 Mon Sep 17 00:00:00 2001 From: Andrej Shadura <andrew.shadura@collabora.co.uk> Date: Wed, 7 Feb 2024 15:20:30 +0100 Subject: [PATCH 1/7] aptly: Add new repository configuration format The new configuration format splits aptly repositories and OBS projects into two separate hashmaps, while still allowing to override settings on per-project level: my $apertis_aptly_server = { "url" => "https://...", "token" => "...", }; our $aptly_targets = { "apertis" => { "server" => $apertis_aptly_server "gpg-key" => $aptly_gpgkey, "prefix" => "apertis", } }; our $aptly_projects = { "apertis:v2025:target" => { "default" => { "target" => "apertis", "distribution" => "v2025", "component" => "target", } }, "apertis:v2025:development" => { "default" => { "target" => "apertis", "distribution" => "v2025", "component" => "development", } }, "apertis:v2025:sdk" => { "default" => { "target" => "apertis", "distribution" => "v2025", "gpg-key" => "...", "component" => "sdk", }, "rebuild" => { "distribution" => "v2025", "component" => "sdk", "gpg-key" => "...", "prefix" => "apertis", "aptly-server" => { "url" => "https://rebuilds.apertis.org", "token" => "tokentoken", }, }, }, "apertis:v2025:foo" => { "default" => { "distribution" => "v2025", "component" => "sdk", "prefix" => "foo", "gpg-key" => "...", "aptly-server" => { "url" => "https://aptly.example.org/debian", "token" => "toktok", }, } }, }; The old-style configuration is still accepted for the time being, subject to be removed in future. Signed-off-by: Andrej Shadura <andrew.shadura@collabora.co.uk> --- src/backend/BSAptly.pm | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/src/backend/BSAptly.pm b/src/backend/BSAptly.pm index d7d2e91084..cde44ab854 100755 --- a/src/backend/BSAptly.pm +++ b/src/backend/BSAptly.pm @@ -18,7 +18,7 @@ use strict; our %aptly_config_projects; BEGIN { - # From the aptly configuration, generate hash mapping project and repositories + # From the obsolete aptly configuration, generate hash mapping project and repositories # to the distribution where they live. foreach my $prefix (keys %{ $BSConfig::aptly_config }) { my $distros = $BSConfig::aptly_config->{$prefix}; @@ -36,6 +36,43 @@ BEGIN { } } } + + my $repo_components = {}; + + foreach my $projid (keys %{$BSConfig::aptly_projects}) { + my $repos = $BSConfig::aptly_projects->{$projid}; + foreach my $repoid (keys %{$repos}) { + my $repo_config = $repos->{$repoid}; + if (defined $repo_config->{'target'}) { + my $target_config = $BSConfig::aptly_targets->{$repo_config->{'target'}}; + die "$projid/$repoid refers to an undefined target repository $repo_config->{'target'}" if !defined $target_config; + + $repo_config->{'aptly-server'} ||= $target_config->{'server'}; + $repo_config->{'gpg-key'} ||= $target_config->{'gpg-key'}; + $repo_config->{'prefix'} ||= $target_config->{'prefix'}; + } + + die "$projid/$repoid does not have either aptly-server or target defined" if !defined $repo_config->{'aptly-server'}; + die "$projid/$repoid does not have prefix defined" if !defined $repo_config->{'prefix'}; + die "$projid/$repoid does not have distribution defined" if !defined $repo_config->{'distribution'}; + + # OBS gives us a single OBS project/repoid, but we need to publish all projects in the same prefix at once + # For this reason, we need to share the components set, which means that we (confusingly) have aptly + # repo-specific configs that contain information about their sibling repos. + my $all_components_in_prefix = ($repo_components + ->{$repo_config->{'aptly-server'}} + ->{$repo_config->{'prefix'}} + ->{$repo_config->{'distribution'}} + ->{'components'} ||= {}); + $all_components_in_prefix->{$repo_config->{'component'}} = { + 'project' => $projid, + 'repository' => $repoid, + 'component' => $repo_config->{'component'}, + }; + $repo_config->{'components'} = $all_components_in_prefix; + $aptly_config_projects{$projid}{$repoid} = $repo_config; + } + } } sub api_tool_exec { -- GitLab From b4c1bfaa7787aa868b5179a8b2bf2fd97899a336 Mon Sep 17 00:00:00 2001 From: Andrej Shadura <andrew.shadura@collabora.co.uk> Date: Wed, 7 Feb 2024 15:35:27 +0100 Subject: [PATCH 2/7] aptly: Print a warning if old configuration is used Signed-off-by: Andrej Shadura <andrew.shadura@collabora.co.uk> --- src/backend/BSAptly.pm | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/backend/BSAptly.pm b/src/backend/BSAptly.pm index cde44ab854..7972d7bdfc 100755 --- a/src/backend/BSAptly.pm +++ b/src/backend/BSAptly.pm @@ -14,12 +14,16 @@ use Build::Deb; use POSIX qw(strftime); use strict; +use feature 'say'; our %aptly_config_projects; BEGIN { # From the obsolete aptly configuration, generate hash mapping project and repositories # to the distribution where they live. + say STDERR 'WARNING: Deprecated configuration option \$aptly_config used, please use $aptly_projects instead!' + if defined $BSConfig::aptly_config; + foreach my $prefix (keys %{ $BSConfig::aptly_config }) { my $distros = $BSConfig::aptly_config->{$prefix}; foreach my $distro (keys %{ $distros }) { -- GitLab From 5b6bdad7a8b0a6e55b97959e5ce1f35a1e99b8b5 Mon Sep 17 00:00:00 2001 From: Andrej Shadura <andrew.shadura@collabora.co.uk> Date: Fri, 9 Feb 2024 14:45:39 +0100 Subject: [PATCH 3/7] aptly: Use Perl function signatures for better readability MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This syntax’s been available since Perl 5.20 (released 2014). Signed-off-by: Andrej Shadura <andrew.shadura@collabora.co.uk> --- src/backend/BSAptly.pm | 63 +++++++++++++++--------------------------- 1 file changed, 23 insertions(+), 40 deletions(-) diff --git a/src/backend/BSAptly.pm b/src/backend/BSAptly.pm index 7972d7bdfc..674abda89c 100755 --- a/src/backend/BSAptly.pm +++ b/src/backend/BSAptly.pm @@ -14,6 +14,9 @@ use Build::Deb; use POSIX qw(strftime); use strict; +# TODO: drop "no warnings" when upgraded to Perl 5.36 +no warnings 'experimental::signatures'; +use feature 'signatures'; use feature 'say'; our %aptly_config_projects; @@ -111,23 +114,19 @@ sub obs2aptly_exec { # Aptly configuration helpers -sub aptly_distro_get_config { - my ($prefix, $distro) = @_; +sub aptly_distro_get_config($prefix, $distro) { return $BSConfig::aptly_config->{$prefix}{$distro}; } -sub aptly_project_get_config { - my ($projid) = @_; +sub aptly_project_get_config($projid) { return $aptly_config_projects{$projid}; } -sub aptly_repo_get_config { - my ($projid, $repoid) = @_; +sub aptly_repo_get_config($projid, $repoid) { return $aptly_config_projects{$projid}{$repoid}; } -sub aptly_repo_get_component { - my ($projid, $repoid) = @_; +sub aptly_repo_get_component($projid, $repoid) { my $repo_config = aptly_repo_get_config($projid, $repoid); my $distro_components = $repo_config->{'components'}; foreach my $component (keys %$distro_components) { @@ -141,13 +140,11 @@ sub aptly_repo_get_component { # OBS objects helpers -sub obs_get_project { - my ($projid) = @_; +sub obs_get_project($projid) { return BSRevision::readproj_local($projid, 1); } -sub obs_get_repo { - my ($projid, $repoid) = @_; +sub obs_get_repo($projid, $repoid) { my $obs_proj = obs_get_project($projid); if (!$obs_proj || !$obs_proj->{'repository'}) { return undef; @@ -160,10 +157,9 @@ sub obs_get_repo { return undef; } -sub obs_project_repos { +sub obs_project_repos($proj) { # From an OBS project, get all its repositories names in a hash. Only those # repositories configured in aptly are included. - my ($proj) = @_; my %ret; if ($proj && $proj->{'repository'}) { foreach my $repo (@{ $proj->{'repository'} }) { @@ -175,7 +171,7 @@ sub obs_project_repos { return \%ret; } -sub aptly_publish_repo { +sub aptly_publish_repo($prefix, $distribution) { # Given a prefix and distribution, publish a set of multi-component # repositories. A repository is included only if: # * it's defined in the aptly config for this prefix/distribution. @@ -183,7 +179,6 @@ sub aptly_publish_repo { # Note that, as this included multiple OBS repositories, the archs defined # for each one might differ. So the union of all the enabled archs is used # when publishing. - my ($prefix, $distribution) = @_; my %archs; my @to_publish; @@ -225,15 +220,13 @@ sub aptly_publish_repo { # Aptly publish command wrappers -sub aptly_publish_drop_check { - my ($prefix, $distribution) = @_; +sub aptly_publish_drop_check($prefix, $distribution) { my $distro_config = aptly_distro_get_config($prefix, $distribution); my @args = ('publish', 'drop', '--ignore-if-missing', $prefix, $distribution); return aptlyctl_exec($distro_config->{'aptly-server'}, @args); } -sub aptly_publish_update { - my ($prefix, $distribution) = @_; +sub aptly_publish_update($prefix, $distribution) { # Update an already published repository distribution my $distro_config = aptly_distro_get_config($prefix, $distribution); my $gpgkey = $distro_config->{'gpg-key'} || $BSConfig::aptly_defconfig->{'gpg-key'}; @@ -247,8 +240,7 @@ sub aptly_publish_update { # Aptly snapshot command wrappers -sub aptly_snapshot_create { - my ($projid, $repoid, $timestamp) = @_; +sub aptly_snapshot_create($projid, $repoid, $timestamp) { my $repo_config = aptly_repo_get_config($projid, $repoid); my @args = ('repo', 'snapshot', "$projid/$repoid", @@ -256,17 +248,15 @@ sub aptly_snapshot_create { return aptlyctl_exec($repo_config->{'aptly-server'}, @args); } -sub aptly_snapshot_exists { +sub aptly_snapshot_exists($projid, $repoid, $timestamp) { # Check if aptly snapshot exists - my ($projid, $repoid, $timestamp) = @_; my $repo_config = aptly_repo_get_config($projid, $repoid); my @args = ('snapshot', 'test-exists', "$projid/$repoid/$timestamp"); return aptlyctl_exec($repo_config->{'aptly-server'}, @args) == 0; } -sub aptly_distro_snapshot { +sub aptly_distro_snapshot($prefix, $distribution, $timestamp) { # Create snapshots for all the repositories in an aptly prefix/distribution. - my ($prefix, $distribution, $timestamp) = @_; my $distro_config = aptly_distro_get_config($prefix, $distribution); my $distro_components = $distro_config->{'components'}; @@ -283,9 +273,8 @@ sub aptly_distro_snapshot { } } -sub aptly_publish_snapshot { +sub aptly_publish_snapshot($prefix, $distribution, $timestamp) { # Publish snapshots for the repositories in an aptly prefix/distribution. - my ($prefix, $distribution, $timestamp) = @_; my %archs; my @to_publish; @@ -328,8 +317,7 @@ sub aptly_publish_snapshot { # Aptly repo command wrappers -sub aptly_repo_create { - my ($projid, $repoid, $distribution, $component) = @_; +sub aptly_repo_create($projid, $repoid, $distribution, $component) { my $repo_config = aptly_repo_get_config($projid, $repoid); my @args = ('repo', 'create', "--distribution=$distribution", @@ -338,10 +326,9 @@ sub aptly_repo_create { return aptlyctl_exec($repo_config->{'aptly-server'}, @args); } -sub aptly_repo_drop { - # Remove aptly repository. Use -force flag to remove even if there's +sub aptly_repo_drop($projid, $repoid) { + # Remove aptly repository. Use --force flag to remove even if there's # a related snapshot based on this repo. - my ($projid, $repoid) = @_; my $repo_config = aptly_repo_get_config($projid, $repoid); my @args = ('repo', 'drop', '--force', "$projid/$repoid"); @@ -350,8 +337,7 @@ sub aptly_repo_drop { # Hook functions for OBS -sub aptly_putproject { - my ($proj, $oldproj, $proj_config) = @_; +sub aptly_putproject($proj, $oldproj, $proj_config) { my $oldrepos = obs_project_repos($oldproj); my $newrepos = obs_project_repos($proj); @@ -376,9 +362,7 @@ sub aptly_putproject { } } -sub aptly_delproject { - my ($proj, $proj_config) = @_; - +sub aptly_delproject($proj, $proj_config) { my $repos = obs_project_repos($proj); foreach my $repoid (keys %{ $repos }) { @@ -389,8 +373,7 @@ sub aptly_delproject { } } -sub aptly_update_repo { - my ($projid, $repoid, $config, $extrep) = @_; +sub aptly_update_repo($projid, $repoid, $config, $extrep) { my $repo_config = aptly_repo_get_config($projid, $repoid); return obs2aptly_exec($repo_config->{'aptly-server'}, "$projid/$repoid", $extrep) || aptly_publish_update($config->{'prefix'}, $config->{'distribution'}); -- GitLab From 7b57c3f72f3a0c5e0872bc5e9cc855d6d5f2d4db Mon Sep 17 00:00:00 2001 From: Andrej Shadura <andrew.shadura@collabora.co.uk> Date: Fri, 9 Feb 2024 17:21:35 +0100 Subject: [PATCH 4/7] aptly: Port internal functions and the hook to the new calling format Signed-off-by: Andrej Shadura <andrew.shadura@collabora.co.uk> --- src/backend/BSAptly.pm | 114 ++++++++++--------- src/backend/bs_published_hook_aptly_snapshot | 21 ++-- 2 files changed, 70 insertions(+), 65 deletions(-) diff --git a/src/backend/BSAptly.pm b/src/backend/BSAptly.pm index 674abda89c..d9f40e27ab 100755 --- a/src/backend/BSAptly.pm +++ b/src/backend/BSAptly.pm @@ -114,10 +114,6 @@ sub obs2aptly_exec { # Aptly configuration helpers -sub aptly_distro_get_config($prefix, $distro) { - return $BSConfig::aptly_config->{$prefix}{$distro}; -} - sub aptly_project_get_config($projid) { return $aptly_config_projects{$projid}; } @@ -171,22 +167,24 @@ sub obs_project_repos($proj) { return \%ret; } -sub aptly_publish_repo($prefix, $distribution) { +sub aptly_publish_repo($projid, $repoid) { # Given a prefix and distribution, publish a set of multi-component # repositories. A repository is included only if: - # * it's defined in the aptly config for this prefix/distribution. + # * it's defined in the aptly config. # * the publish flag is enabled on OBS for the related project/repository. - # Note that, as this included multiple OBS repositories, the archs defined - # for each one might differ. So the union of all the enabled archs is used + # Note that, as this included multiple OBS repositories, the arches defined + # for each one might differ. So the union of all the enabled arches is used # when publishing. - my %archs; + my %arches; my @to_publish; - my $distro_config = aptly_distro_get_config($prefix, $distribution); - my $distro_components = $distro_config->{'components'}; + my $repo_config = aptly_repo_get_config($projid, $repoid); + my $repo_components = $repo_config->{'components'}; + my $prefix = $repo_config->{'prefix'}; + my $distribution = $repo_config->{'distribution'}; - foreach my $component (keys %$distro_components) { - my $component_config = $distro_components->{$component}; + foreach my $component (keys %$repo_components) { + my $component_config = $repo_components->{$component}; my $projid = $component_config->{'project'}; my $repoid = $component_config->{'repository'}; my $obs_proj = obs_get_project($projid); @@ -197,45 +195,50 @@ sub aptly_publish_repo($prefix, $distribution) { push @to_publish, "$projid/$repoid//$component"; foreach my $arch (@{ $obs_repo->{'arch'} }) { if (BSUtil::enabled($repoid, $obs_proj->{'publish'}, 1, $arch)) { - $archs{$arch} = 1; + $arches{$arch} = 1; } } } - if (!%archs) { + if (!%arches) { return 0; } - my $gpgkey = $distro_config->{'gpg-key'} || $BSConfig::aptly_defconfig->{'gpg-key'}; + my $gpgkey = $repo_config->{'gpg-key'} || $BSConfig::aptly_defconfig->{'gpg-key'}; my @args = ('publish', 'create', 'repo', - (map { "--architecture=".Build::Deb::basearch($_) } (('source'), keys %archs)), + (map { + "--architecture=".Build::Deb::basearch($_) + } (('source'), keys %arches)), "--distribution=$distribution", '--skip-contents', '--skip-bz2', $prefix, @to_publish); push @args, "--gpg-key=$gpgkey" if $gpgkey; - return aptlyctl_exec($distro_config->{'aptly-server'}, @args); + return aptlyctl_exec($repo_config->{'aptly-server'}, @args); } # Aptly publish command wrappers -sub aptly_publish_drop_check($prefix, $distribution) { - my $distro_config = aptly_distro_get_config($prefix, $distribution); - my @args = ('publish', 'drop', '--ignore-if-missing', $prefix, $distribution); - return aptlyctl_exec($distro_config->{'aptly-server'}, @args); +sub aptly_publish_drop_check($projid, $repoid) { + my $repo_config = aptly_repo_get_config($projid, $repoid); + my @args = ('publish', 'drop', '--ignore-if-missing', + $repo_config->{'prefix'}, + $repo_config->{'distribution'}); + return aptlyctl_exec($repo_config->{'aptly-server'}, @args); } -sub aptly_publish_update($prefix, $distribution) { +sub aptly_publish_update($projid, $repoid) { # Update an already published repository distribution - my $distro_config = aptly_distro_get_config($prefix, $distribution); - my $gpgkey = $distro_config->{'gpg-key'} || $BSConfig::aptly_defconfig->{'gpg-key'}; + my $repo_config = aptly_repo_get_config($projid, $repoid); + my $gpgkey = $repo_config->{'gpg-key'} || $BSConfig::aptly_defconfig->{'gpg-key'}; my @args = ('publish', 'update', '--skip-contents', '--skip-bz2', - $prefix, $distribution); + $repo_config->{'prefix'}, + $repo_config->{'distribution'}); push @args, "--gpg-key=$gpgkey" if $gpgkey; - return aptlyctl_exec($distro_config->{'aptly-server'}, @args); + return aptlyctl_exec($repo_config->{'aptly-server'}, @args); } # Aptly snapshot command wrappers @@ -255,13 +258,16 @@ sub aptly_snapshot_exists($projid, $repoid, $timestamp) { return aptlyctl_exec($repo_config->{'aptly-server'}, @args) == 0; } -sub aptly_distro_snapshot($prefix, $distribution, $timestamp) { - # Create snapshots for all the repositories in an aptly prefix/distribution. - my $distro_config = aptly_distro_get_config($prefix, $distribution); - my $distro_components = $distro_config->{'components'}; +sub aptly_distro_snapshot($projid, $repoid, $timestamp) { + # Create snapshots for all the repositories for the project/repository. - foreach my $component (keys %$distro_components) { - my $component_config = $distro_components->{$component}; + my $repo_config = aptly_repo_get_config($projid, $repoid); + my $repo_components = $repo_config->{'components'}; + my $prefix = $repo_config->{'prefix'}; + my $distribution = $repo_config->{'distribution'}; + + foreach my $component (keys %$repo_components) { + my $component_config = $repo_components->{$component}; my $projid = $component_config->{'project'}; my $repoid = $component_config->{'repository'}; my $obs_proj = obs_get_project($projid); @@ -273,16 +279,18 @@ sub aptly_distro_snapshot($prefix, $distribution, $timestamp) { } } -sub aptly_publish_snapshot($prefix, $distribution, $timestamp) { - # Publish snapshots for the repositories in an aptly prefix/distribution. - my %archs; +sub aptly_publish_snapshot($projid, $repoid, $timestamp) { + # Publish snapshots for the repositories in a corresponding aptly prefix/distribution. + my %arches; my @to_publish; - my $distro_config = aptly_distro_get_config($prefix, $distribution); - my $distro_components = $distro_config->{'components'}; + my $repo_config = aptly_repo_get_config($projid, $repoid); + my $repo_components = $repo_config->{'components'}; + my $prefix = $repo_config->{'prefix'}; + my $distribution = $repo_config->{'distribution'}; - foreach my $component (keys %$distro_components) { - my $component_config = $distro_components->{$component}; + foreach my $component (keys %$repo_components) { + my $component_config = $repo_components->{$component}; my $projid = $component_config->{'project'}; my $repoid = $component_config->{'repository'}; my $obs_proj = obs_get_project($projid); @@ -294,25 +302,27 @@ sub aptly_publish_snapshot($prefix, $distribution, $timestamp) { push @to_publish, "$projid/$repoid/$timestamp//$component"; foreach my $arch (@{ $obs_repo->{'arch'} }) { if (BSUtil::enabled($repoid, $obs_proj->{'publish'}, 1, $arch)) { - $archs{$arch} = 1; + $arches{$arch} = 1; } } } - if (!%archs) { + if (!%arches) { return 0; } - my $gpgkey = $distro_config->{'gpg-key'} || $BSConfig::aptly_defconfig->{'gpg-key'}; + my $gpgkey = $repo_config->{'gpg-key'} || $BSConfig::aptly_defconfig->{'gpg-key'}; my @args = ('publish', 'create', 'snapshot', - (map { "--architecture=".Build::Deb::basearch($_) } (('source'), keys %archs)), + (map { + "--architecture=".Build::Deb::basearch($_) + } (('source'), keys %arches)), "--distribution=$distribution/snapshots/$timestamp", '--skip-contents', '--skip-bz2', $prefix, @to_publish); push @args, "--gpg-key=$gpgkey" if $gpgkey; - return aptlyctl_exec($distro_config->{'aptly-server'}, @args); + return aptlyctl_exec($repo_config->{'aptly-server'}, @args); } # Aptly repo command wrappers @@ -345,20 +355,20 @@ sub aptly_putproject($proj, $oldproj, $proj_config) { foreach my $repoid (keys %{ $oldrepos }) { my $repo_config = $proj_config->{$repoid}; if (!$newrepos->{$repoid}) { - #aptly_publish_drop_check($repo_config->{'prefix'}, $repo_config->{'distribution'}); + #aptly_publish_drop_check($proj->{'name'}, $repoid); aptly_repo_drop($proj->{'name'}, $repoid); - aptly_publish_repo($repo_config->{'prefix'}, $repo_config->{'distribution'}); + aptly_publish_repo($proj->{'name'}, $repoid); } } foreach my $repoid (keys %{ $newrepos }) { my $repo_config = $proj_config->{$repoid}; - #aptly_publish_drop_check($repo_config->{'prefix'}, $repo_config->{'distribution'}); + #aptly_publish_drop_check($proj->{'name'}, $repoid); if (!$oldrepos->{$repoid}) { my $component = aptly_repo_get_component($proj->{'name'}, $repoid); aptly_repo_create($proj->{'name'}, $repoid, $repo_config->{'distribution'}, $component); } - aptly_publish_repo($repo_config->{'prefix'}, $repo_config->{'distribution'}); + aptly_publish_repo($proj->{'name'}, $repoid); } } @@ -367,16 +377,16 @@ sub aptly_delproject($proj, $proj_config) { foreach my $repoid (keys %{ $repos }) { my $repo_config = $proj_config->{$repoid}; - aptly_publish_drop_check($repo_config->{'prefix'}, $repo_config->{'distribution'}); + aptly_publish_drop_check($proj->{'name'}, $repoid); aptly_repo_drop($proj->{'name'}, $repoid); - aptly_publish_repo($repo_config->{'prefix'}, $repo_config->{'distribution'}); + aptly_publish_repo($proj->{'name'}, $repoid); } } sub aptly_update_repo($projid, $repoid, $config, $extrep) { my $repo_config = aptly_repo_get_config($projid, $repoid); return obs2aptly_exec($repo_config->{'aptly-server'}, "$projid/$repoid", $extrep) - || aptly_publish_update($config->{'prefix'}, $config->{'distribution'}); + || aptly_publish_update($projid, $repoid); } 1; diff --git a/src/backend/bs_published_hook_aptly_snapshot b/src/backend/bs_published_hook_aptly_snapshot index 047b879080..77b23deb3d 100755 --- a/src/backend/bs_published_hook_aptly_snapshot +++ b/src/backend/bs_published_hook_aptly_snapshot @@ -28,26 +28,21 @@ sub distribution_basename { } sub do_distro_snapshot { - my ($prefix, $distribution, $timestamp) = @_; - my $distro_config = BSAptly::aptly_distro_get_config($prefix, $distribution); - die("can't find aptly configuration for distribution $prefix/$distribution\n") if !$distro_config; - BSAptly::aptly_distro_snapshot($prefix, $distribution, $timestamp); - BSAptly::aptly_publish_snapshot($prefix, $distribution, $timestamp); + my ($projid, $repoid, $timestamp) = @_; + my $repo_config = BSAptly::aptly_repo_get_config($projid, $repoid); + die("can't find aptly configuration for distribution $projid/$repoid\n") if !$repo_config; + BSAptly::aptly_distro_snapshot($projid, $repoid, $timestamp); + BSAptly::aptly_publish_snapshot($projid, $repoid, $timestamp); } getopts('t:'); my ($projid, $repoid) = $ARGV[0] =~ /(.*)\/(.*)/; -my @suffixes = ('', '-security', '-updates'); my $timestamp = $opt_t || strftime "%Y%m%dT%H%M%SZ", gmtime; die("bad project/repo parameter: $projid, $repoid\n") if !$projid || !$repoid; -my $distro_config = BSAptly::aptly_repo_get_config($projid, $repoid); -die("can't find related aptly distribution for $projid/$repoid\n") if !$distro_config; -my $prefix = $distro_config->{'prefix'}; -my $distribution = distribution_basename($distro_config->{'distribution'}); +my $repo_config = BSAptly::aptly_repo_get_config($projid, $repoid); +die("can't find related aptly distribution for $projid/$repoid\n") if !$repo_config; -foreach my $suffix (@suffixes) { - do_distro_snapshot($prefix, $distribution.$suffix, $timestamp); -} +do_distro_snapshot($projid, $repoid, $timestamp); -- GitLab From 8f80fb07564fe7db60cd56f41ee520da3510a3c7 Mon Sep 17 00:00:00 2001 From: Andrej Shadura <andrew.shadura@collabora.co.uk> Date: Tue, 20 Feb 2024 15:30:26 +0100 Subject: [PATCH 5/7] aptly: Drop executable bit on BSAptly.pm This package was never meant to be executed directly. Signed-off-by: Andrej Shadura <andrew.shadura@collabora.co.uk> --- src/backend/BSAptly.pm | 1 - 1 file changed, 1 deletion(-) mode change 100755 => 100644 src/backend/BSAptly.pm diff --git a/src/backend/BSAptly.pm b/src/backend/BSAptly.pm old mode 100755 new mode 100644 index d9f40e27ab..78751e80d0 --- a/src/backend/BSAptly.pm +++ b/src/backend/BSAptly.pm @@ -1,4 +1,3 @@ -#!/usr/bin/perl -w # # SPDX-License-Identifier: GPL-2.0+ # -- GitLab From 1f1c622dab10c18d0e15ef2c8368a6709333a32e Mon Sep 17 00:00:00 2001 From: Andrej Shadura <andrew.shadura@collabora.co.uk> Date: Wed, 21 Feb 2024 15:50:47 +0100 Subject: [PATCH 6/7] Adjust README.aptly.md according to the new configuration format Signed-off-by: Andrej Shadura <andrew.shadura@collabora.co.uk> --- README.aptly.md | 178 +++++++++++++++++++++++++++++++----------------- 1 file changed, 114 insertions(+), 64 deletions(-) diff --git a/README.aptly.md b/README.aptly.md index 1c96e8f651..7ee4fd6b5c 100644 --- a/README.aptly.md +++ b/README.aptly.md @@ -22,89 +22,139 @@ configurations defined in order to use the aptly backend. ### aptly repositories hash -The OBS configuration files must provide a hash named `aptly_config` with the +The OBS configuration files must provide a hash named `aptly_projects` with the following structure: ``` -our $aptly_config = { - "prefix_path" => { - "distribution_name" => { - "gpg-key" => "optional_gpg_hash", - "components" => { - "component_name" => { - "project" => "obs_project_id", - "repository" => "obs_repository_id", - }, - [...] - }, +our $aptly_projects = { + "obs_project_id" => { + "obs_repository_id" => { + "target" => "repository_name", + "distribution" => "distribution_name", + "component" => "component_name", + "gpg-key" => "optional_gpg_hash", }, [...] }, + [...] }; ``` -NOTE: a pair `(obs_project_id, obs_repository_id)` can only be appear once in -the hash, i.e. it can't be a component of more than one distribution. +For each `repository_name`, there must be an entry in a hash `aptly_targets`: + +``` +our $aptly_targets = { + "repository_name" => { + "server" => { + "url" => "https://...", + "token" => "...", + }, + "gpg-key" => "gpg_hash", + "prefix" => "prefix_path", + } +}; +``` -For example, for an Apertis v2022 release: +Instead of specifying `target` and a corresponding entry in `aptly_targets`, +it’s also possible to configure the aptly endpoint directly using +`aptly-server` hash (see example below). + +For example, for an Apertis v2025 release: * publish prefix path set to: `shared/apertis/public`. -* 3 distributions defined: `v2022`, `v2022-security`, `v2022-updates`. +* 3 distributions defined: `v2025`, `v2025-security`, `v2025-updates`. * each distribution has 3 components: `target`, `development`, `sdk`. * for each component, the OBS project and repository is defined. -* as an example, `v2022` will be published using the `gpg-key` defined for this +* `rebuild` repository for `sdk` is published at a separate aptly instance which + is specified inline using `aptly-server` setting. +* as an example, `v2025` will be published using the `gpg-key` defined for this distribution. Otherwise, the default `gpg-key` is used. ``` -our $aptly_config = { - "shared/apertis/public" => { - "v2022" => { - "gpg-key" => "8E62938108AE643A217D0511027B2E6C53229B30", - "components" => { - "target" => { - "project" => "apertis:v2022:target", - "repository" => "default", - }, - "development" => { - "project" => "apertis:v2022:development", - "repository" => "default", - }, - "sdk" => { - "project" => "apertis:v2022:sdk", - "repository" => "default", - }, - }, +my $apertis_aptly_server = { + "url" => "https://...", + "token" => "...", +}; + +our $aptly_repos = { + "apertis" => { + "server" => $apertis_aptly_server + "gpg-key" => $aptly_gpgkey, + "prefix" => "shared/apertis/public", + } +}; + +our $aptly_projects = { + "apertis:v2025:target" => { + "default" => { + "target" => "apertis", + "distribution" => "v2025", + "component" => "target", + } + }, + "apertis:v2025:development" => { + "default" => { + "target" => "apertis", + "distribution" => "v2025", + "component" => "development", + } + }, + "apertis:v2025:sdk" => { + "default" => { + "target" => "apertis", + "distribution" => "v2025", + "component" => "sdk", }, - "v2022-security" => { - "components" => { - "target" => { - "project" => "apertis:v2022:security:target", - "repository" => "default", - }, - "development" => { - "project" => "apertis:v2022:security:development", - "repository" => "default", - }, - "sdk" => { - "project" => "apertis:v2022:security:sdk", - "repository" => "default", - }, + "rebuild" => { + "distribution" => "v2025", + "component" => "sdk", + "gpg-key" => "...", + "prefix" => "apertis", + "aptly-server" => { + "url" => "https://rebuilds.apertis.org", + "token" => "tokentoken", }, }, - "v2022-updates" => { - "components" => { - "target" => { - "project" => "apertis:v2022:updates:target", - "repository" => "default", - }, - "development" => { - "project" => "apertis:v2022:updates:development", - "repository" => "default", - }, - "sdk" => { - "project" => "apertis:v2022:updates:sdk", - "repository" => "default", - }, - }, + }, + "apertis:v2025:updates:target" => { + "default" => { + "target" => "apertis", + "distribution" => "v2025-updates", + "component" => "target", + } + }, + "apertis:v2025:updates:development" => { + "default" => { + "target" => "apertis", + "distribution" => "v2025-updates", + "component" => "development", + } + }, + "apertis:v2025:updates:sdk" => { + "default" => { + "target" => "apertis", + "distribution" => "v2025-updates", + "component" => "sdk", + }, + }, + "apertis:v2025:security:target" => { + "default" => { + "target" => "apertis", + "distribution" => "v2025-security", + "component" => "target", + } + }, + "apertis:v2025:security:development" => { + "default" => { + "target" => "apertis", + "distribution" => "v2025-security", + "component" => "development", + } + }, + "apertis:v2025:security:sdk" => { + "default" => { + "target" => "apertis", + "distribution" => "v2025-security", + "component" => "sdk", }, }, }; -- GitLab From 052e77e02bf740bd9e380632b77375d4bfc63c3b Mon Sep 17 00:00:00 2001 From: Ryan Gonzalez <ryan.gonzalez@collabora.com> Date: Wed, 6 Mar 2024 22:13:23 +0000 Subject: [PATCH 7/7] Update BSConfig for the tests to match the new config format Signed-off-by: Ryan Gonzalez <ryan.gonzalez@collabora.com> Signed-off-by: Andrej Shadura <andrew.shadura@collabora.co.uk> --- tests/aptly/BSConfig.local.pm | 36 ++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/tests/aptly/BSConfig.local.pm b/tests/aptly/BSConfig.local.pm index 6e3b44a4fe..baa3fe27b3 100644 --- a/tests/aptly/BSConfig.local.pm +++ b/tests/aptly/BSConfig.local.pm @@ -39,26 +39,28 @@ foreach $release (@reprepro_releases) { }; }; -our $aptly_config = {}; +our $aptly_targets = { + 'apertis' => { + 'server' => { + 'url' => 'http://aptly:8080', + }, + 'prefix' => $apertis_prefix, + }, +}; + +our $aptly_projects = {}; foreach $release (@aptly_releases) { foreach $component (@apertis_components) { - $aptly_config->{$apertis_prefix}{$release}{"aptly-server"} = $aptly_server; - $aptly_config->{$apertis_prefix}{$release."-updates"}{"aptly-server"} = $aptly_server; - $aptly_config->{$apertis_prefix}{$release."-security"}{"aptly-server"} = $aptly_server; - - $aptly_config->{$apertis_prefix}{$release}{"components"}{$component} = { - "project" => "apertis:".$release.":".$component, - "repository" => "default", - }; - $aptly_config->{$apertis_prefix}{$release."-updates"}{"components"}{$component} = { - "project" => "apertis:".$release.":updates:".$component, - "repository" => "default", - }; - $aptly_config->{$apertis_prefix}{$release."-security"}{"components"}{$component} = { - "project" => "apertis:".$release.":security:".$component, - "repository" => "default", - }; + foreach my $suffix ('', '-updates', '-security') { + $aptly_projects->{"apertis:$release$suffix:$component"} = { + 'default' => { + 'target' => 'apertis', + 'distribution' => $release . $suffix, + 'component' => $component, + }, + }; + } }; }; -- GitLab