Skip to content

Commit 62b80a8

Browse files
authored
Update dockerfile 2.2.4 (#1924)
* updated Dockerfile - use `python:3.10-slim` as baseimage - separate builder and runtime stages again - get rid of uneeded packages - pin packages for persistence - remove outdir from entrypoint since invoke.init is available in /data - shrinked image size to <2GB - way better security score than before * small output update to build.sh and run.sh * update matrix in build-container.yml * remove branches from build-container.yml
1 parent 14587c9 commit 62b80a8

File tree

4 files changed

+43
-30
lines changed

4 files changed

+43
-30
lines changed

.github/workflows/build-container.yml

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,12 @@ on:
55
push:
66
branches:
77
- 'main'
8-
- 'development'
9-
- 'update-dockerfile'
108

119
jobs:
1210
docker:
1311
strategy:
1412
fail-fast: false
1513
matrix:
16-
arch:
17-
- x86_64
18-
- aarch64
1914
pip-requirements:
2015
- requirements-lin-amd.txt
2116
- requirements-lin-cuda.txt
@@ -37,7 +32,7 @@ jobs:
3732
with:
3833
context: .
3934
file: docker-build/Dockerfile
40-
platforms: Linux/${{ matrix.arch }}
35+
platforms: linux/amd64,linux/arm64
4136
push: false
42-
tags: ${{ env.dockertag }}:${{ matrix.pip-requirements }}-${{ matrix.arch }}
37+
tags: ${{ env.dockertag }}:${{ matrix.pip-requirements }}
4338
build-args: pip_requirements=${{ matrix.pip-requirements }}

docker-build/Dockerfile

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM ubuntu:22.10
1+
FROM python:3.10-slim AS builder
22

33
# use bash
44
SHELL [ "/bin/bash", "-c" ]
@@ -7,28 +7,42 @@ SHELL [ "/bin/bash", "-c" ]
77
RUN apt-get update \
88
&& apt-get install -y \
99
--no-install-recommends \
10-
build-essential \
11-
gcc \
12-
git \
13-
libgl1-mesa-glx \
14-
libglib2.0-0 \
15-
pip \
16-
python3 \
17-
python3-dev \
10+
gcc=4:10.2.* \
11+
libgl1-mesa-glx=20.3.* \
12+
libglib2.0-0=2.66.* \
13+
python3-dev=3.9.* \
1814
&& apt-get clean \
1915
&& rm -rf /var/lib/apt/lists/*
2016

21-
# set workdir and copy sources
22-
WORKDIR /invokeai
17+
# set workdir, PATH and copy sources
18+
WORKDIR /usr/src/app
19+
ENV PATH /usr/src/app/.venv/bin:$PATH
2320
ARG PIP_REQUIREMENTS=requirements-lin-cuda.txt
2421
COPY . ./environments-and-requirements/${PIP_REQUIREMENTS} ./
2522

26-
# install requirements and link outputs folder
27-
RUN pip install \
28-
--no-cache-dir \
29-
-r ${PIP_REQUIREMENTS}
23+
# install requirements
24+
RUN python3 -m venv .venv \
25+
&& pip install \
26+
--no-cache-dir \
27+
-r ${PIP_REQUIREMENTS}
28+
29+
FROM python:3.10-slim AS runtime
30+
31+
# Install necesarry packages
32+
RUN apt-get update \
33+
&& apt-get install -y \
34+
--no-install-recommends \
35+
libgl1-mesa-glx=20.3.* \
36+
libglib2.0-0=2.66.* \
37+
&& apt-get clean \
38+
&& rm -rf /var/lib/apt/lists/*
39+
40+
WORKDIR /usr/src/app
41+
COPY --from=builder /usr/src/app .
3042

3143
# set Environment, Entrypoint and default CMD
3244
ENV INVOKEAI_ROOT /data
33-
ENTRYPOINT [ "python3", "scripts/invoke.py", "--outdir=/data/outputs" ]
45+
ENV PATH=/usr/src/app/.venv/bin:$PATH
46+
47+
ENTRYPOINT [ "python3", "scripts/invoke.py" ]
3448
CMD [ "--web", "--host=0.0.0.0" ]

docker-build/build.sh

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ pip_requirements=${PIP_REQUIREMENTS:-requirements-lin-cuda.txt}
1212
dockerfile=${INVOKE_DOCKERFILE:-docker-build/Dockerfile}
1313

1414
# print the settings
15-
echo "You are using these values:"
16-
echo -e "Dockerfile:\t\t ${dockerfile}"
17-
echo -e "requirements:\t\t ${pip_requirements}"
18-
echo -e "volumename:\t\t ${volumename}"
19-
echo -e "arch:\t\t\t ${arch}"
20-
echo -e "platform:\t\t ${platform}"
21-
echo -e "invokeai_tag:\t\t ${invokeai_tag}\n"
15+
echo -e "You are using these values:\n"
16+
echo -e "Dockerfile:\t ${dockerfile}"
17+
echo -e "requirements:\t ${pip_requirements}"
18+
echo -e "volumename:\t ${volumename}"
19+
echo -e "arch:\t\t ${arch}"
20+
echo -e "platform:\t ${platform}"
21+
echo -e "invokeai_tag:\t ${invokeai_tag}\n"
2222

2323
if [[ -n "$(docker volume ls -f name="${volumename}" -q)" ]]; then
2424
echo "Volume already exists"

docker-build/run.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ set -e
33

44
source ./docker-build/env.sh || echo "please run from repository root" || exit 1
55

6+
echo -e "You are using these values:\n"
7+
echo -e "volumename:\t ${volumename}"
8+
echo -e "invokeai_tag:\t ${invokeai_tag}\n"
9+
610
docker run \
711
--interactive \
812
--tty \

0 commit comments

Comments
 (0)