Skip to content

Commit 71fc8bd

Browse files
huddlejtsibley
authored andcommitted
Replace Alpine-based image with a Debian-based image
Alpine Linux uses musl libc instead of glibc which means it cannot use most pre-built Python wheels for glibc-based Linux distributions [1]. As a result, Python packages need to be built from source, leading to longer build times and increased complexity in the Dockerfile for more complex packages. For complex packages like opencv-python, building from source is especially non-trivial. This commit ports the existing Alpine-based Dockerfile to a minimal Debian-based file with pre-installed Python 3 (the official Python Docker image) and removes dependencies that were originally required to build Python packages from sources (e.g., cvxopt) where installation from a wheel is now possible. This commit also removes all explicit references to Python 2 dependencies, as fauna is compatible enough with Python 3 for downloading to work and sacra was previously removed. [1] docker-library/docs#904
1 parent 04da879 commit 71fc8bd

File tree

1 file changed

+29
-67
lines changed

1 file changed

+29
-67
lines changed

Dockerfile

Lines changed: 29 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -5,30 +5,24 @@
55
# image with tools only needed during the image build.
66

77
# First build the temporary image.
8-
FROM alpine:3.9.6 AS builder
8+
FROM python:3.7-slim-buster AS builder
99

1010
# Execute subsequent RUN statements with bash for handy modern shell features.
11-
RUN apk add --no-cache bash
1211
SHELL ["/bin/bash", "-c"]
1312

1413
# Add system deps for building
15-
RUN apk add --no-cache \
14+
RUN apt-get update && apt-get install -y --no-install-recommends \
1615
autoconf \
1716
automake \
18-
build-base \
17+
build-essential \
1918
ca-certificates \
2019
curl \
21-
freetype-dev \
2220
git \
23-
gmp-dev \
21+
libgmp-dev \
2422
libpng-dev \
25-
linux-headers \
2623
nodejs \
27-
nodejs-npm \
28-
perl \
29-
python3-dev \
30-
suitesparse-dev \
31-
xz
24+
npm \
25+
pkg-config
3226

3327
# Downloading dependencies, these should be pinned to specific versions
3428

@@ -61,37 +55,6 @@ RUN curl -fsSL https://github.com/vcftools/vcftools/releases/download/v0.1.16/vc
6155
| tar xzvpf - --strip-components=2
6256
RUN ./configure --prefix=$PWD/built && make && make install
6357

64-
# Install Python 3 dependencies
65-
# These may be upgraded by augur/setup.py,
66-
# but having them here enables caching
67-
# Be sure to install numpy ahead of pandas
68-
69-
# cvxopt install is particularly fussy.
70-
# It is separated out from the rest of the installs to ensures that pip wheels
71-
# can be used for as much as possible, since using --global-option disables use
72-
# of wheels.
73-
RUN CVXOPT_BLAS_LIB=openblas \
74-
CVXOPT_LAPACK_LIB=openblas \
75-
pip3 install --global-option=build_ext \
76-
--global-option="-I/usr/include/suitesparse" \
77-
cvxopt==1.1.9
78-
RUN pip3 install numpy==1.19.4
79-
RUN pip3 install scipy==1.3.3
80-
RUN pip3 install pandas==1.1.5
81-
RUN pip3 install bcbio-gff==0.6.6
82-
RUN pip3 install biopython==1.76
83-
RUN pip3 install boto==2.49.0
84-
RUN pip3 install ipdb==0.10.1
85-
RUN pip3 install jsonschema==3.0.1
86-
RUN pip3 install matplotlib==2.2.2
87-
RUN pip3 install phylo-treetime==0.8.0
88-
RUN pip3 install requests==2.22.0
89-
RUN pip3 install rethinkdb==2.4.8
90-
RUN pip3 install seaborn==0.9.0
91-
RUN pip3 install snakemake==5.10.0
92-
RUN pip3 install unidecode==1.1.1
93-
RUN pip3 install xlrd==1.2.0
94-
9558
# Install envdir, which is used by pathogen builds
9659
RUN pip3 install envdir==1.0.1
9760

@@ -101,6 +64,9 @@ RUN pip3 install awscli==1.18.195
10164
# Install our own CLI so builds can do things like `nextstrain deploy`
10265
RUN pip3 install nextstrain-cli==2.0.0.post1
10366

