Skip to content

Commit 190d981

Browse files
committed
generate.pl: Add Dockerfile changes for debug builds
- Install gdb - Set debugging flags - Slightly refactor Dockerfile template
1 parent d2d5fa2 commit 190d981

File tree

1 file changed

+25
-8
lines changed

1 file changed

+25
-8
lines changed

Diff for: generate.pl

+25-8
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,13 @@ sub die_with_sample {
7070
EOF
7171
chomp $docker_slim_run_purge;
7272

73+
my $docker_debug_run_install = <<'EOF';
74+
apt-get update \
75+
&& apt-get install -y --no-install-recommends \
76+
gdb
77+
EOF
78+
chomp $docker_debug_run_install;
79+
7380
my $config = do {
7481
open my $fh, '<', 'config.yml' or die "Couldn't open config";
7582
local $/;
@@ -152,7 +159,9 @@ sub die_with_sample {
152159

153160
$release->{extra_flags} ||= '';
154161

155-
$release->{image} = $build =~ /main/ ? 'buildpack-deps' : 'debian';
162+
$release->{image} = $build =~ /(main|debug)/ ? 'buildpack-deps' : 'debian';
163+
164+
my $debug_flags = $build =~ /debug/ ? '-Doptimize=-g -DEBUGGING=both' : '';
156165

157166
for my $debian_release (@{$release->{debian_release}}) {
158167

@@ -162,16 +171,24 @@ sub die_with_sample {
162171
$output =~ s/\{\{args\}\}/$builds{$build}/mg;
163172

164173
if ($build =~ /slim/) {
165-
$output =~ s/\{\{docker_slim_run_install\}\}/$docker_slim_run_install/mg;
166-
$output =~ s/\{\{docker_slim_run_purge\}\}/$docker_slim_run_purge/mg;
174+
$output =~ s/\{\{docker_run_install\}\}/$docker_slim_run_install/mg;
175+
$output =~ s/\{\{docker_run_purge\}\}/$docker_slim_run_purge/mg;
167176
$output =~ s/\{\{tag\}\}/$debian_release-slim/mg;
168177
}
178+
elsif ($build =~ /debug/) {
179+
$output =~ s/\{\{docker_run_install\}\}/$docker_debug_run_install/mg;
180+
$output =~ s/\{\{debug_flags\}\}/$debug_flags/mg;
181+
$output =~ s#\{\{docker_run_purge\}\}#rm -fr /var/cache/apt/* /var/lib/apt/lists/*#mg;
182+
$output =~ s/\{\{tag\}\}/$debian_release/mg;
183+
}
169184
else {
170-
$output =~ s/\{\{docker_slim_run_install\}\}/true/mg;
171-
$output =~ s/\{\{docker_slim_run_purge\}\}/true/mg;
185+
$output =~ s/\{\{docker_run_install\}\}/true/mg;
186+
$output =~ s/\{\{docker_run_purge\}\}/true/mg;
172187
$output =~ s/\{\{tag\}\}/$debian_release/mg;
173188
}
174189

190+
$output =~ s/ \{\{debug_flags\}\}//mg;
191+
175192
my $dir = sprintf "%i.%03i.%03i-%s-%s", ($release->{version} =~ /(\d+)\.(\d+)\.(\d+)/), $build, $debian_release;
176193

177194
mkdir $dir unless -d $dir;
@@ -292,7 +309,7 @@ =head1 DESCRIPTION
292309
{{docker_copy_perl_patch}}
293310
WORKDIR /usr/src/perl
294311
295-
RUN {{docker_slim_run_install}} \
312+
RUN {{docker_run_install}} \
296313
&& curl -fL {{url}} -o perl-{{version}}.tar.{{type}} \
297314
&& echo '{{sha256}} *perl-{{version}}.tar.{{type}}' | sha256sum --strict --check - \
298315
&& tar --strip-components=1 -xaf perl-{{version}}.tar.{{type}} -C /usr/src/perl \
@@ -301,7 +318,7 @@ =head1 DESCRIPTION
301318
&& gnuArch="$(dpkg-architecture --query DEB_BUILD_GNU_TYPE)" \
302319
&& archBits="$(dpkg-architecture --query DEB_BUILD_ARCH_BITS)" \
303320
&& archFlag="$([ "$archBits" = '64' ] && echo '-Duse64bitall' || echo '-Duse64bitint')" \
304-
&& ./Configure -Darchname="$gnuArch" "$archFlag" {{args}} {{extra_flags}} -des \
321+
&& ./Configure -Darchname="$gnuArch" "$archFlag" {{args}} {{extra_flags}} {{debug_flags}} -des \
305322
&& make -j$(nproc) \
306323
&& {{test}} \
307324
&& make install \
@@ -314,7 +331,7 @@ =head1 DESCRIPTION
314331
# sha256 checksum is from docker-perl team, cf https://github.com/docker-library/official-images/pull/12612#issuecomment-1158288299
315332
&& echo '{{cpm_dist_sha256}} */usr/local/bin/cpm' | sha256sum --strict --check - \
316333
&& chmod +x /usr/local/bin/cpm \
317-
&& {{docker_slim_run_purge}} \
334+
&& {{docker_run_purge}} \
318335
&& rm -fr /root/.cpanm /usr/src/perl /usr/src/{{cpanm_dist_name}}* /tmp/* \
319336
&& cpanm --version && cpm --version
320337

0 commit comments

Comments
 (0)