FROM python:3.7-slim as base

RUN apt-get update && \
    apt-get install -y git && \
    pip install --no-cache --upgrade pip requirements-builder

FROM base as builder

# The python install is done in two steps to avoid re-installing all dependencies every
# time the code changes
COPY setup.py README.rst CHANGES.rst /code/renku/
COPY renku/version.py.tmpl /code/renku/renku/version.py.tmpl
WORKDIR /code/renku
RUN requirements-builder --level=pypi setup.py > /tmp/requirements.txt && \
    pip install -r /tmp/requirements.txt

COPY .git /code/renku/.git
COPY renku /code/renku/renku

# Set CLEAN_INSTALL to a non-null value to ensure that only a committed version of
# renku-python is installed in the image. This is the default for chartpress builds.
ARG CLEAN_INSTALL
RUN if [ -n "${CLEAN_INSTALL}" ]; then git reset --hard ; fi

RUN pip wheel --wheel-dir /wheels . && \
    pip install --no-index --no-warn-script-location --force --root=/pythonroot/ /wheels/*.whl && \
    apt-get clean

FROM base

RUN apt-get install -y git-lfs && \
    git lfs install

COPY --from=builder /pythonroot/ /

ENTRYPOINT ["renku"]
