standalone build

This commit is contained in:
Michael Pilosov 2026-05-16 19:59:14 -06:00
parent 746635b570
commit b2ab86a8ad
3 changed files with 101 additions and 2 deletions

View File

@ -1,12 +1,27 @@
FROM python:3.13-slim
# BiRefNet background removal service — installs the published package on the CUDA 12.6 runtime.
# Same CUDA base family as the main ../Dockerfile, but installs rmbg-as-a-service from TestPyPI
# with a plain pip rather than building from the local source tree.
FROM nvidia/cuda:12.6.1-cudnn-runtime-ubuntu24.04
ENV DEBIAN_FRONTEND=noninteractive \
PYTHONUNBUFFERED=1 \
PIP_BREAK_SYSTEM_PACKAGES=1 \
HF_HOME=/app/hf_cache \
HF_HUB_ENABLE_HF_TRANSFER=1 \
PORT=8000
RUN pip install rmbg-as-a-service hf-transfer
# Ubuntu 24.04 ships Python 3.12 (the project requires >=3.12).
RUN apt-get update \
&& apt-get install -y --no-install-recommends python3 python3-pip ca-certificates \
&& rm -rf /var/lib/apt/lists/*
# rmbg-as-a-service from TestPyPI; its deps from real PyPI; CUDA torch from the PyTorch index.
# pip prefers torch's +cu126 build because the local version label outranks the plain wheel.
RUN pip install \
--index-url https://test.pypi.org/simple/ \
--extra-index-url https://pypi.org/simple/ \
--extra-index-url https://download.pytorch.org/whl/cu126 \
"rmbg-as-a-service==0.0.2" hf-transfer
EXPOSE 8000
CMD ["rmbg-as-a-service"]

53
build/Makefile Normal file
View File

@ -0,0 +1,53 @@
# mindthemath/rmbg image — build the published-package container, test it, push it.
# Override inline, e.g.: make release TAG=0.0.2
COMPOSE ?= docker compose
PYTHON ?= python3
IMAGE ?= mindthemath/rmbg
TAG ?= latest
PORT ?= 8000
INPUT ?= ../test.jpg
OUTPUT ?= output.png
BG ?= alpha
# Exported so compose.yml's ${TAG} interpolation picks it up.
export TAG
.DEFAULT_GOAL := help
.PHONY: help build run up stop down logs log ps shell test push release clean
help: ## Show this help
@grep -E '^[a-zA-Z_-]+:.*?## ' $(MAKEFILE_LIST) \
| awk 'BEGIN{FS=":.*?## "}{printf " \033[36m%-12s\033[0m %s\n", $$1, $$2}'
build: ## Build the mindthemath/rmbg image
$(COMPOSE) build
run up: ## Start the service (GPU) in the background
$(COMPOSE) up -d
stop down: ## Stop and remove the service container
$(COMPOSE) down
logs log: ## Follow service logs
$(COMPOSE) logs -f
ps: ## Show service status
$(COMPOSE) ps
shell: ## Open a shell inside a fresh container
$(COMPOSE) run --rm --entrypoint bash rmbg
test: ## Send INPUT to the running service, save OUTPUT
$(PYTHON) ../scripts/client.py --url http://localhost:$(PORT) \
--input $(INPUT) --output $(OUTPUT) --background $(BG)
push: ## Push mindthemath/rmbg:$(TAG) to Docker Hub (needs docker login)
docker push $(IMAGE):$(TAG)
release: build push ## Build then push mindthemath/rmbg:$(TAG)
clean: ## Stop the service and remove the built image
-$(COMPOSE) down
-docker image rm $(IMAGE):$(TAG)

31
build/compose.yml Normal file
View File

@ -0,0 +1,31 @@
# mindthemath/rmbg — runs the image built from the published (TestPyPI) package.
services:
rmbg:
build:
context: .
dockerfile: Dockerfile
image: mindthemath/rmbg:${TAG:-latest}
container_name: rmbg
ports:
- "${PORT:-8000}:8000"
environment:
- NVIDIA_VISIBLE_DEVICES=all
- NVIDIA_DRIVER_CAPABILITIES=compute,utility
# Default variant/resolution; both are also selectable per request.
- BIREFNET_MODEL=${BIREFNET_MODEL:-general}
- BIREFNET_RESOLUTION=${BIREFNET_RESOLUTION:-1024}
# Use the nvidia-container-runtime for GPU acceleration.
runtime: nvidia
volumes:
# Persist downloaded BiRefNet weights across container restarts.
- hf-cache:/app/hf_cache
healthcheck:
test: ["CMD", "python3", "-c", "import urllib.request; urllib.request.urlopen('http://localhost:8000/health')"]
interval: 15s
timeout: 5s
retries: 30
start_period: 180s
restart: unless-stopped
volumes:
hf-cache: