diff --git a/.github/workflows/build-container.yml b/.github/workflows/build-container.yml index b340768dd2..2ba9e588e2 100644 --- a/.github/workflows/build-container.yml +++ b/.github/workflows/build-container.yml @@ -3,7 +3,8 @@ on: push: branches: - 'main' - - 'update/ci/*' + - 'update/ci/docker/*' + - 'update/docker/*' tags: - 'v*.*.*' diff --git a/docker/Dockerfile b/docker/Dockerfile index d957e72334..7146a67981 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -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" diff --git a/docker/build.sh b/docker/build.sh index dc1a1dcc78..1ad51b387a 100755 --- a/docker/build.sh +++ b/docker/build.sh @@ -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}" \ .. diff --git a/docker/run.sh b/docker/run.sh index 5593faaa3e..f769976b1c 100755 --- a/docker/run.sh +++ b/docker/run.sh @@ -28,4 +28,4 @@ docker run \ --publish=9090:9090 \ --cap-add=sys_nice \ ${GPU_FLAGS:+--gpus="${GPU_FLAGS}"} \ - "${CONTAINER_IMAGE}" ${1:+$@} + "${CONTAINER_IMAGE}" ${@:+$@}