Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(docker): adjust Dockerfile layers to improve build cache design #2102

Merged
merged 6 commits into from
Mar 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,7 @@ requirements_tmp_for_setup.txt
*.npz
presets/*/user_presets/*
inputs
outputs
outputs
dataset/**
!dataset/**/
!dataset/**/.gitkeep
49 changes: 25 additions & 24 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -54,21 +54,8 @@ RUN if [ "$TARGETPLATFORM" = "linux/amd64" ]; then \

FROM python:3.10-slim as final

ARG UID
ARG VERSION
ARG RELEASE

LABEL name="bmaltais/kohya_ss" \
vendor="bmaltais" \
maintainer="bmaltais" \
# Dockerfile source repository
url="https://github.com/bmaltais/kohya_ss" \
version=${VERSION} \
# This should be a number, incremented with each change
release=${RELEASE} \
io.k8s.display-name="kohya_ss" \
summary="Kohya's GUI: This repository provides a Gradio GUI for Kohya's Stable Diffusion trainers(https://github.com/kohya-ss/sd-scripts)." \
description="The GUI allows you to set the training parameters and generate and run the required CLI commands to train the model. This is the docker image for Kohya's GUI. For more information about this tool, please visit the following website: https://github.com/bmaltais/kohya_ss."
ENV NVIDIA_VISIBLE_DEVICES all
ENV NVIDIA_DRIVER_CAPABILITIES compute,utility

# Install runtime dependencies
RUN apt-get update && \
Expand All @@ -81,6 +68,7 @@ RUN ln -s /usr/lib/x86_64-linux-gnu/libnvinfer.so /usr/lib/x86_64-linux-gnu/libn
ln -s /usr/lib/x86_64-linux-gnu/libnvinfer_plugin.so /usr/lib/x86_64-linux-gnu/libnvinfer_plugin.so.7

# Create user
ARG UID
RUN groupadd -g $UID $UID && \
useradd -l -u $UID -g $UID -m -s /bin/sh -N $UID

Expand All @@ -89,21 +77,20 @@ RUN install -d -m 775 -o $UID -g 0 /dataset && \
install -d -m 775 -o $UID -g 0 /licenses && \
install -d -m 775 -o $UID -g 0 /app

# Copy dist and support arbitrary user ids (OpenShift best practice)
COPY --chown=$UID:0 --chmod=775 \
--from=build /root/.local /home/$UID/.local

WORKDIR /app
COPY --chown=$UID:0 --chmod=775 . .

# Copy licenses (OpenShift Policy)
COPY --chmod=775 LICENSE.md /licenses/LICENSE.md
COPY --link --chmod=775 LICENSE.md /licenses/LICENSE.md

# Copy dependencies and code (and support arbitrary uid for OpenShift best practice)
COPY --link --chown=$UID:0 --chmod=775 --from=build /root/.local /home/$UID/.local
COPY --link --chown=$UID:0 --chmod=775 . /app

ENV PATH="/home/$UID/.local/bin:$PATH"
ENV PYTHONPATH="${PYTHONPATH}:/home/$UID/.local/lib/python3.10/site-packages"
ENV LD_PRELOAD=libtcmalloc.so
ENV PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python

WORKDIR /app

VOLUME [ "/dataset" ]

# 7860: Kohya GUI
Expand All @@ -116,4 +103,18 @@ STOPSIGNAL SIGINT

# Use dumb-init as PID 1 to handle signals properly
ENTRYPOINT ["dumb-init", "--"]
CMD ["python3", "kohya_gui.py", "--listen", "0.0.0.0", "--server_port", "7860"]
CMD ["python3", "kohya_gui.py", "--listen", "0.0.0.0", "--server_port", "7860"]

ARG VERSION
ARG RELEASE
LABEL name="bmaltais/kohya_ss" \
vendor="bmaltais" \
maintainer="bmaltais" \
# Dockerfile source repository
url="https://github.com/bmaltais/kohya_ss" \
version=${VERSION} \
# This should be a number, incremented with each change
release=${RELEASE} \
io.k8s.display-name="kohya_ss" \
summary="Kohya's GUI: This repository provides a Gradio GUI for Kohya's Stable Diffusion trainers(https://github.com/kohya-ss/sd-scripts)." \
description="The GUI allows you to set the training parameters and generate and run the required CLI commands to train the model. This is the docker image for Kohya's GUI. For more information about this tool, please visit the following website: https://github.com/bmaltais/kohya_ss."
File renamed without changes.
Empty file added dataset/logs/.gitkeep
Empty file.
Empty file added dataset/outputs/.gitkeep
Empty file.
Empty file added dataset/regularization/.gitkeep
Empty file.
12 changes: 7 additions & 5 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
version: "3.8"

services:
kohya-ss-gui:
container_name: kohya-ss-gui
Expand All @@ -11,22 +12,23 @@ services:
ports:
- 7860:7860
- 6006:6006
tty: true
ipc: host
environment:
CLI_ARGS: ""
SAFETENSORS_FAST_GPU: 1
DISPLAY: $DISPLAY
tmpfs:
- /tmp
volumes:
- /tmp/.X11-unix:/tmp/.X11-unix
- ./dataset:/dataset
- ./dataset/images:/app/data
- ./dataset/logs:/app/logs
- ./dataset/outputs:/app/outputs
- ./dataset/regularization:/app/regularization
- ./.cache/config:/app/config
- ./.cache/user:/home/1000/.cache
- ./.cache/triton:/home/1000/.triton
- ./.cache/nv:/home/1000/.nv
- ./.cache/keras:/home/1000/.keras
- ./.cache/config:/home/1000/.config
- ./.cache/config:/home/1000/.config # For backward compatibility
deploy:
resources:
reservations:
Expand Down