Skip to content

Commit a66405d

Browse files
committed
Build a debugging version of Perl
Create a debugging version of Perl with gdb installed so one can take an exact copy of the image with all the symbol tables etc etc.
1 parent 1d9b750 commit a66405d

File tree

2 files changed

+39
-6
lines changed

2 files changed

+39
-6
lines changed

config.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
builds:
33
- main
44
- slim
5+
- debug
56

67
options:
78
common: "-Duseshrplib -Dvendorprefix=/usr/local"

generate.pl

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,19 @@ sub die_with_sample {
6969
EOF
7070
chomp $docker_slim_run_purge;
7171

72+
my $docker_rm_sources = <<'OEF';
73+
rm -fr ./cpanm /root/.cpanm /usr/src/perl /usr/src/{{cpanm_dist_name}}* /tmp/*
74+
OEF
75+
chomp $docker_rm_sources;
76+
77+
my $docker_rm_sources_install = <<'OEF';
78+
rm -fr ./cpanm /root/.cpanm /tmp/* /usr/src/{{cpanm_dist_name}}* \
79+
&& apt-get update \
80+
&& apt-get install --no-install-recommends -y gdb \
81+
&& rm -fr /var/cache/apt/* /var/lib/apt/lists/*
82+
OEF
83+
chomp $docker_rm_sources_install;
84+
7285
my $config = do {
7386
open my $fh, '<', 'config.yml' or die "Couldn't open config";
7487
local $/;
@@ -144,20 +157,24 @@ sub die_with_sample {
144157

145158
$release->{extra_flags} ||= '';
146159
$release->{debian_release} ||= 'stretch';
160+
my $debug_flags = '';
147161

148-
if ($build =~ /main/) {
162+
if ($build =~ /(main|debug)/) {
149163
$release->{image} = 'buildpack-deps';
150164
$release->{tag} = $release->{debian_release};
165+
if ($build =~ /debug/) {
166+
# The beginning space here is important, it is here to reduce the
167+
# size of the diff size for the non-debug Dockerfiles.
168+
# Older versions may require -Doptimise=-g
169+
$debug_flags = " -Doptimise=-g -DEBUGGING=both";
170+
}
151171
}
152172
else {
153173
$release->{image} = 'debian';
154174
$release->{tag} = "@{[ $release->{debian_release} ]}-slim";
155175
}
156176

157177
my $output = $template;
158-
$output =~ s/\{\{$_\}\}/$release->{$_}/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;
161178

162179
if ($build =~ /slim/) {
163180
$output =~ s/\{\{docker_slim_run_install\}\}/$docker_slim_run_install/mg;
@@ -168,6 +185,21 @@ sub die_with_sample {
168185
$output =~ s/\{\{docker_slim_run_purge\}\}/true/mg;
169186
}
170187

188+
if ($build eq 'debug') {
189+
$output =~ s/\{\{docker_rm_sources\}\}/$docker_rm_sources_install/mg;
190+
}
191+
else {
192+
$output =~ s/\{\{docker_rm_sources\}\}/$docker_rm_sources/mg;
193+
}
194+
195+
$output =~ s/\{\{$_\}\}/$release->{$_}/mg
196+
for (qw(version pause extra_flags sha256 type url image tag cpanm_dist_name cpanm_dist_url cpanm_dist_sha256));
197+
$output =~ s/\{\{args\}\}/$builds{$build}/mg;
198+
199+
# The beginning space here is important, it is here to reduce the
200+
# size of the diff size for the non-debug Dockerfiles.
201+
$output =~ s/ \{\{debug_flags\}\}/$debug_flags/mg;
202+
171203
my $dir = sprintf "%i.%03i.%03i-%s", ($release->{version} =~ /(\d+)\.(\d+)\.(\d+)/), $build;
172204

173205
mkdir $dir unless -d $dir;
@@ -277,7 +309,7 @@ =head1 DESCRIPTION
277309
&& gnuArch="$(dpkg-architecture --query DEB_BUILD_GNU_TYPE)" \
278310
&& archBits="$(dpkg-architecture --query DEB_BUILD_ARCH_BITS)" \
279311
&& archFlag="$([ "$archBits" = '64' ] && echo '-Duse64bitall' || echo '-Duse64bitint')" \
280-
&& ./Configure -Darchname="$gnuArch" "$archFlag" {{args}} {{extra_flags}} -des \
312+
&& ./Configure -Darchname="$gnuArch" "$archFlag" {{args}} {{extra_flags}} {{debug_flags}} -des \
281313
&& make -j$(nproc) \
282314
&& {{test}} \
283315
&& make install \
@@ -286,7 +318,7 @@ =head1 DESCRIPTION
286318
&& echo '{{cpanm_dist_sha256}} *{{cpanm_dist_name}}.tar.gz' | sha256sum -c - \
287319
&& tar -xzf {{cpanm_dist_name}}.tar.gz && cd {{cpanm_dist_name}} && perl bin/cpanm . && cd /root \
288320
&& {{docker_slim_run_purge}} \
289-
&& rm -fr ./cpanm /root/.cpanm /usr/src/perl /usr/src/{{cpanm_dist_name}}* /tmp/*
321+
&& {{docker_rm_sources}}
290322
291323
WORKDIR /root
292324

0 commit comments

Comments
 (0)