67+
# Install Snakemake
68+
RUN pip3 install snakemake==5.10.0
69+
10470
# Add Nextstrain components
10571

10672
# Allow caching to be avoided from here on out by calling
@@ -127,41 +93,37 @@ RUN pip3 install --requirement=/nextstrain/fauna/requirements.txt
12793
# accessible and importable.
12894
RUN pip3 install --editable /nextstrain/augur
12995

96+
# Install additional "full" dependencies for augur.
97+
# TODO: these versions should be updated in augur's setup.py to work with the
98+
# pip install nextstrain-augur[full] approach.
99+
RUN pip3 install cvxopt==1.2.4
100+
RUN pip3 install matplotlib==2.2.2
101+
RUN pip3 install seaborn==0.9.0
102+
130103
# Install Node deps, build Auspice, and link it into the global search path. A
131104
# fresh install is only ~40 seconds, so we're not worrying about caching these
132105
# as we did the Python deps. Building auspice means we can run it without
133106
# hot-reloading, which is time-consuming and generally unnecessary in the
134107
# container image. Linking is equivalent to an editable Python install and
135108
# used for the same reasons described above.
136-
RUN cd /nextstrain/auspice && npm install && npm run build && npm link
137-
109+
RUN cd /nextstrain/auspice && npm update && npm install && npm run build && npm link
138110

139111
# ———————————————————————————————————————————————————————————————————— #
140112

141-
142113
# Now build the final image.
143-
FROM alpine:3.9.6
114+
FROM python:3.7-slim-buster
144115

145116
# Add system runtime deps
146-
RUN apk add --no-cache \
117+
RUN apt-get update && apt-get install -y --no-install-recommends \
147118
bzip2 \
148119
ca-certificates \
149120
curl \
150-
bash \
151-
freetype \
152-
gmp \
153121
gzip \
154-
lapack \
155-
libpng \
156122
nodejs \
157123
perl \
158-
python2 \
159-
python3 \
160-
suitesparse \
161124
ruby \
162-
tar \
163125
wget \
164-
xz \
126+
xz-utils \
165127
zip unzip
166128

167129
# Configure the prompt for interactive usage
@@ -184,7 +146,7 @@ COPY --from=builder /build/vcftools/built/share/ /usr/local/share/
184146
RUN chmod a+rX /usr/local/bin/* /usr/local/libexec/*
185147

186148
# Add installed Python libs
187-
COPY --from=builder /usr/lib/python3.6/site-packages/ /usr/lib/python3.6/site-packages/
149+
COPY --from=builder /usr/local/lib/python3.7/site-packages/ /usr/local/lib/python3.7/site-packages/
188150

189151
# Add installed Python scripts that we need.
190152
#
@@ -196,23 +158,23 @@ COPY --from=builder /usr/lib/python3.6/site-packages/ /usr/lib/python3.6/site-pa
196158
# troublesome or excessive.
197159
# -trs, 15 June 2018
198160
COPY --from=builder \
199-
/usr/bin/augur \
200-
/usr/bin/aws \
201-
/usr/bin/envdir \
202-
/usr/bin/nextstrain \
203-
/usr/bin/snakemake \
204-
/usr/bin/
161+
/usr/local/bin/augur \
162+
/usr/local/bin/aws \
163+
/usr/local/bin/envdir \
164+
/usr/local/bin/nextstrain \
165+
/usr/local/bin/snakemake \
166+
/usr/local/bin/
205167

206168
# Add installed Node libs
207-
COPY --from=builder /usr/lib/node_modules/ /usr/lib/node_modules/
169+
COPY --from=builder /usr/local/lib/node_modules/ /usr/local/lib/node_modules/
208170

209171
# Add globally linked Auspice script.
210172
#
211173
# This symlink is present in the "builder" image, but using COPY results in the
212174
# _contents_ of the target being copied instead of a symlink being created.
213175
# The symlink is required so that Auspice's locally-installed deps are
214176
# correctly discovered by node.
215-
RUN ln -sv /usr/lib/node_modules/auspice/auspice.js /usr/bin/auspice
177+
RUN ln -sv /usr/local/lib/node_modules/auspice/auspice.js /usr/local/bin/auspice
216178

217179
# Add Nextstrain components
218180
COPY --from=builder /nextstrain /nextstrain

0 commit comments

Comments
 (0)