add flavor to pip cache id

to prevent cache invalidation
This commit is contained in:
mauwii 2023-02-06 23:46:53 +01:00 committed by Matthias Wild
parent 28a5424242
commit cdb3e18b80
4 changed files with 24 additions and 21 deletions

View File

@ -3,7 +3,8 @@ on:
push:
branches:
- 'main'
- 'update/ci/*'
- 'update/ci/docker/*'
- 'update/docker/*'
tags:
- 'v*.*.*'

View File

@ -1,4 +1,5 @@
# syntax=docker/dockerfile:1
ARG PYTHON_VERSION=3.9
##################
## base image ##
@ -6,19 +7,19 @@ ARG PYTHON_VERSION=3.9
FROM python:${PYTHON_VERSION}-slim AS python-base
# prepare for buildkit cache
RUN rm -f /etc/apt/apt.conf.d/docker-clean
RUN rm -f /etc/apt/apt.conf.d/docker-clean \
&& echo 'Binary::apt::APT::Keep-Downloaded-Packages "true";' >/etc/apt/apt.conf.d/keep-cache
# Install necesarry packages
RUN \
--mount=type=cache,target=/var/cache/apt,sharing=locked \
apt-get update \
&& apt-get install \
-yqq \
--mount=type=cache,target=/var/lib/apt,sharing=locked \
apt update \
&& apt-get install -y \
--no-install-recommends \
libgl1-mesa-glx=20.3.* \
libglib2.0-0=2.66.* \
libopencv-dev=4.5.* \
&& rm -rf /var/lib/apt/lists/*
libopencv-dev=4.5.*
# set working directory and path
ARG APPDIR=/usr/src
@ -34,24 +35,24 @@ ENV PIP_USE_PEP517=1
# prepare for buildkit cache
ARG PIP_CACHE_DIR=/var/cache/buildkit/pip
ARG CONTAINER_FLAVOR=cuda
ENV PIP_CACHE_DIR ${PIP_CACHE_DIR}
RUN mkdir -p ${PIP_CACHE_DIR}
# Install dependencies
RUN \
--mount=type=cache,target=${PIP_CACHE_DIR} \
--mount=type=cache,target=${PIP_CACHE_DIR},id=pip-${CONTAINER_FLAVOR} \
--mount=type=cache,target=/var/cache/apt,sharing=locked \
apt-get update \
&& apt-get install \
-yqq \
--mount=type=cache,target=/var/lib/apt,sharing=locked \
apt update \
&& apt-get install -y \
--no-install-recommends \
build-essential=12.9 \
gcc=4:10.2.* \
python3-dev=3.9.* \
&& rm -rf /var/lib/apt/lists/*
python3-dev=3.9.*
# create virtual environment
RUN --mount=type=cache,target=${PIP_CACHE_DIR} \
RUN --mount=type=cache,target=${PIP_CACHE_DIR},id=pip-${CONTAINER_FLAVOR} \
python3 -m venv "${APPNAME}" \
--upgrade-deps
@ -62,8 +63,8 @@ COPY --link . .
ARG PIP_EXTRA_INDEX_URL
ENV PIP_EXTRA_INDEX_URL ${PIP_EXTRA_INDEX_URL}
ARG PIP_PACKAGE=.
RUN --mount=type=cache,target=${PIP_CACHE_DIR} \
"${APPDIR}/${APPNAME}/bin/pip" install ${PIP_PACKAGE}
RUN --mount=type=cache,target=${PIP_CACHE_DIR},id=pip-${CONTAINER_FLAVOR} \
"${APPNAME}/bin/pip" install ${PIP_PACKAGE}
# build patchmatch
RUN python3 -c "from patchmatch import patch_match"
@ -74,7 +75,7 @@ RUN python3 -c "from patchmatch import patch_match"
FROM python-base AS runtime
# setup environment
COPY --from=pyproject-builder --link ${APPDIR}/${APPNAME} ${APPDIR}/${APPNAME}
COPY --from=pyproject-builder ${APPDIR}/${APPNAME} ${APPDIR}/${APPNAME}
ENV INVOKEAI_ROOT=/data
ENV INVOKE_MODEL_RECONFIGURE="--yes --default_only"

View File

@ -36,9 +36,10 @@ fi
# Build Container
DOCKER_BUILDKIT=1 docker build \
--platform="${PLATFORM}" \
--tag="${CONTAINER_IMAGE}" \
--platform="${PLATFORM:-Linux/amd64}" \
--tag="${CONTAINER_IMAGE:-invokeai}" \
${CONTAINER_FLAVOR:+--build-arg="CONTAINER_FLAVOR=${CONTAINER_FLAVOR}"} \
${PIP_EXTRA_INDEX_URL:+--build-arg="PIP_EXTRA_INDEX_URL=${PIP_EXTRA_INDEX_URL}"} \
${PIP_PACKAGE:+--build-arg="PIP_PACKAGE=${PIP_PACKAGE}"} \
--file="${DOCKERFILE}" \
--file="${DOCKERFILE:-./Dockerfile}" \
..

View File

@ -28,4 +28,4 @@ docker run \
--publish=9090:9090 \
--cap-add=sys_nice \
${GPU_FLAGS:+--gpus="${GPU_FLAGS}"} \
"${CONTAINER_IMAGE}" ${1:+$@}
"${CONTAINER_IMAGE}" ${@:+$@}