Skip to content

Commit e002a31

Browse files
authored
Add Dockerfile for binary-com's standard perl image (#1)
* Add Dockerfile for binary-com's standard perl image This is mostly derived from https://github.com/tm604/perl-docker with a few changes: - Use https://hub.docker.com/_/perl instead of building from debian:buster; this allows for source verification of both the Perl build and cpanm (which is already done on the official images) and a slightly slimmer build. - Forgo multi-stage build in favor of a smarter single-stage: we're due to install further dependencies on a later build trigger for derivative images anyway, so some core build essentials can be included here now for a batteries-included approach with less moving parts during the subsequent build triggers. - Add a sane `ENTRYPOINT` for correct behaviors when running on Kubernetes. * 📓 Dockerfile: Add maintainer label * 📓 Dockerfile: bump to Perl 5.32 * 📓 Add basic image build and test workflow * Dockerfile: apt cache support and rebase to debian:buster - Add support for using an apt cache/proxy during builds. - Rebase against debian:buster; we'd want to build our own perl that we can supply our own configuration flags in the future. - Since we build our own perl (and cpanm) ensure we're doing some basic source validation for the tarballs; embed the SHA256 sums for now, figure a better way later. * .github/workflows/test.yaml: Change image name, use proxy when able When using https://github.com/nektos/act for running tests locally, one can supply `$DEBIAN_PROXY` in .env file for act to use upon building the image. Also change the image name for consistency with Binary -> Deriv rebranding. * Dockerfile: Update maintainer label, factor perl/cpanm versions Use our DERIV author name on CPAN, and move perl/cpanm version info and checksums into environment variables for easy updating later.
1 parent 2e5cc59 commit e002a31

File tree

2 files changed

+96
-0
lines changed

2 files changed

+96
-0
lines changed

.github/workflows/test.yaml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: Build image
2+
3+
on:
4+
push:
5+
branches:
6+
- '**'
7+
tags-ignore:
8+
- '*'
9+
pull_request:
10+
11+
jobs:
12+
build-test:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/checkout@master
16+
- name: Build base perl image
17+
run: |
18+
docker version
19+
[ -n $DEBIAN_PROXY ] && docker_build_opts="--build-arg=DEBIAN_PROXY=${DEBIAN_PROXY}"
20+
docker build "$docker_build_opts" -t deriv/perl .
21+
- name: Inspect image creation and tag time
22+
run: |
23+
docker image inspect --format \'{{.Created}}\' deriv/perl
24+
docker image inspect --format \'{{.Metadata.LastTagTime}}\' deriv/perl

Dockerfile

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# This is the layer that can run things
2+
FROM debian:buster
3+
LABEL maintainer="Deriv Services Ltd. <[email protected]>"
4+
5+
# Some standard server-like config used everywhere
6+
ENV TZ=UTC
7+
ENV DEBIAN_FRONTEND=noninteractive
8+
ENV PERL_VERSION=5.32.0
9+
ENV PERL_SHA256=6f436b447cf56d22464f980fac1916e707a040e96d52172984c5d184c09b859b
10+
ENV CPANM_VERSION=1.7044
11+
ENV CPANM_SHA256=9b60767fe40752ef7a9d3f13f19060a63389a5c23acc3e9827e19b75500f81f3
12+
13+
# Use an apt-cacher-ng or similar proxy when available during builds
14+
ARG DEBIAN_PROXY
15+
16+
WORKDIR /usr/src/perl
17+
18+
RUN [ -n "$DEBIAN_PROXY" ] \
19+
&& (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) \
21+
|| echo "No local Debian proxy configured" \
22+
&& apt-get update \
23+
&& apt-get dist-upgrade -y -q --no-install-recommends \
24+
&& 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 \
27+
&& 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 \
31+
&& make -j$(nproc) \
32+
&& make install \
33+
&& cd /usr/src \
34+
&& curl -LO https://www.cpan.org/authors/id/M/MI/MIYAGAWA/App-cpanminus-${CPANM_VERSION}.tar.gz \
35+
&& 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 \
45+
&& mkdir -p /etc/ssh/ \
46+
&& ssh-keyscan github.com >> /etc/ssh/ssh_known_hosts \
47+
&& mkdir -p /app
48+
49+
WORKDIR /app/
50+
51+
ENV PATH="/opt/perl-${PERL_VERSION}/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin:/usr/local/sbin"
52+
53+
ONBUILD ADD cpanfile aptfile /app/
54+
55+
# Install everything in the aptfile first, as system deps, then
56+
# go through the CPAN deps. Once those are all done, remove anything
57+
# that we would have pulled in as a build dep (compilers, for example)
58+
# 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/
69+
70+
ENTRYPOINT [ "/usr/bin/dumb-init", "--" ]
71+
72+
CMD [ "perl", "app.pl" ]

0 commit comments

Comments
 (0)