Skip to content

Commit

Permalink
add infinite image browser container
Browse files Browse the repository at this point in the history
  • Loading branch information
neggles committed Mar 10, 2024
1 parent a62394e commit efbc362
Show file tree
Hide file tree
Showing 5 changed files with 157 additions and 2 deletions.
55 changes: 55 additions & 0 deletions browser/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# syntax=docker/dockerfile:1

# base image to use
ARG BASE_IMAGE=python:3.10-bookworm
# settings for apt and pip (inheritable by all images)
ARG DEBIAN_FRONTEND=noninteractive
ARG DEBIAN_PRIORITY=critical
ARG PIP_PREFER_BINARY=1

# Build the base image.
FROM ${BASE_IMAGE} as browser

# Set shell
SHELL ["/bin/bash", "-ceuxo", "pipefail"]

# Inherit args from global
ARG DEBIAN_FRONTEND
ARG DEBIAN_PRIORITY
ARG PIP_PREFER_BINARY

# Silence pip root user warnings
ENV PIP_ROOT_USER_ACTION=ignore
ENV _PIP_LOCATIONS_NO_WARN_ON_MISMATCH=1

# create app/data directories
RUN mkdir -p /app/browser /data /output
# set workdir
WORKDIR /app/browser

# clone repo and clean up git dir (to reduce image size)
ARG BROWSER_REPO=https://github.com/zanllp/sd-webui-infinite-image-browsing.git
ARG BROWSER_REF=main
RUN git clone --depth=1 --single-branch --branch="${BROWSER_REF}" "${BROWSER_REPO}" /app/browser \
&& rm -fr /app/browser/.git

# install Python dependencies
RUN --mount=type=cache,target=/root/.cache/pip,sharing=locked \
python -m pip install -U pip setuptools wheel \
&& python -m pip install -r requirements.txt

# hotpatch the path to the sqlite db file so it's in /data
RUN sed -iE 's|iib\.db|/data/iib.sqlite|g' /app/browser/scripts/iib/db/datamodel.py \
&& grep -q '/data/iib.sqlite' /app/browser/scripts/iib/db/datamodel.py \
|| (echo "Failed to hotpatch the sqlite db path!" && exit 1)

# copy in entrypoint script and set permissions
COPY --chown=root:root entrypoint.sh /app/entrypoint.sh
RUN chmod 755 /app/entrypoint.sh

# copy in default config
COPY --chown=root:root config.json /app/config.default.json

# set entrypoint
ENTRYPOINT ["/app/entrypoint.sh"]
CMD []
10 changes: 10 additions & 0 deletions browser/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"outdir_samples": "",
"outdir_txt2img_samples": "/output/txt2img",
"outdir_img2img_samples": "/output/img2img",
"outdir_extras_samples": "/output/extras",
"outdir_txt2img_grids": "/output/txt2img-grids",
"outdir_img2img_grids": "/output/img2img-grids",
"outdir_save": "/output/saved",
"outdir_grids": ""
}
47 changes: 47 additions & 0 deletions browser/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/usr/bin/env bash
set -euo pipefail

REPO_DIR=${REPO_DIR:-'/app/browser'}
IMAGES_DIR=${IMAGES_DIR:-'/output'}
BROWSER_PORT=${BROWSER_PORT-}

# make sure we're in the repo dir
cd ${REPO_DIR}

# fixed flags (needed for docker)
IIB_FLAGS='--host=0.0.0.0'

WEBUI_CONFIG_PATH=${WEBUI_CONFIG_PATH:-'/data/config/auto/config.json'}
if [[ ! -f ${WEBUI_CONFIG_PATH} ]]; then
echo \
"------------------------------------------------------------------------" \
" No config file found at ${WEBUI_CONFIG_PATH}, using default config. " \
" !!! Defaults assume your webui output dir is mounted at /outputs !!! " \
"------------------------------------------------------------------------"
WEBUI_CONFIG_PATH="/app/config.default.json"
fi

# if we have any args, and the first arg is not a flag, assume args are a command and exec it
if [[ $# -gt 0 ]] && [[ ! $1 =~ ^- ]]; then
echo "Command detected (first arg is not a flag), will not start server!"
echo "exec'ing command: $@"
exec "$@"
fi

# make temp dir and set env (thumbnail storage)
mkdir -p /data/.cache/iib
export TMPDIR=/data/.cache/iib

# add port flag if set
if [[ -n ${BROWSER_PORT} ]]; then
IIB_FLAGS="${IIB_FLAGS} --port=${BROWSER_PORT}"
fi

# check if the mounted /data volume has an IIB installation and pass the flag to use it
if [[ -d '/data/config/auto/extensions/sd-webui-infinite-image-browsing' ]]; then
echo 'Found IIB installation in mounted /data volume, enabling DB sharing mode'
IIB_FLAGS="${IIB_FLAGS} --sd_webui_dir=/data/config/auto"
fi

echo "Starting webui server with args: $@ --host=0.0.0.0"
exec python -u app.py --sd_webui_config=${WEBUI_CONFIG_PATH} "$@" ${IIB_FLAGS}
23 changes: 21 additions & 2 deletions docker-bake.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,20 @@ function torchSpec {

# build a tag for an image from this repo
function repoImage {
params = [imageName]
params = [imageTag]
variadic_params = extraVals
result = join(":", [
join("/", [IMAGE_REGISTRY, IMAGE_NAMESPACE]),
join("-", concat([imageName], extraVals))
join("-", concat([imageTag], extraVals))
])
}
# sub-image, REGISTRY/NAMESPACE/subimagename:
function subImage {
params = [subImageName, imageTag]
variadic_params = extraVals
result = join(":", [
join("/", [IMAGE_REGISTRY, IMAGE_NAMESPACE, subImageName]),
join("-", concat([imageTag], extraVals))
])
}

Expand Down Expand Up @@ -171,3 +180,13 @@ target "local-dev" {
]
args = {}
}

target "browser" {
inherits = ["common", "docker-metadata-action"]
context = "./browser"
dockerfile = "Dockerfile"
target = "browser"
tags = [
subImage("browser", "latest"),
]
}
24 changes: 24 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,27 @@ services:
source: ./output
target: /output

browser:
image: ghcr.io/neggles/sd-webui-docker/browser:latest
restart: unless-stopped
container_name: sd-browser
profiles:
- "browser"
build:
context: ./browser
dockerfile: Dockerfile
target: browser
environment:
BROWSER_PORT: 7869
ports:
- mode: ingress
target: 7869
published: 7869
protocol: tcp
volumes:
- type: bind
source: ./data
target: /data
- type: bind
source: ./output
target: /output

0 comments on commit efbc362

Please sign in to comment.