Skip to content
This repository was archived by the owner on Aug 23, 2025. It is now read-only.

Commit c4b00a1

Browse files
committed
feat: build with Nuitka
- Renamed `.env` to `.env_example` and updated the README to reflect this change. - Added `.env` to .gitignore for security reasons. - Added `dumb-init` and `patchelf` packages to Dockerfile to enhance the functionalities. - Changed WORKDIR from `/app` to `/source`. - Added Nuitka compilation step in the Dockerfile. - Commented out the copy command for `ffprobe` in the Dockerfile. - Updated the directories paths in the Dockerfile. - Changed the app execution command in Docker ENTRYPOINT to use the compiled binary. - Changed the bind mount for `OUTPUTS` in docker-compose.yml and updated README to reflect this. - Added error handling in docker-compose.yml for when `OUTPUTS` environment variable is not set. Signed-off-by: 陳鈞 <[email protected]>
1 parent 4c6d880 commit c4b00a1

File tree

5 files changed

+36
-19
lines changed

5 files changed

+36
-19
lines changed

.env renamed to .env_example

File renamed without changes.

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.env

Dockerfile

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ RUN --mount=type=cache,id=apt-$TARGETARCH$TARGETVARIANT,sharing=locked,target=/v
1414
--mount=type=cache,id=aptlists-$TARGETARCH$TARGETVARIANT,sharing=locked,target=/var/lib/apt/lists \
1515
apt-get update && apt-get install -y --no-install-recommends \
1616
# https://pillow.readthedocs.io/en/stable/installation/building-from-source.html
17-
libjpeg62-turbo-dev libwebp-dev zlib1g-dev
17+
libjpeg62-turbo-dev libwebp-dev zlib1g-dev \
18+
dumb-init
1819

1920
FROM base as build
2021

@@ -24,9 +25,12 @@ ARG TARGETVARIANT
2425
# Install build dependencies
2526
RUN --mount=type=cache,id=apt-$TARGETARCH$TARGETVARIANT,sharing=locked,target=/var/cache/apt \
2627
--mount=type=cache,id=aptlists-$TARGETARCH$TARGETVARIANT,sharing=locked,target=/var/lib/apt/lists \
27-
apt-get install -y --no-install-recommends build-essential
28+
apt-get install -y --no-install-recommends \
29+
build-essential \
30+
# For Nuitka standalone mode
31+
patchelf
2832

29-
WORKDIR /app
33+
WORKDIR /source
3034

3135
# Install under /root/.local
3236
ENV PIP_USER="true"
@@ -39,7 +43,7 @@ ARG PIP_DISABLE_PIP_VERSION_CHECK="true"
3943
RUN --mount=type=cache,id=pip-$TARGETARCH$TARGETVARIANT,sharing=locked,target=/root/.cache/pip \
4044
--mount=source=sd-webui-infinite-image-browsing/requirements.txt,target=requirements.txt,rw \
4145
pip install -U --force-reinstall pip setuptools wheel && \
42-
pip install -r requirements.txt dumb-init
46+
pip install -r requirements.txt nuitka
4347

4448
# Replace pillow with pillow-simd (Only for x86)
4549
ARG TARGETPLATFORM
@@ -49,9 +53,16 @@ RUN --mount=type=cache,id=pip-$TARGETARCH$TARGETVARIANT,sharing=locked,target=/r
4953
CC="cc -mavx2" pip install -U --force-reinstall pillow-simd; \
5054
fi
5155

52-
# Cleanup
53-
RUN find "/root/.local" -name '*.pyc' -print0 | xargs -0 rm -f || true ; \
54-
find "/root/.local" -type d -name '__pycache__' -print0 | xargs -0 rm -rf || true ;
56+
# Compile with nuitka
57+
RUN --mount=source=sd-webui-infinite-image-browsing,target=.,rw \
58+
python3 -m nuitka \
59+
--include-data-dir=vue/dist=vue/dist \
60+
--output-dir=/ \
61+
--standalone \
62+
--deployment \
63+
--disable-cache=all \
64+
--remove-output \
65+
app.py
5566

5667
FROM base as final
5768

@@ -61,7 +72,7 @@ RUN pip uninstall -y setuptools pip wheel && \
6172

6273
# ffmpeg
6374
COPY --link --from=mwader/static-ffmpeg:6.1.1 /ffmpeg /usr/local/bin/
64-
COPY --link --from=mwader/static-ffmpeg:6.1.1 /ffprobe /usr/local/bin/
75+
# COPY --link --from=mwader/static-ffmpeg:6.1.1 /ffprobe /usr/local/bin/
6576

6677
# Create user
6778
ARG UID
@@ -78,8 +89,7 @@ COPY --link --chmod=775 LICENSE /licenses/Dockerfile.LICENSE
7889
COPY --link --chmod=775 sd-webui-infinite-image-browsing/LICENSE /licenses/sd-webui-infinite-image-browsing.LICENSE
7990

8091
# Copy dependencies and code (and support arbitrary uid for OpenShift best practice)
81-
COPY --link --chown=$UID:0 --chmod=775 --from=build /root/.local /home/$UID/.local
82-
COPY --link --chown=$UID:0 --chmod=775 sd-webui-infinite-image-browsing /app
92+
COPY --link --chown=$UID:0 --chmod=775 --from=build /app.dist /app
8393

8494
# Create config file
8595
COPY <<EOF /config.json
@@ -107,7 +117,7 @@ RUN rm /bin/echo /bin/ln /bin/rm /bin/sh
107117

108118
WORKDIR /app
109119

110-
VOLUME [ "/output", "/tmp" ]
120+
VOLUME [ "/outputs", "/tmp" ]
111121

112122
EXPOSE 80
113123

@@ -116,7 +126,7 @@ USER $UID
116126
STOPSIGNAL SIGINT
117127

118128
# Use dumb-init as PID 1 to handle signals properly
119-
ENTRYPOINT ["dumb-init", "--", "python3", "app.py", "--host", "0.0.0.0", "--port", "80", "--sd_webui_config", "/config.json"]
129+
ENTRYPOINT ["dumb-init", "--", "/app/app.bin", "--host", "0.0.0.0", "--port", "80", "--sd_webui_config", "/config.json"]
120130

121131
ARG VERSION
122132
ARG RELEASE

README.md

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,21 @@ https://github.com/jim60105/docker-infinite-image-browsing/assets/16995691/c636d
1010

1111
## Usage Command
1212

13-
Edit the `.env` file to set the outputs directory from the `AUTOMATIC1111/stable-diffusion-webui`
13+
- Copy `.env_example` to `.env`
1414

15-
https://github.com/jim60105/docker-infinite-image-browsing/blob/83e9b218680258eadbb8813c17118f8c34631e13/.env#L1
15+
```bash
16+
cp .env_example .env
17+
```
1618

17-
And then run the following command:
19+
- Set the outputs directory from the `AUTOMATIC1111/stable-diffusion-webui` in `.env` file.
1820

19-
```bash
20-
docker compose up -d
21-
```
21+
https://github.com/jim60105/docker-infinite-image-browsing/blob/83e9b218680258eadbb8813c17118f8c34631e13/.env#L1
22+
23+
- And then run the following command:
24+
25+
```bash
26+
docker compose up -d
27+
```
2228

2329
### Build Command
2430

docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ services:
1212
tmpfs:
1313
- /tmp
1414
volumes:
15-
- ${OUTPUTS}:/output
15+
- ${OUTPUTS?Please set the outputs directory from the `AUTOMATIC1111/stable-diffusion-webui` in `.env` file.}:/outputs

0 commit comments

Comments
 (0)