Skip to content
Snippets Groups Projects
Commit 1fe1424a authored by Simon Künzel's avatar Simon Künzel
Browse files

fixup! Add package caching for CI

parent 9a49e4c2
No related branches found
No related tags found
No related merge requests found
Pipeline #7318 canceled
Pipeline: backend

#7319

    # Can be "development" or "production" # Can be "development" or "production"
    ARG ENV_TYPE ARG ENV_TYPE
    ARG GIT_COMMIT_SHA ARG GIT_COMMIT_SHA
    FROM registry.git.fsmpi.rwth-aachen.de/videoag/backend/${ENV_TYPE}_common_py:${GIT_COMMIT_SHA} FROM registry.git.fsmpi.rwth-aachen.de/videoag/backend/${ENV_TYPE}_common_py:${GIT_COMMIT_SHA} AS base
    # READ THE NOTE on caching in the README before changing this/for more info! # READ THE NOTE on caching in the README before changing this/for more info!
    ARG PIP_CACHE_DIR= ARG PIP_CACHE_DIR=
    ARG APT_CACHE_DIR=
    RUN rm -f /etc/apt/apt.conf.d/docker-clean
    RUN if ! [ -z "$APT_CACHE_DIR" ]; then echo "Dir::Cache::Archives '$APT_CACHE_DIR';" > /etc/apt/apt.conf.d/ci_caching; fi
    ENV VIDEOAG_API_GIT_COMMIT_HASH $GIT_COMMIT_SHA ENV VIDEOAG_API_GIT_COMMIT_HASH $GIT_COMMIT_SHA
    COPY extra_requirements.txt ./
    # Install and build requirements in different image too reduce final image size
    FROM base AS builder
    # READ THE NOTE on caching in the README before changing this/for more info! # READ THE NOTE on caching in the README before changing this/for more info!
    COPY extra_requirements.txt ./
    RUN --mount=type=cache,target=/root/.cache/pip \ RUN --mount=type=cache,target=/root/.cache/pip \
    pip --python .venv/bin/python install -r extra_requirements.txt --mount=type=cache,target=/var/cache/apt,sharing=locked \
    --mount=type=cache,target=/var/lib/apt,sharing=locked \
    if ! pip --python .venv/bin/python install -r extra_requirements.txt; \
    then echo "Pip failed (packages weren't cached) but you can ignore the error above. We will install the build dependencies and try again" \
    # Packages needed to build lxml with pip
    && apt-get update && apt-get --no-install-recommends install -y gcc python3-dev libxml2-dev libxslt-dev \
    && pip --python .venv/bin/python install -r extra_requirements.txt; \
    fi
    FROM base AS final
    COPY --from=builder /code/.venv /code/.venv
    COPY docker_start.sh ./ COPY docker_start.sh ./
    COPY .pylintrc ./ COPY .pylintrc ./
    ......
    ...@@ -12,19 +12,21 @@ WORKDIR /code ...@@ -12,19 +12,21 @@ WORKDIR /code
    RUN mkdir -p /code RUN mkdir -p /code
    WORKDIR /code WORKDIR /code
    # Install and build requirements in different image too reduce final image size # Install and build requirements in different image too reduce final image size
    FROM base AS builder FROM base AS builder
    # Packages needed to build psycopg with pip
    # READ THE NOTE on caching in the README before changing this/for more info! # READ THE NOTE on caching in the README before changing this/for more info!
    RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
    --mount=type=cache,target=/var/lib/apt,sharing=locked \
    apt-get update && apt-get --no-install-recommends install -y libpq-dev gcc python3-dev
    COPY requirements.txt /code COPY requirements.txt /code
    RUN python -m venv --without-pip .venv/
    RUN --mount=type=cache,target=/root/.cache/pip \ RUN --mount=type=cache,target=/root/.cache/pip \
    pip --python /code/.venv/bin/python install -r requirements.txt --mount=type=cache,target=/var/cache/apt,sharing=locked \
    --mount=type=cache,target=/var/lib/apt,sharing=locked \
    if ! pip --python .venv/bin/python install -r requirements.txt; \
    then echo "Pip failed (packages weren't cached) but you can ignore the error above. We will install the build dependencies and try again" \
    # Packages needed to build psycopg with pip
    && apt-get update && apt-get --no-install-recommends install -y gcc python3-dev libpq-dev \
    && pip --python .venv/bin/python install -r requirements.txt; \
    fi
    FROM base AS final FROM base AS final
    ......
    0% Loading or .
    You are about to add 0 people to the discussion. Proceed with caution.
    Please register or to comment