-
Notifications
You must be signed in to change notification settings - Fork 6
/
build
executable file
·132 lines (108 loc) · 3.79 KB
/
build
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#!/usr/bin/env perl
use strict;
use warnings;
use Scalar::Util ();
use autodie;
use Getopt::Long;
use Path::Tiny;
use Digest::SHA;
sub usage {
die "Usage: $0 [--push] [--filter=s] [--check]\n";
}
my %cfg = (repo => 'melopt/perl-alt');
GetOptions(\%cfg, 'help|?', 'push', 'filter=s', 'repo=s', 'multiplatform', 'check', 'debug') or usage();
usage() if $cfg{help};
my $repo = $cfg{repo};
my @versions = (
['perl', 'latest', '5.40-slim', 1],
['perl', 'full', '5.40'],
['alpine', 'latest', '3.20'],
['alpine', 'next', 'edge'],
['alpine', 'edge', 'edge'],
['chainguard', 'latest', 'latest', undef, 'cgr.dev/chainguard/wolfi-base'],
);
## Lambda
my %lambda_runtime_versions = (
aarch64 => [
'https://github.com/aws/aws-lambda-runtime-interface-emulator/releases/download/v1.22/aws-lambda-rie-arm64',
'15ae5356c8e76cc483007c7cfe1aa821cae10afd259eab82ad8b7102ff486fdf',
],
x86_64 => [
'https://github.com/aws/aws-lambda-runtime-interface-emulator/releases/download/v1.22/aws-lambda-rie-x86_64',
'9badeae7e0ed0667afa60f79fd250002dfae38104f23ebc80508e247616ac97a',
],
);
if ($cfg{check}) {
for my $arch (sort keys %lambda_runtime_versions) {
my ($url, $wanted) = $lambda_runtime_versions{$arch}->@*;
my $tmp = Path::Tiny->tempfile;
system('/usr/bin/curl', '-sLo', $tmp, $url);
my $d = Digest::SHA->new(256);
$d->addfile($tmp->stringify);
my $got = $d->hexdigest;
my $status = $wanted eq $got ? 'ok' : 'out-of-date';
print "$status: $arch $url\n\twanted $wanted\n\tactual $got\n\tfile $tmp";
}
exit(0);
}
## Multiplatform support
my @plats;
my $docker_cmd = 'docker';
if ($cfg{multiplatform}) {
$docker_cmd = 'nerdctl';
push @plats, '--platform', 'linux/arm64,linux/amd64';
print ">>>>>>>>>>> MULTIPLATFORM Build detected: @plats\n";
sleep(5);
}
for my $spec (@versions) {
my ($f, $t, $v, $x, $bi) = @$spec;
$bi = $f unless $bi;
my $baset = "$repo:$f-$t";
my $basev = "$repo:$f-$v";
my @tags;
for my $target (qw( devel build runtime reply )) {
my $tagt = "$baset-$target";
my $tagv = "$basev-$target";
my $tagx = $x ? "$target" : "";
my $tagl = $x && $target eq 'runtime' ? "latest" : "";
if ($cfg{filter} and $tagt !~ m/$cfg{filter}/) {
print ">>>>>>>> Skipped via filter '$cfg{filter}'\n";
next;
}
print ">>>> target $target, base $v: $tagt\n";
print ">>>> target $target, base $v: $tagv\n";
print ">>>> also tagged: $tagx\n" if $tagx;
print ">>>> also tagged: $tagl\n" if $tagl;
print "\n";
my @itags = ($tagt, $tagv);
push @itags, $tagx if $tagx;
push @itags, $tagl if $tagl;
push @itags, $baset if $target eq "devel";
my @cmd = ($docker_cmd, 'build');
push @cmd, '--progress', 'plain' if $cfg{debug};
push @cmd, @plats if @plats;
push @cmd, '--target' => $target;
push @cmd, '--file' => "Dockerfile.$f";
push @cmd, map { ('--tag', $_) } @itags;
push @cmd, '--label' => 'maintainer=Pedro Melo <[email protected]>';
push @cmd,
'--build-arg' => "BASE=$bi:$v",
'--build-arg' => "AWS_LAMBDA_RIE_URL_aarch64=$lambda_runtime_versions{aarch64}[0]",
'--build-arg' => "AWS_LAMBDA_RIE_SIG_aarch64=$lambda_runtime_versions{aarch64}[1]",
'--build-arg' => "AWS_LAMBDA_RIE_URL_x86_64=$lambda_runtime_versions{x86_64}[0]",
'--build-arg' => "AWS_LAMBDA_RIE_SIG_x86_64=$lambda_runtime_versions{x86_64}[1]";
push @cmd, '.';
my $err = my_system(@cmd);
die "FATAL: failed to build Docker image for target $target, base $v: $tagt\n" if $err;
push @tags, @itags;
if ($cfg{push}) {
my_system($docker_cmd, 'push', @plats, $_) for @tags;
@tags = ();
}
}
}
print "\n\n>>> DONE\n\n";
sub my_system {
print "\n\n>>>>>>>> Cmd: @_\n\n";
return system(@_);
}