99sub die_with_sample {
1010 die <<EOF ;
1111
12- The Releases.yaml file must look roughly like:
12+ The config.yml file must look roughly like:
1313
14- releases:
15- - version: 5.20.0
16- sha256: asdasdadas
14+ ---
15+ builds:
16+ - main
17+ - slim
1718
18- Where version is the version number of Perl and sha256 is the SHA256 of
19- the tar.bz2 file.
19+ options:
20+ common: "-Duseshrplib -Dvendorprefix=/usr/local"
21+ threaded: "-Dusethreads"
22+
23+ releases:
24+ - version: 5.20.0
25+ sha256: asdasdadas
26+
27+ Where "version" is the version number of Perl and "sha256" is the SHA256
28+ of the Perl distribution tarball.
2029
2130If needed or desired, extra_flags: can be added, which will be passed
2231verbatim to Configure.
2332
33+ Run "perldoc ./generate.pl" to read the complete documentation.
34+
2435EOF
2536}
2637
27- my $yaml = do {
28- open my $fh , " <" , " Releases.yaml" or die " Couldn't open releases" ;
38+ my $docker_slim_run_install = <<'EOF' ;
39+ apt-get update \
40+ && apt-get install -y --no-install-recommends \
41+ bzip2 \
42+ ca-certificates \
43+ # cpio \
44+ curl \
45+ dpkg-dev \
46+ # file \
47+ gcc \
48+ # g++ \
49+ # libbz2-dev \
50+ # libdb-dev \
51+ libc6-dev \
52+ # libgdbm-dev \
53+ # liblzma-dev \
54+ make \
55+ netbase \
56+ patch \
57+ # procps \
58+ # zlib1g-dev \
59+ xz-utils
60+ EOF
61+ chomp $docker_slim_run_install ;
62+
63+ my $docker_slim_run_purge = <<'EOF' ;
64+ savedPackages="make netbase" \
65+ && apt-mark auto '.*' > /dev/null \
66+ && apt-mark manual $savedPackages \
67+ && apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false \
68+ && rm -fr /var/cache/apt/* /var/lib/apt/lists/*
69+ EOF
70+ chomp $docker_slim_run_purge ;
71+
72+ my $config = do {
73+ open my $fh , ' <' , ' config.yml' or die " Couldn't open config" ;
2974 local $/ ;
3075 Load <$fh >;
3176};
@@ -35,43 +80,41 @@ sub die_with_sample {
3580 <DATA >;
3681};
3782
38- my $common = join " " , qw{
39- -Duseshrplib
40- -Dvendorprefix=/usr/local
41- } ;
42-
43- my %builds = (
44- " 64bit" => " $common " ,
45- " 64bit,threaded" => " -Dusethreads $common " ,
46- );
83+ my %builds ;
4784
4885# sha256 taken from http://www.cpan.org/authors/id/M/MI/MIYAGAWA/CHECKSUMS
4986my %cpanm = (
50- name => " App-cpanminus-1.7044" ,
51- url => " http://www.cpan.org/authors/id/M/MI/MIYAGAWA/App-cpanminus-1.7044.tar.gz" ,
52- sha256 => " 9b60767fe40752ef7a9d3f13f19060a63389a5c23acc3e9827e19b75500f81f3" ,
87+ name => " App-cpanminus-1.7044" ,
88+ url => " http://www.cpan.org/authors/id/M/MI/MIYAGAWA/App-cpanminus-1.7044.tar.gz" ,
89+ sha256 => " 9b60767fe40752ef7a9d3f13f19060a63389a5c23acc3e9827e19b75500f81f3" ,
5390);
5491
55- die_with_sample unless defined $yaml -> {releases };
56- die_with_sample unless ref $yaml -> {releases } eq " ARRAY" ;
92+ die_with_sample unless defined $config -> {releases };
93+ die_with_sample unless ref $config -> {releases } eq " ARRAY" ;
5794
58- if (! -d " downloads" ) {
95+ if (!-d " downloads" ) {
5996 mkdir " downloads" or die " Couldn't create a downloads directory" ;
6097}
6198
62- for my $release (@{$yaml -> {releases }}) {
63- do { die_with_sample unless $release -> {$_ }} for (qw( version sha256) );
99+ for my $build (@{$config -> {builds }}) {
100+ $builds {$build } = $config -> {options }{common };
101+ $builds {" $build ,threaded" } = " @{$config ->{options}}{qw/threaded common/}" ;
102+ }
103+
104+ for my $release (@{$config -> {releases }}) {
105+ do { die_with_sample unless $release -> {$_ } }
106+ for (qw( version sha256) );
64107
65108 die " Bad version: $release ->{version}" unless $release -> {version } =~ / \A 5\.\d +\.\d +\Z / ;
66109
67110 my $patch ;
68111 $release -> {type } ||= ' bz2' ;
69112 my $file = " perl-$release ->{version}.tar.$release ->{type}" ;
70- my $url = " https://www.cpan.org/src/5.0/$file " ;
71- if (-f " downloads/$file " &&
72- ` sha256sum downloads/ $file ` =~ / ^ \Q $release ->{sha256} \E\s + \Q downloads \/ $ file\E / ) {
73- print " Skipping download of $file , already current \n " ;
74- } else {
113+ my $url = " https://www.cpan.org/src/5.0/$file " ;
114+ if (-f " downloads/$file " && ` sha256sum downloads/ $file ` =~ / ^ \Q $release ->{sha256} \E\s + \Q downloads \/ $file \E / ) {
115+ print " Skipping download of $ file, already current \n " ;
116+ }
117+ else {
75118 print " Downloading $url \n " ;
76119 getstore($url , " downloads/$file " );
77120 }
@@ -95,20 +138,37 @@ sub die_with_sample {
95138 die " Couldn't create a Devel::PatchPerl patch for $release ->{version}" if $? != 0;
96139 }
97140
98- $release -> {url } = $url ;
99- $release -> {extra_flags } = " " unless defined $release -> {extra_flags };
100- $release -> {_tag } = $release -> {buildpack_deps } || " stretch" ;
101- $release -> {" cpanm_dist_$_ " } = $cpanm {$_ } for keys %cpanm ;
141+ for my $build (keys %builds ) {
142+ $release -> {url } = $url ;
143+ $release -> {" cpanm_dist_$_ " } = $cpanm {$_ } for keys %cpanm ;
144+
145+ $release -> {extra_flags } ||= ' ' ;
146+ $release -> {debian_release } ||= ' stretch' ;
147+
148+ if ($build =~ / main/ ) {
149+ $release -> {image } = ' buildpack-deps' ;
150+ $release -> {tag } = $release -> {debian_release };
151+ }
152+ else {
153+ $release -> {image } = ' debian' ;
154+ $release -> {tag } = " @{[ $release ->{debian_release} ]}-slim" ;
155+ }
102156
103- for my $config (keys %builds ) {
104157 my $output = $template ;
105158 $output =~ s /\{\{ $_\}\} / $release ->{$_ }/ mg
106- for (qw( version pause extra_flags sha256 type url _tag cpanm_dist_name cpanm_dist_url cpanm_dist_sha256) );
107- $output =~ s /\{\{ args\}\} / $builds {$config }/ mg ;
159+ for (qw( version pause extra_flags sha256 type url image tag cpanm_dist_name cpanm_dist_url cpanm_dist_sha256) );
160+ $output =~ s /\{\{ args\}\} / $builds {$build }/ mg ;
108161
109- my $dir = sprintf " %i .%03i.%03i-%s " ,
110- ($release -> {version } =~ / (\d +)\. (\d +)\. (\d +)/ ),
111- $config ;
162+ if ($build =~ / slim/ ) {
163+ $output =~ s /\{\{ docker_slim_run_install\}\} / $docker_slim_run_install / mg ;
164+ $output =~ s /\{\{ docker_slim_run_purge\}\} / $docker_slim_run_purge / mg ;
165+ }
166+ else {
167+ $output =~ s /\{\{ docker_slim_run_install\}\} / true/ mg ;
168+ $output =~ s /\{\{ docker_slim_run_purge\}\} / true/ mg ;
169+ }
170+
171+ my $dir = sprintf " %i .%03i.%03i-%s " , ($release -> {version } =~ / (\d +)\. (\d +)\. (\d +)/ ), $build ;
112172
113173 mkdir $dir unless -d $dir ;
114174
@@ -119,11 +179,13 @@ sub die_with_sample {
119179 }
120180
121181 if (defined $release -> {test_parallel } && $release -> {test_parallel } eq " no" ) {
122- $output =~ s /\{\{ test\}\} / make test_harness/ ;
123- } elsif (!defined $release -> {test_parallel } || $release -> {test_parallel } eq " yes" ) {
124- $output =~ s /\{\{ test\}\} / TEST_JOBS=\$ (nproc) make test_harness/ ;
125- } else {
126- die " test_parallel was provided for $release ->{version} but is invalid; should be 'yes' or 'no'\n " ;
182+ $output =~ s /\{\{ test\}\} / make test_harness/ ;
183+ }
184+ elsif (!defined $release -> {test_parallel } || $release -> {test_parallel } eq " yes" ) {
185+ $output =~ s /\{\{ test\}\} / TEST_JOBS=\$ (nproc) make test_harness/ ;
186+ }
187+ else {
188+ die " test_parallel was provided for $release ->{version} but is invalid; should be 'yes' or 'no'\n " ;
127189 }
128190
129191 open my $dockerfile , " >" , " $dir /Dockerfile" or die " Couldn't open $dir /Dockerfile for writing" ;
@@ -136,17 +198,18 @@ sub die_with_sample {
136198
137199=head1 NAME
138200
139- generate.pl
201+ generate.pl - generate Dockerfiles for Perl
140202
141203=head1 SYNOPSIS
142204
143- generate.pl is a little helper script to reinitalize the Dockerfiles from a YAML file.
205+ cd /path/to/docker-perl
206+ ./generate.pl
144207
145208=head1 DESCRIPTION
146209
147- generate.pl is meant to be run from the actual repo directory, with a Releases.yaml file
148- correctly configured. It starts with a 'releases' key, which contains a list of releases,
149- each with the following keys:
210+ generate.pl is meant to be run from the actual repo directory, with a
211+ config.yml file correctly configured. It contains with a 'releases'
212+ key, which contains a list of releases, each with the following keys:
150213
151214=over 4
152215
@@ -160,23 +223,27 @@ =head1 DESCRIPTION
160223
161224=item sha256
162225
163- The SHA-256 of the C<.tar.bz2 > file for that release.
226+ The SHA-256 of the tarball for that release.
227+
228+ =back
164229
165230=item OPTIONAL
166231
167232=over 4
168233
169- =item buildpack_deps
234+ =item debian_release
170235
171- The Docker L<buildpack-deps|https://hub.docker.com/_/buildpack-deps>
172- image tag which this Perl would build on.
236+ The Docker image tag which this Perl would build on, common to both the
237+ L<https://hub.docker.com/_/buildpack-deps|buildpack-deps> and
238+ L<https://hub.docker.com/_/debian|debian> Docker images.
173239
174- Defaults: C<stretch >
240+ Defaults: C<stretch > for C<main > builds, C<stretch-slim > for C<slim >
241+ builds.
175242
176243=item extra_flags
177244
178- Additional text to pass to C<Configure > . At the moment, this is necessary for
179- 5.18.x so that it can get the C<-fwrapv > flag.
245+ Additional text to pass to C<Configure > . At the moment, this is
246+ necessary for 5.18.x so that it can get the C<-fwrapv > flag.
180247
181248Default: C<"" >
182249
@@ -195,13 +262,14 @@ =head1 DESCRIPTION
195262=cut
196263
197264__DATA__
198- FROM buildpack-deps :{{_tag }}
265+ FROM {{image}} :{{tag }}
199266LABEL maintainer="Peter Martini <PeterCMartini@GMail.com>, Zak B. Elep <zakame@cpan.org>"
200267
201268COPY *.patch /usr/src/perl/
202269WORKDIR /usr/src/perl
203270
204- RUN curl -SL {{url}} -o perl-{{version}}.tar.{{type}} \
271+ RUN {{docker_slim_run_install}} \
272+ && curl -SL {{url}} -o perl-{{version}}.tar.{{type}} \
205273 && echo '{{sha256}} *perl-{{version}}.tar.{{type}}' | sha256sum -c - \
206274 && tar --strip-components=1 -xaf perl-{{version}}.tar.{{type}} -C /usr/src/perl \
207275 && rm perl-{{version}}.tar.{{type}} \
@@ -217,6 +285,7 @@ =head1 DESCRIPTION
217285 && curl -LO {{cpanm_dist_url}} \
218286 && echo '{{cpanm_dist_sha256}} *{{cpanm_dist_name}}.tar.gz' | sha256sum -c - \
219287 && tar -xzf {{cpanm_dist_name}}.tar.gz && cd {{cpanm_dist_name}} && perl bin/cpanm . && cd /root \
288+ && {{docker_slim_run_purge}} \
220289 && rm -fr ./cpanm /root/.cpanm /usr/src/perl /usr/src/{{cpanm_dist_name}}* /tmp/*
221290
222291WORKDIR /root
0 commit comments