mirror of
https://github.com/xcat2/xcat-core.git
synced 2026-11-20 09:22:17 +00:00
Merge pull request #7981 from VersatusHPC/fix/release-source-only-signing
fix(build): preserve binaries in source-only runs
This commit is contained in:
+13
-16
@@ -697,7 +697,7 @@ sub index_repo {
|
||||
|
||||
# The stable bootstrap filename is a direct-download convenience, not a
|
||||
# second package. Keep it out of repository metadata.
|
||||
unlink $alias if -f $alias;
|
||||
unlink $alias if !$opts{source_only} && -f $alias;
|
||||
say "Creating repository $repodir";
|
||||
# Drop the top-level stray src.rpm and the mock logs (build.log/root.log/...)
|
||||
# that mock leaves in the resultdir, so the dir is directly deployable (upstream
|
||||
@@ -720,6 +720,7 @@ sub update_repo {
|
||||
|
||||
sub write_release_alias {
|
||||
my ($repodir) = @_;
|
||||
return if $opts{source_only};
|
||||
my $alias = "$repodir/xCAT-release-latest.noarch.rpm";
|
||||
|
||||
# glob() returns a wildcard-free pattern verbatim even when the file does not exist, so
|
||||
@@ -738,14 +739,12 @@ sub sign_rpms {
|
||||
sign_repo_dir("dist/$target/rpms", $opts{gpg_key_name});
|
||||
}
|
||||
|
||||
# Sign every rpm in a core repo dir -- the top-level binaries AND SRPMS/*.src.rpm --
|
||||
# then re-index (signing rewrites the rpms, invalidating checksums) and detach-sign
|
||||
# + export the key into BOTH the binary and the SRPMS repodata dirs.
|
||||
# Source-only runs sign and index only SRPMS; normal runs also update the binary repository.
|
||||
sub sign_repo_dir {
|
||||
my ($repodir, $key_name) = @_;
|
||||
|
||||
say "Signing RPMs in $repodir";
|
||||
my @bin = glob("$repodir/*.rpm");
|
||||
my @bin = $opts{source_only} ? () : glob("$repodir/*.rpm");
|
||||
if (@bin) {
|
||||
sh_or_die(qq(rpmsign --define "%_gpg_name $key_name" --addsign )
|
||||
. join(" ", map { qq("$_") } @bin),
|
||||
@@ -761,7 +760,7 @@ sub sign_repo_dir {
|
||||
# Signing can change RPM bytes without changing the size or timestamp used by the metadata cache.
|
||||
index_repo($repodir, 1);
|
||||
|
||||
for my $rd ("$repodir/repodata",
|
||||
for my $rd (($opts{source_only} ? () : ("$repodir/repodata")),
|
||||
(-d "$repodir/SRPMS/repodata" ? ("$repodir/SRPMS/repodata") : ())) {
|
||||
my $repomd = "$rd/repomd.xml";
|
||||
next unless -f $repomd;
|
||||
@@ -866,10 +865,7 @@ sub merge_core_repos {
|
||||
"Failed to rsync '$in' into '$out'\n");
|
||||
}
|
||||
|
||||
# Index, sign (when --gpg-sign), write the final repository metadata, then create the
|
||||
# xCAT-release-latest stable bootstrap alias. The alias MUST be created AFTER the final
|
||||
# metadata pass so write_release_alias can unlink it before createrepo and keep it out of
|
||||
# the repository index.
|
||||
# Create the bootstrap alias after the final index pass so it does not enter repository metadata.
|
||||
index_repo($out);
|
||||
if ($opts{gpg_sign}) {
|
||||
$ENV{GNUPGHOME} = $opts{gpg_home} if $opts{gpg_home};
|
||||
@@ -1199,11 +1195,10 @@ C<--rebuild> is skipped.
|
||||
./buildrpms.pl --target alma+epel-9-x86_64 --source-only
|
||||
|
||||
The srpms land in C<dist/E<lt>targetE<gt>/rpms/SRPMS/> and that index is regenerated.
|
||||
The binary metadata under C<dist/E<lt>targetE<gt>/rpms/> is deliberately left as the
|
||||
last binary build wrote it: re-indexing a directory with no binaries in it would
|
||||
replace working metadata with metadata for an empty repository. For the same reason
|
||||
no C<.repo> file or buildinfo is emitted, since both describe an installable binary
|
||||
repo that this mode does not produce. With C<--gpg-sign> the srpms are signed.
|
||||
Repository finalization leaves existing binary RPMs, metadata, signatures,
|
||||
public keys and the bootstrap alias unchanged. No C<.repo> file or buildinfo is
|
||||
emitted, since both describe an installable binary repo that this mode does not
|
||||
produce. With C<--gpg-sign>, the source RPMs and their repository metadata are signed.
|
||||
|
||||
Cannot be combined with C<--merge-core-repos>, which assembles already-built
|
||||
per-arch binary trees.
|
||||
@@ -1312,11 +1307,13 @@ Builds all selected package/target combinations.
|
||||
|
||||
=item 2.
|
||||
|
||||
Runs C<createrepo --update> for each selected target under C<dist/>.
|
||||
Indexes repositories for each selected target under C<dist/>. With C<--source-only>,
|
||||
only the SRPM repository is indexed.
|
||||
|
||||
=item 3.
|
||||
|
||||
If C<--gpg-sign> is set, signs RPMs and C<repomd.xml> for each target.
|
||||
With C<--source-only>, only source RPMs and their repository metadata are signed.
|
||||
|
||||
=item 4.
|
||||
|
||||
|
||||
@@ -63,6 +63,12 @@ they do not qualify package installation on every target architecture. On EL8,
|
||||
install both `python36` and `python3-rpm` to provide the interpreter and its RPM
|
||||
bindings.
|
||||
|
||||
The release case also runs source-only finalization with unsigned and signed
|
||||
binary RPMs, empty binary trees, and absent, retained and standalone aliases.
|
||||
It checks that binary files and aliases retain their bytes, modes and timestamps
|
||||
while source RPMs and metadata use a different signing key. This covers cached
|
||||
source RPMs; it does not run mock or publish a repository.
|
||||
|
||||
The Debian probe permission test has a separate pull-request CI step. It needs
|
||||
Debian build tools, BATS, bubblewrap, fakeroot, reprepro and
|
||||
libfile-slurper-perl. Run it as an ordinary user on a Debian or Ubuntu host
|
||||
|
||||
@@ -4,7 +4,8 @@ use warnings;
|
||||
use Digest::SHA qw(sha256_hex);
|
||||
use File::Basename qw(dirname);
|
||||
use File::Copy qw(copy);
|
||||
use File::Path qw(make_path);
|
||||
use File::Find qw(find);
|
||||
use File::Path qw(make_path remove_tree);
|
||||
use File::Slurper qw(read_binary write_text);
|
||||
use File::Temp qw(tempdir);
|
||||
use FindBin;
|
||||
@@ -117,6 +118,73 @@ my $schedule = command("$root/work", 'unshare', '--user', '--map-root-user', '--
|
||||
is(scalar(grep { $_ eq "scheduled xCAT-release-$target" } split /\n/, $schedule), 1,
|
||||
'default build schedules the release package once');
|
||||
|
||||
command($root, 'gpg', '--batch', '--pinentry-mode', 'loopback', '--passphrase', '',
|
||||
'--quick-generate-key', 'Source Test <source@example.test>', 'rsa2048', 'sign', '0');
|
||||
my $source_key = command($root, 'gpg', '--armor', '--export', 'source@example.test');
|
||||
write_text("$root/source.key", $source_key);
|
||||
command($root, 'rpm', '--dbpath', "$root/source-rpmdb", '--import', "$root/source.key");
|
||||
command($root, 'gpg', '--output', "$root/source-keyring.gpg", '--export', 'source@example.test');
|
||||
for my $state (qw(empty unsigned signed no-alias alias-only)) {
|
||||
subtest "source-only with $state binaries" => sub {
|
||||
remove_tree($cached);
|
||||
make_path("$cached/SRPMS");
|
||||
copy("$root/SRPMS/$srpm", "$cached/SRPMS/$srpm") or die $!;
|
||||
if ($state ne 'empty' && $state ne 'alias-only') {
|
||||
command($root, 'cp', '-a', "$root/output/.", $cached);
|
||||
copy("$root/SRPMS/$srpm", "$cached/SRPMS/$srpm") or die $!;
|
||||
if ($state eq 'unsigned') {
|
||||
copy("$root/RPMS/noarch/$rpm", "$cached/$rpm") or die $!;
|
||||
command($root, 'createrepo_c', '--excludes', 'SRPMS/*',
|
||||
'--excludes', 'xCAT-release-latest.noarch.rpm', $cached);
|
||||
command($root, 'gpg', '--batch', '--yes', '--armor', '--detach-sign',
|
||||
'--default-key', 'package@example.test', "$cached/repodata/repomd.xml");
|
||||
}
|
||||
check_package_index($cached, $rpm, 'initial binary repository');
|
||||
}
|
||||
if ($state eq 'no-alias') {
|
||||
unlink "$cached/xCAT-release-latest.noarch.rpm" or die $!;
|
||||
} elsif ($state ne 'empty') {
|
||||
# Keep an older alias to detect replacement even when the versioned RPM still exists.
|
||||
copy("$root/RPMS/noarch/$rpm", "$cached/xCAT-release-latest.noarch.rpm") or die $!;
|
||||
chmod 0600, "$cached/xCAT-release-latest.noarch.rpm" or die $!;
|
||||
utime 1600000000, 1600000000, "$cached/xCAT-release-latest.noarch.rpm" or die $!;
|
||||
}
|
||||
my $before = binary_snapshot($cached);
|
||||
for my $attempt (0, 1, 2) {
|
||||
my $signed = $attempt > 0 ? 1 : 0;
|
||||
my $label = "$state source-only signed=$signed run=$attempt";
|
||||
my ($rc, $out, $err) = run_in("$root/work", 'unshare', '--user', '--map-root-user', '--mount',
|
||||
'bash', repo_path('xCAT-test/native/fixtures/buildrpms-namespace.sh'),
|
||||
'sh', '-c', 'trap \'gpgconf --homedir "$GNUPGHOME" --kill gpg-agent\' EXIT; "$@"',
|
||||
'source-test', $^X, 'buildrpms.pl', '--package', 'xCAT-release', '--target', $target,
|
||||
'--release', '1', '--nproc', '1', '--source-only',
|
||||
$signed ? ('--gpg-sign', '--gpg-key-name', 'source@example.test') : ());
|
||||
unless (is($rc, 0, "$label completes")) {
|
||||
diag($out, $err);
|
||||
return;
|
||||
}
|
||||
is_deeply(binary_snapshot($cached), $before,
|
||||
"$label preserves all binary file bytes, modes and mtimes");
|
||||
check_package_index("$cached/SRPMS", $srpm, $label);
|
||||
if ($signed) {
|
||||
my $signature = command($root, 'rpmkeys', '--dbpath', "$root/source-rpmdb",
|
||||
'--checksig', "$cached/SRPMS/$srpm");
|
||||
like($signature, qr/\bsignatures OK\b/, "$label verifies the source RPM signature");
|
||||
command($root, 'gpgv', '--keyring', "$root/source-keyring.gpg",
|
||||
"$cached/SRPMS/repodata/repomd.xml.asc",
|
||||
"$cached/SRPMS/repodata/repomd.xml");
|
||||
is(read_binary("$cached/SRPMS/repodata/repomd.xml.key"), $source_key,
|
||||
"$label exports the source signing key");
|
||||
isnt(read_binary("$cached/SRPMS/$srpm"), read_binary("$root/SRPMS/$srpm"),
|
||||
"$label signs the source RPM");
|
||||
} else {
|
||||
is(read_binary("$cached/SRPMS/$srpm"), read_binary("$root/SRPMS/$srpm"),
|
||||
"$label leaves the source RPM unsigned");
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
unlink "$root/input/$rpm" or die $!;
|
||||
command("$root/work", $^X, 'buildrpms.pl', '--merge-core-repos',
|
||||
'--target', $target, '--release', '1', '--output-dir', "$root/output",
|
||||
@@ -156,6 +224,35 @@ sub package_stats {
|
||||
return {map { $_ => [(stat("$directory/$_"))[7, 9]] } ($rpm, "SRPMS/$srpm")};
|
||||
}
|
||||
|
||||
sub binary_snapshot {
|
||||
my ($directory) = @_;
|
||||
my %files;
|
||||
find({no_chdir => 1, wanted => sub {
|
||||
if ($File::Find::name eq "$directory/SRPMS") {
|
||||
$File::Find::prune = 1;
|
||||
return;
|
||||
}
|
||||
return unless -f $File::Find::name;
|
||||
my $relative = substr($File::Find::name, length($directory) + 1);
|
||||
$files{$relative} = [sha256_hex(read_binary($File::Find::name)), (stat($File::Find::name))[2, 9]];
|
||||
}}, $directory);
|
||||
return \%files;
|
||||
}
|
||||
|
||||
sub check_package_index {
|
||||
my ($repo, $filename, $label) = @_;
|
||||
my @indexed = primary_packages($repo);
|
||||
is(scalar(@indexed), 1, "$label indexes one $filename");
|
||||
for my $package (@indexed) {
|
||||
my ($location) = $package->findnodes('./*[local-name()="location"]');
|
||||
is($location->getAttribute('href'), $filename, "$label locates $filename");
|
||||
my ($checksum) = $package->findnodes('./*[local-name()="checksum"]');
|
||||
is($checksum->getAttribute('type'), 'sha256', "$label uses SHA256 for $filename");
|
||||
is($checksum->textContent, sha256_hex(read_binary("$repo/$filename")),
|
||||
"$label metadata matches final $filename bytes");
|
||||
}
|
||||
}
|
||||
|
||||
sub check_repository {
|
||||
my ($directory, $signed, $label, $before) = @_;
|
||||
is_deeply(package_stats($directory), $before, "$label signing preserves package sizes and mtimes")
|
||||
@@ -165,17 +262,7 @@ sub check_repository {
|
||||
is(read_binary($alias), read_binary("$directory/$rpm"), "$label alias has final RPM bytes");
|
||||
is((stat($alias))[2] & 0777, 0644, "$label alias is readable");
|
||||
for my $entry ([$directory, $rpm], ["$directory/SRPMS", $srpm]) {
|
||||
my ($repo, $filename) = @$entry;
|
||||
my @indexed = primary_packages($repo);
|
||||
is(scalar(@indexed), 1, "$label indexes one $filename");
|
||||
for my $package (@indexed) {
|
||||
my ($location) = $package->findnodes('./*[local-name()="location"]');
|
||||
is($location->getAttribute('href'), $filename, "$label locates $filename");
|
||||
my ($checksum) = $package->findnodes('./*[local-name()="checksum"]');
|
||||
is($checksum->getAttribute('type'), 'sha256', "$label uses SHA256 for $filename");
|
||||
is($checksum->textContent, sha256_hex(read_binary("$repo/$filename")),
|
||||
"$label metadata matches final $filename bytes");
|
||||
}
|
||||
check_package_index(@$entry, $label);
|
||||
}
|
||||
if ($signed) {
|
||||
for my $repo ($directory, "$directory/SRPMS") {
|
||||
|
||||
Reference in New Issue
Block a user