From ff475a48b8acf255e502a760743afa7e5afcf934 Mon Sep 17 00:00:00 2001 From: Automation Pipeline Date: Sun, 8 Oct 2023 10:01:27 -0400 Subject: [PATCH] Now builds things, next step is adjusting the pipeline to use the new script/ --- build.pl | 86 ++++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 65 insertions(+), 21 deletions(-) diff --git a/build.pl b/build.pl index 2de9a76..e114ad6 100755 --- a/build.pl +++ b/build.pl @@ -13,6 +13,7 @@ use Path::Tiny; use IPC::Run; use Time::HiRes qw/time/; use Syntax::Keyword::Try; +use Time::Piece; my @bases = qw/bullseye-backports bookworm-backports/; my @options = ("main", "main-threaded", "main-longdouble", "main-quadmath", "main-debugging", "main-longdouble-threaded", "main-quadmath-threaded", "main-debugging-threaded", "main-debugging-longdouble-threaded", "main-debugging-quadmath-threaded", "main-debugging-longdouble", "main-debugging-quadmath"); @@ -20,8 +21,9 @@ my @versions = ("5.20.3", "5.22.4", "5.24.4", "5.26.3", "5.28.3", "5.30.3", "5.3 my $max_workers = 8; my $verbose = 1; my $suffix = ""; -my $push_repo = ""; +my $push_repo = "gitea.simcop2387.info/simcop2387/perl-container"; my $arch = 'amd64'; +my %build_args = (); GetOptions('verbose' => \$verbose, 'quiet' => sub {$verbose = 0}, @@ -29,6 +31,7 @@ GetOptions('verbose' => \$verbose, 'suffix=s' => \$suffix, 'push_repo=s' => \$push_repo, 'arch=s' => \$arch, + 'build_args=s%' => \%build_args, ); my $arch_suffix="-$arch"; @@ -92,6 +95,9 @@ sub run_cmd { my $e = $@; print "$disp_prefix: $e\n"; + print $log_fh "---------------------\n"; + print $log_fh "Exception: $e\n"; + print $log_fh "---------------------\n"; return -1; } } @@ -100,30 +106,63 @@ my $builder = IO::Async::Function->new( code => sub { my ( $version, $options, $os_base ) = @_; - my $expanded_version = $version =~ s/(?5)\.(?\d+)\.(?\d+)/sprintf "%d.%03d.%03d", $+{major}, $+{minor}, $+{patch}/er; + try { + my $expanded_version = $version =~ s/(?5)\.(?\d+)\.(?\d+)/sprintf "%d.%03d.%03d", $+{major}, $+{minor}, $+{patch}/er; - my $tags = ["$push_repo$version-$options-$os_base$suffix$arch_suffix", "$push_repo$expanded_version-$options-$os_base$suffix$arch_suffix"]; + # TODO other calcs for image names + my $tags = ["$push_repo/$version-$options-$os_base$suffix$arch_suffix", "$push_repo/$expanded_version-$options-$os_base$suffix$arch_suffix"]; + + my $build_date = Time::Piece::gmtime()->datetime(); - my ($total_output, $total_error, $retval); + my %labels = ( + "org.opencontainers.image.created"=>$build_date, + "org.label-schema.build-date"=>$build_date, + "org.opencontainers.image.source"=>"https://gitea.simcop2387.info/simcop2387/docker-perl.git", + "org.label-schema.vcs-url"=> "https://gitea.simcop2387.info/simcop2387/docker-perl.git", + "org.opencontainers.image.url"=>"https://gitea.simcop2387.info/simcop2387/docker-perl", + "org.label-schema.url"=>"https://gitea.simcop2387.info/simcop2387/docker-perl", + "org.label-schema.usage"=> "https://gitea.simcop2387.info/simcop2387/docker-perl", + "org.opencontainers.image.revision"=>$ENV{CI_COMMIT_REF}, + "org.label-schema.vcs-ref"=> $ENV{CI_COMMIT_REF}, + "org.label-schema.version"=> $version, + "org.label-schema.name"=> "perl-$options", + "org.label-schema.schema-version"=> "1.0", + ); - my $startdir = path("output/perls"); - my $log_dir = path("output/logs"); - $log_dir->mkdir(); - my $log_file = $log_dir->child("$expanded_version-$options-$os_base$suffix$arch_suffix-build.log"); - my $log_fh = $log_file->openw_utf8(); - my $workdir = $startdir->child("$expanded_version-$options-$os_base/"); + my ($total_output, $total_error, $retval); - if ($workdir->exists()) { - chdir($workdir); - my ($output, $error, $retval) = run_cmd(["ls"], $tags->[0], $log_fh, ""); - } else { - print "Failed to find $workdir\n"; + my $startdir = path("output/perls"); + my $log_dir = path("output/logs"); + $log_dir->mkdir(); + my $log_file = $log_dir->child("$expanded_version-$options-$os_base$suffix$arch_suffix-build.log"); + my $log_fh = $log_file->openw_utf8(); + my $workdir = $startdir->child("$expanded_version-$options-$os_base/"); + + if ($workdir->exists()) { + chdir($workdir); + my @tag_args = map {("-t", $_)} @$tags; + my @labels = map {my $k=$_; my $v=$labels{$k}; ("--label", "$k=$v")} keys %labels; + my @buildargs = map {my $k=$_; my $v=$build_args{$k}; ("--build-arg", "$k=$v")} keys %build_args; + + my $cmd = [qw(docker buildx build --rm=true -f Dockerfile ./ --push --pull=true), @buildargs, @tag_args, @labels]; + use Data::Dumper; + print Dumper($cmd); + + my ($output, $error, $retval) = run_cmd($cmd, $tags->[0], $log_fh, ""); + } else { + print "Failed to find $workdir\n"; + } + + $log_fh->close(); + + # Should probably return a success or failure + return; + } catch { + my $e = $@; + + print "EXCEPTION: $e\n"; + return; } - - $log_fh->close(); - - # Should probably return a success or failure - return; }, max_workers => $max_workers, @@ -137,9 +176,14 @@ $builder->start(); my %calls; -for my $version (@versions) { +my $count = 0; + +ALL: for my $version (@versions) { for my $option (@options) { for my $base (@bases) { + print "---> $count\n"; + last ALL if $count++ == 10; + my $rend = "$version-$option-$base"; my $future = $builder->call(args => [$version, $option, $base])->on_ready(sub { delete $calls{$rend};