@@ -70,6 +70,13 @@ sub die_with_sample {
7070EOF
7171chomp $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+
7380my $config = do {
7481 open my $fh , ' <' , ' config.yml' or die " Couldn't open config" ;
7582 local $/ ;
@@ -152,7 +159,10 @@ 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+ # leading space is important for reducing diff against non-debug Dockerfiles
165+ my $debug_flags = $build =~ / debug/ ? ' -Doptimize=-g -DEBUGGING=both' : ' ' ;
156166
157167 for my $debian_release (@{$release -> {debian_release }}) {
158168
@@ -162,16 +172,25 @@ sub die_with_sample {
162172 $output =~ s /\{\{ args\}\} / $builds {$build }/ mg ;
163173
164174 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 ;
175+ $output =~ s /\{\{ docker_run_install \}\} / $docker_slim_run_install / mg ;
176+ $output =~ s /\{\{ docker_run_purge \}\} / $docker_slim_run_purge / mg ;
167177 $output =~ s /\{\{ tag\}\} / $debian_release -slim/ mg ;
168178 }
179+ elsif ($build =~ / debug/ ) {
180+ $output =~ s /\{\{ docker_run_install\}\} / $docker_debug_run_install / mg ;
181+ # leading space important to reduce diffs against non-debug Dockerfiles
182+ $output =~ s / \{\{ debug_flags\}\} / $debug_flags / mg ;
183+ $output =~ s #\{\{ docker_run_purge\}\} # rm -fr /var/cache/apt/* /var/lib/apt/lists/*# mg ;
184+ $output =~ s /\{\{ tag\}\} / $debian_release / mg ;
185+ }
169186 else {
170- $output =~ s /\{\{ docker_slim_run_install \}\} / true/ mg ;
171- $output =~ s /\{\{ docker_slim_run_purge \}\} / true/ mg ;
187+ $output =~ s /\{\{ docker_run_install \}\} / true/ mg ;
188+ $output =~ s /\{\{ docker_run_purge \}\} / true/ mg ;
172189 $output =~ s /\{\{ tag\}\} / $debian_release / mg ;
173190 }
174191
192+ $output =~ s / \{\{ debug_flags\}\} // mg ;
193+
175194 my $dir = sprintf " %i .%03i.%03i-%s -%s " , ($release -> {version } =~ / (\d +)\. (\d +)\. (\d +)/ ), $build , $debian_release ;
176195
177196 mkdir $dir unless -d $dir ;
@@ -292,7 +311,7 @@ =head1 DESCRIPTION
292311{{docker_copy_perl_patch}}
293312WORKDIR /usr/src/perl
294313
295- RUN {{docker_slim_run_install }} \
314+ RUN {{docker_run_install }} \
296315 && curl -fL {{url}} -o perl-{{version}}.tar.{{type}} \
297316 && echo '{{sha256}} *perl-{{version}}.tar.{{type}}' | sha256sum --strict --check - \
298317 && tar --strip-components=1 -xaf perl-{{version}}.tar.{{type}} -C /usr/src/perl \
@@ -301,7 +320,7 @@ =head1 DESCRIPTION
301320 && gnuArch="$(dpkg-architecture --query DEB_BUILD_GNU_TYPE)" \
302321 && archBits="$(dpkg-architecture --query DEB_BUILD_ARCH_BITS)" \
303322 && archFlag="$([ "$archBits" = '64' ] && echo '-Duse64bitall' || echo '-Duse64bitint')" \
304- && ./Configure -Darchname="$gnuArch" "$archFlag" {{args}} {{extra_flags}} -des \
323+ && ./Configure -Darchname="$gnuArch" "$archFlag" {{args}} {{extra_flags}} {{debug_flags}} -des \
305324 && make -j$(nproc) \
306325 && {{test}} \
307326 && make install \
@@ -314,7 +333,7 @@ =head1 DESCRIPTION
314333 # sha256 checksum is from docker-perl team, cf https://github.com/docker-library/official-images/pull/12612#issuecomment-1158288299
315334 && echo '{{cpm_dist_sha256}} */usr/local/bin/cpm' | sha256sum --strict --check - \
316335 && chmod +x /usr/local/bin/cpm \
317- && {{docker_slim_run_purge }} \
336+ && {{docker_run_purge }} \
318337 && rm -fr /root/.cpanm /usr/src/perl /usr/src/{{cpanm_dist_name}}* /tmp/* \
319338 && cpanm --version && cpm --version
320339
0 commit comments