Skip to content

Commit b48e2e0

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 7df584e commit b48e2e0

File tree

1 file changed

+28
-67
lines changed

1 file changed

+28
-67
lines changed

Dockerfile

Lines changed: 28 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,40 +93,35 @@ 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
ca-certificates \
148119
curl \
149-
bash \
150-
freetype \
151-
gmp \
152120
gzip \
153-
lapack \
154-
libpng \
155121
nodejs \
156-
perl \
157-
python2 \
158-
python3 \
159-
suitesparse \
160122
ruby \
161-
tar \
162123
wget \
163-
xz \
124+
xz-utils \
164125
zip unzip
165126

166127
# Configure the prompt for interactive usage
@@ -183,7 +144,7 @@ COPY --from=builder /build/vcftools/built/share/ /usr/local/share/
183144
RUN chmod a+rX /usr/local/bin/* /usr/local/libexec/*
184145

185146
# Add installed Python libs
186-
COPY --from=builder /usr/lib/python3.6/site-packages/ /usr/lib/python3.6/site-packages/
147+
COPY --from=builder /usr/local/lib/python3.7/site-packages/ /usr/local/lib/python3.7/site-packages/
187148

188149
# Add installed Python scripts that we need.
189150
#
@@ -195,22 +156,22 @@ COPY --from=builder /usr/lib/python3.6/site-packages/ /usr/lib/python3.6/site-pa
195156
# troublesome or excessive.
196157
# -trs, 15 June 2018
197158
COPY --from=builder \
198-
/usr/bin/augur \
199-
/usr/bin/aws \
200-
/usr/bin/nextstrain \
201-
/usr/bin/snakemake \
202-
/usr/bin/
159+
/usr/local/bin/augur \
160+
/usr/local/bin/aws \
161+
/usr/local/bin/nextstrain \
162+
/usr/local/bin/snakemake \
163+
/usr/local/bin/
203164

204165
# Add installed Node libs
205-
COPY --from=builder /usr/lib/node_modules/ /usr/lib/node_modules/
166+
COPY --from=builder /usr/local/lib/node_modules/ /usr/local/lib/node_modules/
206167

207168
# Add globally linked Auspice script.
208169
#
209170
# This symlink is present in the "builder" image, but using COPY results in the
210171
# _contents_ of the target being copied instead of a symlink being created.
211172
# The symlink is required so that Auspice's locally-installed deps are
212173
# correctly discovered by node.
213-
RUN ln -sv /usr/lib/node_modules/auspice/auspice.js /usr/bin/auspice
174+
RUN ln -sv /usr/local/lib/node_modules/auspice/auspice.js /usr/local/bin/auspice
214175

215176
# Add Nextstrain components
216177
COPY --from=builder /nextstrain /nextstrain

0 commit comments

Comments
 (0)