Skip to content

Commit 10c8e8e

Browse files
tom-binaryzakame
andauthored
docker/perl_dzil (#3)
* Add dzil recipe This also serves as a very simple example of using our base perl image. * Dockerfile: a couple more fixes - Check aptfile for readability, not size, so it can be skipped if the file doesn't exist. - Do not auto-remove removable packages; removing them doesn't affect the overall image size anyway, and some packages (like runtime libraries auto-installed by their -dev counterparts) can be inadventently removed and break CPAN modules. * .github/workflows/test.yaml: Test dzil image as well This probably needs its own workflow later, but for now just do a quick build and check using the dzil image. * Dockerfile: invoke dumb-init on cpanm ONBUILD for signals handling This is important for cross-compile builds (e.g. amd64 to arm64) as cpanm/perl won't handle signals without defining them in the code, cf Perl/docker-perl#44. Without this, cross-compiles will appear to stall. * Move apt/cpan setup to script so we can call in sub-images too * dzil build should pull in authordeps and apply Pod::Inherit patch for the DERIV author bundle * Include Pod::Inherit @inc patch * Include CircleCI config as well * Update CircleCI docker orb * Latest orb does not have artifacts path for hadolint * List of dockerfiles now colon-separated * Switch to orb versions of build+publish * Clean up CircleCI config - no point running hadolint everywhere * Apply hadolint recommendations * Filter out some more hadolint checks * Try to set WORKDIR * Attempt to make job steps sequential * Apply `perl` context * CircleCI orb has several bugs, so the current version is not usable * Report $DOCKER_LOGIN to test context-is-broken hypothesis Co-authored-by: Zak B. Elep <[email protected]>
1 parent e002a31 commit 10c8e8e

File tree

8 files changed

+171
-28
lines changed

8 files changed

+171
-28
lines changed

.circleci/config.yml

+96
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
version: 2.1
2+
orbs:
3+
docker: circleci/[email protected]
4+
jobs:
5+
perl:
6+
executor: docker/docker
7+
steps:
8+
- setup_remote_docker
9+
- checkout
10+
- run:
11+
command: |
12+
echo Log in as "$DOCKER_LOGIN"
13+
echo "$DOCKER_PASSWORD" | docker login --username "$DOCKER_LOGIN" --password-stdin
14+
docker build -t deriv/perl .
15+
name: Build deriv/perl
16+
dzil:
17+
executor: docker/docker
18+
steps:
19+
- setup_remote_docker
20+
- checkout
21+
- run:
22+
command: |
23+
echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_LOGIN" --password-stdin
24+
cd dzil && docker build -t deriv/dzil .
25+
name: Build deriv/dzil
26+
workflows:
27+
version: 2
28+
build-workflow:
29+
jobs:
30+
- perl:
31+
context: perl
32+
- dzil:
33+
context: perl
34+
requires:
35+
- perl
36+
- docker/hadolint:
37+
dockerfiles: Dockerfile:dzil/Dockerfile
38+
# Don't pin apt versions, we'll never remember to update them
39+
ignore-rules: DL3008,SC2046,DL3003,DL4006,DL3006
40+
merged:
41+
jobs:
42+
- docker/publish:
43+
deploy: true
44+
image: deriv/perl
45+
filters:
46+
branches:
47+
only: /^master$/
48+
- docker/publish:
49+
deploy: true
50+
image: deriv/dzil
51+
path: dzil
52+
filters:
53+
branches:
54+
only: /^master$/
55+
- docker/hadolint:
56+
dockerfiles: Dockerfile:dzil/Dockerfile
57+
# Don't pin apt versions, we'll never remember to update them
58+
ignore-rules: DL3008,SC2046,DL3003,DL4006,DL3006
59+
filters:
60+
branches:
61+
only: /^master$/
62+
tagged:
63+
jobs:
64+
- docker/publish:
65+
deploy: true
66+
image: deriv/perl
67+
filters:
68+
branches:
69+
only: /^master$/
70+
- docker/publish:
71+
deploy: true
72+
image: deriv/dzil
73+
path: dzil
74+
filters:
75+
branches:
76+
only: /^master$/
77+
daily:
78+
jobs:
79+
- docker/publish:
80+
deploy: false
81+
image: deriv/perl
82+
- docker/publish:
83+
deploy: false
84+
image: deriv/dzil
85+
path: dzil
86+
- docker/hadolint:
87+
dockerfiles: Dockerfile:dzil/Dockerfile
88+
# Don't pin apt versions, we'll never remember to update them
89+
ignore-rules: DL3008,SC2046,DL3003,DL4006,DL3006
90+
triggers:
91+
- schedule:
92+
cron: 05 19 * * *
93+
filters:
94+
branches:
95+
only:
96+
- master

.github/workflows/test.yaml

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Build image
1+
name: Build images
22

33
on:
44
push:
@@ -13,12 +13,15 @@ jobs:
1313
runs-on: ubuntu-latest
1414
steps:
1515
- uses: actions/checkout@master
16-
- name: Build base perl image
16+
- name: Build images
1717
run: |
1818
docker version
1919
[ -n $DEBIAN_PROXY ] && docker_build_opts="--build-arg=DEBIAN_PROXY=${DEBIAN_PROXY}"
2020
docker build "$docker_build_opts" -t deriv/perl .
21+
cd dzil && docker build "$docker_build_opts" -t deriv/dzil .
2122
- name: Inspect image creation and tag time
2223
run: |
2324
docker image inspect --format \'{{.Created}}\' deriv/perl
2425
docker image inspect --format \'{{.Metadata.LastTagTime}}\' deriv/perl
26+
docker image inspect --format \'{{.Created}}\' deriv/dzil
27+
docker image inspect --format \'{{.Metadata.LastTagTime}}\' deriv/dzil

Dockerfile

+17-26
Original file line numberDiff line numberDiff line change
@@ -12,60 +12,51 @@ ENV CPANM_SHA256=9b60767fe40752ef7a9d3f13f19060a63389a5c23acc3e9827e19b75500f81f
1212

1313
# Use an apt-cacher-ng or similar proxy when available during builds
1414
ARG DEBIAN_PROXY
15+
ARG HTTP_PROXY
1516

1617
WORKDIR /usr/src/perl
1718

1819
RUN [ -n "$DEBIAN_PROXY" ] \
1920
&& (echo "Acquire::http::Proxy \"http://$DEBIAN_PROXY\";" > /etc/apt/apt.conf.d/30proxy) \
20-
&& (echo "Acquire::http::Proxy::ppa.launchpad.net DIRECT;" >> /etc/apt/apt.conf.d/30proxy) \
2121
|| echo "No local Debian proxy configured" \
2222
&& apt-get update \
2323
&& apt-get dist-upgrade -y -q --no-install-recommends \
2424
&& apt-get install -y -q --no-install-recommends \
25-
git openssh-client curl socat ca-certificates gcc make libc6-dev libssl-dev zlib1g-dev xz-utils dumb-init \
26-
&& curl -SL https://www.cpan.org/src/5.0/perl-${PERL_VERSION}.tar.xz -o perl-${PERL_VERSION}.tar.xz \
25+
git openssh-client curl socat ca-certificates gcc make libc6-dev libssl-dev zlib1g-dev xz-utils dumb-init patch \
26+
&& curl -SL https://www.cpan.org/src/5.0/"perl-${PERL_VERSION}".tar.xz -o "perl-${PERL_VERSION}".tar.xz \
2727
&& echo "${PERL_SHA256} *perl-${PERL_VERSION}.tar.xz" | sha256sum -c - \
28-
&& tar --strip-components=1 -xaf perl-${PERL_VERSION}.tar.xz -C /usr/src/perl \
29-
&& rm perl-${PERL_VERSION}.tar.xz \
30-
&& ./Configure -Duse64bitall -Duseshrplib -Dprefix=/opt/perl-${PERL_VERSION} -Dman1dir=none -Dman3dir=none -des \
28+
&& tar --strip-components=1 -xaf "perl-${PERL_VERSION}".tar.xz -C /usr/src/perl \
29+
&& rm "perl-${PERL_VERSION}".tar.xz \
30+
&& ./Configure -Duse64bitall -Duseshrplib -Dprefix=/opt/"perl-${PERL_VERSION}" -Dman1dir=none -Dman3dir=none -des \
3131
&& make -j$(nproc) \
3232
&& make install \
3333
&& cd /usr/src \
3434
&& curl -LO https://www.cpan.org/authors/id/M/MI/MIYAGAWA/App-cpanminus-${CPANM_VERSION}.tar.gz \
3535
&& echo "${CPANM_SHA256} *App-cpanminus-${CPANM_VERSION}.tar.gz" | sha256sum -c - \
36-
&& tar -xzf App-cpanminus-${CPANM_VERSION}.tar.gz \
37-
&& rm App-cpanminus-${CPANM_VERSION}.tar.gz \
38-
&& cd App-cpanminus-${CPANM_VERSION} && /opt/perl-${PERL_VERSION}/bin/perl bin/cpanm . \
39-
&& rm -rf /var/lib/apt/lists/* /var/cache/apt/* \
40-
&& rm -fr ./cpanm /root/.cpanm /usr/src/perl /usr/src/App-cpanminus-${CPANM_VERSION}* /tmp/* \
41-
# Locale support is probably quite useful in some cases, but
42-
# let's let individual builds decide that via aptfile config
43-
# && echo 'en_US.UTF-8 UTF-8' > /etc/locale.gen \
44-
# && locale-gen \
36+
&& tar -xzf "App-cpanminus-${CPANM_VERSION}".tar.gz \
37+
&& rm "App-cpanminus-${CPANM_VERSION}".tar.gz \
38+
&& cd "App-cpanminus-${CPANM_VERSION}" && /opt/"perl-${PERL_VERSION}"/bin/perl bin/cpanm . \
39+
&& rm -rf /var/lib/apt/lists/* /var/cache/apt/* /etc/apt/apt.conf.d/30proxy \
40+
&& rm -fr ./cpanm /root/.cpanm /usr/src/perl /usr/src/"App-cpanminus-${CPANM_VERSION}"* /tmp/* \
4541
&& mkdir -p /etc/ssh/ \
4642
&& ssh-keyscan github.com >> /etc/ssh/ssh_known_hosts \
4743
&& mkdir -p /app
4844

4945
WORKDIR /app/
46+
COPY prepare-apt-cpan.sh /usr/local/bin/
5047

5148
ENV PATH="/opt/perl-${PERL_VERSION}/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin:/usr/local/sbin"
5249

53-
ONBUILD ADD cpanfile aptfile /app/
50+
ONBUILD ARG HTTP_PROXY
51+
ONBUILD WORKDIR /app/
52+
ONBUILD COPY cpanfile aptfile /app/
5453

5554
# Install everything in the aptfile first, as system deps, then
5655
# go through the CPAN deps. Once those are all done, remove anything
5756
# that we would have pulled in as a build dep (compilers, for example)
5857
# unless they happened to be in the aptfile.
59-
ONBUILD RUN if [ -s /app/aptfile ]; then \
60-
apt-get -y -q update \
61-
&& apt-get -y -q --no-install-recommends install $(cat /app/aptfile); \
62-
fi \
63-
&& cpanm --notest --quiet --installdeps --with-recommends . \
64-
&& apt-get purge -y -q $(perl -le'@seen{split " ", "" . do { local ($/, @ARGV) = (undef, "/app/aptfile"); <> }} = () if -r "aptfile"; print for grep { !exists $seen{$_} } qw(make gcc git openssh-client libc6-dev libssl-dev zlib1g-dev)') \
65-
&& apt-get -y --purge autoremove \
66-
&& rm -rf /var/lib/apt/lists/* /var/cache/apt/* /root/.cpanm /tmp/*
67-
68-
ONBUILD ADD . /app/
58+
ONBUILD RUN prepare-apt-cpan.sh
59+
ONBUILD COPY . /app/
6960

7061
ENTRYPOINT [ "/usr/bin/dumb-init", "--" ]
7162

dzil/Dockerfile

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
ARG HTTP_PROXY
2+
FROM deriv/perl
3+
COPY pod-inherit.patch .
4+
RUN patch -p0 $(perldoc -lm Pod::Inherit) < pod-inherit.patch
5+
ONBUILD COPY cpanfile aptfile dist.ini /app/
6+
ONBUILD RUN prepare-apt-cpan.sh \
7+
&& dzil authordeps | cpanm -n
8+
ONBUILD COPY . /app/

dzil/aptfile

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
libncurses-dev
2+
libreadline-dev
3+
git
4+
gcc
5+
make
6+
libc6-dev
7+
openssh-client
8+
patch

dzil/cpanfile

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
requires 'Dist::Zilla::PluginBundle::Author::DERIV';

dzil/pod-inherit.patch

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
--- a/Pod/Inherit.pm 2020-04-03 21:58:36.470197738 +0800
2+
+++ b/Pod/Inherit.pm 2014-06-13 10:45:18.000000000 +0800
3+
@@ -909,7 +909,7 @@
4+
unless (exists $INC{$class_as_filename}) {
5+
# Still no source? Great... we'll have to pray that require will work...
6+
print "Still no source found for $classname; forced to use 'require'\n" if ($DEBUG && !$src);
7+
- my $did_it = $src ? do $src : Class::Load::load_optional_class($classname);
8+
+ my $did_it = $src ? do "./$src" : Class::Load::load_optional_class($classname);
9+
unless ($did_it) {
10+
my $err = $@;
11+
$err =~ s/ \(\@INC contains: .*\)//;
12+
@@ -994,7 +994,10 @@
13+
$src = Path::Class::File->new($src)->as_foreign('Unix');
14+
15+
return <<__END_HEADER__;
16+
+=encoding utf8
17+
+
18+
=for comment POD_DERIVED_INDEX_GENERATED
19+
+
20+
The following documentation is automatically generated. Please do not edit
21+
this file, but rather the original, inline with $classname
22+
at $src

prepare-apt-cpan.sh

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/bin/bash
2+
# Prepare dependencies by installing anything found in `aptfile`
3+
# then applying CPAN modules from `cpanfile`.
4+
5+
set -e
6+
7+
if [ -r /app/aptfile ]; then
8+
apt-get -y -q update
9+
apt-get -y -q --no-install-recommends install $(cat /app/aptfile)
10+
fi
11+
cpanm --notest --installdeps .
12+
apt-get purge -y -q $(perl -le'@seen{split " ", "" . do { local ($/, @ARGV) = (undef, "/app/aptfile"); <> }} = () if -r "aptfile"; print for grep { !exists $seen{$_} } qw(make gcc git openssh-client libc6-dev libssl-dev zlib1g-dev patch)')
13+
rm -rf /var/lib/apt/lists/* /var/cache/apt/* /root/.cpanm /tmp/*
14+

0 commit comments

Comments
 (0)