mozilla / bugbug

Platform for Machine Learning projects on Software Engineering
Mozilla Public License 2.0
504 stars 311 forks source link

Use multistage build to reduce image size #315

Open marco-c opened 5 years ago

marco-c commented 5 years ago

With a multistage build we can have small Docker images without causing caching problems with squashing multiple comands in one layer.

La0 commented 5 years ago

Taskboot cannot use docker-squash for now anyway...

marco-c commented 5 years ago

We wouldn't need to squash with multistage builds

La0 commented 5 years ago

I had this version based on slim, but was not convinced by the size enhancements:

#syntax=docker/dockerfile:experimental
ARG PYTHON_VERSION=3.7.3-slim

FROM python:${PYTHON_VERSION} as build

# Install bugbug requirements as wheels
WORKDIR /wheels
COPY requirements.txt /requirements.txt
RUN apt-get update && \
                apt-get install -y gcc g++ && \
                pip wheel --disable-pip-version-check -r /requirements.txt && \

# Restart build from a slim image
FROM python:${PYTHON_VERSION}

# Import wheels
COPY --from=build /wheels /tmp/wheels

# Setup bugbug with a bind RO mount
RUN --mount=type=bind,target=/tmp/bugbug \
        apt-get update && \
        apt-get install libgomp1 && \
        pip install -f /tmp/wheels /tmp/bugbug && \
        rm -rf /tmp/wheels