ci(gitlab-ci): pull frontend artifacts from backend downstream pipeline

This commit is contained in:
Sarah Vaupel 2024-09-16 01:51:13 +02:00
parent e059082cf6
commit 120e00ea2e
3 changed files with 57 additions and 1 deletions

View File

@ -67,7 +67,7 @@ setup:dynamic:
- BACKEND_IMAGE_VERSION=`${GIT_LOG_COMMAND} ${BACKEND_IMAGE_DEPENDENCIES} | tee backend-image-version`
- 'echo "FRONTEND_IMAGE_VERSION: ${FRONTEND_IMAGE_VERSION}, BACKEND_IMAGE_VERSION: ${BACKEND_IMAGE_VERSION}"'
- cat .gitlab-ci/frontend.yml | .gitlab-ci/dynamci.pl FRONTEND_IMAGE_VERSION=${FRONTEND_IMAGE_VERSION} > frontend.yml
- cat .gitlab-ci/backend.yml | .gitlab-ci/dynamci.pl BACKEND_IMAGE_VERSION=${BACKEND_IMAGE_VERSION} > backend.yml
- cat .gitlab-ci/backend.yml | .gitlab-ci/dynamci.pl BACKEND_IMAGE_VERSION=${BACKEND_IMAGE_VERSION} PARENT_PIPELINE_ID=${CI_PIPELINE_ID} > backend.yml
artifacts:
paths:
- frontend-image-version

View File

@ -13,6 +13,7 @@
variables:
BACKEND_IMAGE_VERSION: #dyn#
PARENT_PIPELINE_ID: #dyn#
stages:
- compile
@ -26,6 +27,9 @@ default:
entrypoint: [""]
docker:
platform: x86_64
before_script:
- ./.gitlab-ci/pull-frontend-artifacts.pl "${REGISTRY_AUTH_TOKEN}" "${PARENT_PIPELINE_ID}"
- unzip ./.artifacts.tmp/artifacts.zip
artifacts:
name: "${CI_JOB_NAME}-${CI_COMMIT_SHORT_SHA}"
expire_in: "1 day"

View File

@ -0,0 +1,52 @@
#!/usr/bin/env perl
use strict;
use warnings;
my $dir = ".artifacts.tmp";
my ($token, $id) = @ARGV;
die "usage: $0 [token] [id]" unless defined $token and defined $id;
die "id in bad format" unless $id=~m#^[0-9]+$#;
if(!-d $dir) {
mkdir($dir) or die "Cannot create directory '$dir', because: $!\n";
}
system(qq(curl --globoff --header "PRIVATE-TOKEN: $token" "https://gitlab.uniworx.de/api/v4/projects/5/pipelines/$id/bridges" > $dir/bridges));
my $pips = pparse("$dir/bridges", {id=>qq#."downstream_pipeline"."id"#}, {name=>""});
my $fe = $pips->{frontend}{id};
die "No frontend pipeline found!" unless $fe;
system(qq(curl --globoff --header "PRIVATE-TOKEN: $token" "https://gitlab.uniworx.de/api/v4/projects/5/pipelines/$fe/jobs" > $dir/fe-jobs));
my $arte = pparse("$dir/fe-jobs", {id=>""}, {name=>"", web_url=>"", artifacts=>""});
system(qq#curl --output $dir/artifacts.zip --location --header "PRIVATE-TOKEN: $token" "https://gitlab.uniworx.de/api/v4/projects/5/jobs/$arte->{compile}{id}/artifacts"#);
sub pparse {
my ($file, $numerical, $alpha) = @_;
my %all = ();
for my $k(keys %$numerical) {
$all{$k} = $numerical->{$k} || qq#."$k"#;
}
for my $k(keys %$alpha) {
$all{$k} = $alpha->{$k} || qq#."$k"#;
}
my $select = join ', ', map {qq#"$_": $all{$_}#} sort keys %all;
my $cont = qx(cat $file | jq -c '.[] | {$select}');
my @cont = split m/\R/, $cont;
my %ret = ();
for my $c(@cont) {
my %block = ();
for(keys %$numerical) {
$block{$_} = $1 if $c=~m#"$_":([0-9]+)#;
}
for(keys %$alpha) {
$block{$_} = $1 if $c=~m#"$_":"([^"]*)"#;
}
$ret{$block{name}} =\%block;
}
return \%ret
}