Skip to content

Commit a36348e

Browse files
authored
Merge pull request #1158 from betatim/image-cleaning-with-buster
2 parents 1f1f0c4 + 76692c1 commit a36348e

File tree

7 files changed

+52
-50
lines changed

7 files changed

+52
-50
lines changed

doc/doc-requirements.txt

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,4 @@ sphinx-copybutton
1717
# automatically building documentation based on inspection of the binderhub
1818
# package, which means we need to install it on RTD so it is available for
1919
# inspection.
20-
#
21-
# The binderhub package dependencies include pycurl though, and pycurl cannot be
22-
# installed on RTD, so due to that we maintain a copy of binderhub's
23-
# requirements.txt where we comment out pyrcurl.
24-
docker
25-
escapism
26-
jinja2
27-
jsonschema
28-
jupyterhub
29-
kubernetes
30-
prometheus_client
31-
#pycurl
32-
python-json-logger
33-
tornado>=5.1
34-
traitlets
20+
-r ../requirements.txt

helm-chart/images/binderhub/Dockerfile

Lines changed: 36 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,59 @@
1-
# Using multi-stage builds
2-
ARG DIST=buster
3-
FROM buildpack-deps:$DIST as build-stage
4-
# ARG has to occur twice to be used in both contents and FROM
1+
# We use a build stage to package binderhub and pycurl into a wheel which we
2+
# then install by itself in the final image which is relatively slimmed.
53
ARG DIST=buster
64

5+
6+
# The build stage
7+
# ---------------
8+
FROM python:3.8-$DIST as build-stage
9+
# ARG DIST is defined again to be made available in this build stage's scope.
10+
# ref: https://docs.docker.com/engine/reference/builder/#understand-how-arg-and-from-interact
11+
ARG DIST
12+
13+
# Install node as required to package binderhub to a wheel
714
RUN echo "deb http://deb.nodesource.com/node_14.x $DIST main" > /etc/apt/sources.list.d/nodesource.list \
815
&& curl -s https://deb.nodesource.com/gpgkey/nodesource.gpg.key | apt-key add -
9-
10-
RUN apt-get update && \
11-
apt-get install --yes \
16+
RUN apt-get update \
17+
&& apt-get install --yes \
1218
nodejs \
13-
python3 \
14-
python3-pip \
15-
python3-wheel \
16-
python3-setuptools
19+
&& rm -rf /var/lib/apt/lists/*
1720

1821
# Copy the whole git repository to /tmp/binderhub
1922
COPY . /tmp/binderhub
2023
WORKDIR /tmp/binderhub
2124

22-
# Build binderhub the python library
23-
RUN python3 setup.py bdist_wheel
25+
# Build the binderhub python library into a wheel and save it to the ./dist
26+
# folder. There are no pycurl wheels so we build our own in the build stage.
27+
RUN python setup.py bdist_wheel
28+
RUN pip wheel pycurl --wheel-dir ./dist
29+
2430

2531
# The final stage
2632
# ---------------
27-
FROM python:3.8-$DIST
33+
FROM python:3.8-slim-$DIST
2834
WORKDIR /
2935

30-
# Copy the built binderhub python wheel from the build-stage
31-
# to the current directory within the container.
32-
COPY --from=build-stage /tmp/binderhub/dist/*.whl .
36+
# The slim version doesn't include git as required by binderhub
37+
RUN apt-get update \
38+
&& apt-get install --yes \
39+
git \
40+
&& rm -rf /var/lib/apt/lists/*
3341

34-
# Copy the additional Python requirements for our Docker container from the
35-
# build context. These can be certain pinned versions or peer dependencies.
42+
43+
# Copy the built wheels from the build-stage. Also copy the image
44+
# requirements.txt built from the binderhub package requirements.txt and the
45+
# requirements.in file using the ./dependency script.
46+
COPY --from=build-stage /tmp/binderhub/dist/*.whl pre-built-wheels/
3647
COPY helm-chart/images/binderhub/requirements.txt .
48+
49+
# Install pre-built wheels and the generated requirements.txt for the image.
3750
RUN pip install --no-cache-dir \
38-
*.whl \
51+
pre-built-wheels/*.whl \
3952
-r requirements.txt
4053

41-
# when building the image used to compute the "frozen"
42-
# dependencies we add `pip-tools` which is for computing
43-
# the dependencies.
44-
# It is not added when chartpress builds the image used by
45-
# the helm chart when deploying BinderHub
54+
# When using the ./dependency script to output a frozen environment, we do it
55+
# from within this container. So below we conditionally install pip-tools for
56+
# use by the ./dependency script.
4657
ARG PIP_TOOLS=
4758
RUN test -z "$PIP_TOOLS" || pip install --no-cache pip-tools==$PIP_TOOLS
4859

helm-chart/images/binderhub/requirements.in

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,3 @@ google-cloud-logging
1111
kubernetes==9.*
1212
# jupyterhub is pinned to match the JupyterHub Helm chart's version of jupyterhub
1313
jupyterhub==1.1.*
14-
# For pycurl v7.43.0.6 there are no wheels available on pypi.org, so stick
15-
# to the previous version for now.
16-
pycurl==7.43.0.5

helm-chart/images/binderhub/requirements.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ protobuf==3.14.0 # via google-api-core, googleapis-common-protos
3838
pyasn1-modules==0.2.8 # via google-auth
3939
pyasn1==0.4.8 # via pyasn1-modules, rsa
4040
pycparser==2.20 # via cffi
41-
pycurl==7.43.0.5 # via -r binderhub.in, -r requirements.in
4241
pyopenssl==19.1.0 # via certipy
4342
pyrsistent==0.17.3 # via jsonschema
4443
python-dateutil==2.8.1 # via alembic, jupyterhub, kubernetes
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
FROM python:3.8-alpine3.11
1+
FROM python:3.8-slim-buster
22

3-
ADD requirements.txt /tmp/requirements.txt
4-
RUN pip3 install --no-cache-dir -r /tmp/requirements.txt
3+
COPY requirements.txt /tmp/requirements.txt
4+
RUN pip install --no-cache-dir -r /tmp/requirements.txt
55

6-
ADD image-cleaner.py /usr/local/bin/image-cleaner.py
6+
COPY image-cleaner.py /usr/local/bin/image-cleaner.py
77
# set PYTHONUNBUFFERED to ensure output is produced
88
ENV PYTHONUNBUFFERED=1
99
CMD image-cleaner.py

requirements.txt

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
1-
# Keep this file in sync with `doc/doc-requirements.txt`!
1+
# About pycurl:
2+
# - pycurl is a dependency but not listed here, only in `setup.py`
3+
# - pycurl requires both `curl-config` and `gcc` to be available when installing
4+
# it from source.
5+
# - the reason we do not list pycurl here is that it is not needed when our
6+
# code is imported to generate the documentation and it is tricky to install
7+
# in the ReadTheDocs build environment.
8+
# - instead we manually add pycurl to the list of dependencies in setup.py
9+
# which is the list used when installing the binderhub package.
210
docker
311
escapism
412
jinja2
513
jsonschema
614
jupyterhub
715
kubernetes
816
prometheus_client
9-
pycurl
1017
python-json-logger
1118
tornado>=5.1
1219
traitlets

setup.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
l.strip() for l in f.readlines()
1414
if not l.strip().startswith('#')
1515
]
16+
# manually add pycurl here, see comment in requirements.txt
17+
requirements.append("pycurl")
1618

1719
with open(os.path.join(here, 'README.rst'), encoding="utf8") as f:
1820
readme = f.read()

0 commit comments

Comments
 (0)