|
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. |
5 | 3 | ARG DIST=buster |
6 | 4 |
|
| 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 |
7 | 14 | RUN echo "deb http://deb.nodesource.com/node_14.x $DIST main" > /etc/apt/sources.list.d/nodesource.list \ |
8 | 15 | && 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 \ |
12 | 18 | nodejs \ |
13 | | - python3 \ |
14 | | - python3-pip \ |
15 | | - python3-wheel \ |
16 | | - python3-setuptools |
| 19 | + && rm -rf /var/lib/apt/lists/* |
17 | 20 |
|
18 | 21 | # Copy the whole git repository to /tmp/binderhub |
19 | 22 | COPY . /tmp/binderhub |
20 | 23 | WORKDIR /tmp/binderhub |
21 | 24 |
|
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 | + |
24 | 30 |
|
25 | 31 | # The final stage |
26 | 32 | # --------------- |
27 | | -FROM python:3.8-$DIST |
| 33 | +FROM python:3.8-slim-$DIST |
28 | 34 | WORKDIR / |
29 | 35 |
|
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/* |
33 | 41 |
|
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/ |
36 | 47 | COPY helm-chart/images/binderhub/requirements.txt . |
| 48 | + |
| 49 | +# Install pre-built wheels and the generated requirements.txt for the image. |
37 | 50 | RUN pip install --no-cache-dir \ |
38 | | - *.whl \ |
| 51 | + pre-built-wheels/*.whl \ |
39 | 52 | -r requirements.txt |
40 | 53 |
|
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. |
46 | 57 | ARG PIP_TOOLS= |
47 | 58 | RUN test -z "$PIP_TOOLS" || pip install --no-cache pip-tools==$PIP_TOOLS |
48 | 59 |
|
|
0 commit comments