-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
68 lines (58 loc) · 2.64 KB
/
Copy pathDockerfile
File metadata and controls
68 lines (58 loc) · 2.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# ImageForge — Dockerfile (CPU-only portable image)
# ===================================================
# HONEST SCOPE — read before you build this.
#
# ImageForge is designed for Apple-Silicon (MPS) and runs natively via the
# host venv (see README "Quick start" / ./start.sh). That is the recommended
# path on a Mac and the one with the proven benchmarks.
#
# Docker on macOS has NO MPS GPU passthrough, so a container can only run the
# engine on CPU — which is correct but slow (minutes per image, not seconds).
# This image therefore exists for:
# * portability / Linux servers / CI smoke tests,
# * exercising the HTTP API surface without a Mac,
# NOT for fast local generation on your Mac. For that, use ./start.sh.
#
# Build:
# docker build -t imageforge .
# Run (HTTP API on host port 8765):
# docker run --rm -p 8765:8765 imageforge
# # then: curl http://127.0.0.1:8765/health
#
# The heavy SD weights are downloaded from HuggingFace on first generation.
# Mount a cache to avoid re-downloading across runs:
# docker run --rm -p 8765:8765 \
# -v "$HOME/.cache/huggingface:/root/.cache/huggingface" \
# -v "$(pwd)/outputs:/app/outputs" imageforge
FROM python:3.11-slim
# System libs commonly needed by Pillow / diffusers image IO.
RUN apt-get update && apt-get install -y --no-install-recommends \
libgl1 libglib2.0-0 \
&& rm -rf /var/lib/apt/lists/*
WORKDIR /app
# Light HTTP/MCP layer first (good docker-layer caching).
RUN pip install --no-cache-dir \
fastapi "uvicorn[standard]" mcp pydantic pydantic-settings httpx
# Heavy SD stack — CPU torch (the default torch wheel is CPU on linux/amd64).
# Kept in a separate layer so the light layer above stays cache-stable.
RUN pip install --no-cache-dir \
torch torchvision \
diffusers transformers accelerate safetensors Pillow huggingface_hub
# App source (models/outputs/cache are git-ignored and created at runtime).
COPY imageforge/ ./imageforge/
COPY pyproject.toml .env.example ./
# CPU device inside the container; bind on all interfaces so -p works.
ENV DEVICE=cpu \
HOST=0.0.0.0 \
PORT=8765 \
IMAGEFORGE_MODEL=sd-turbo \
OUTPUT_DIR=/app/outputs \
CACHE_DIR=/app/cache \
MODELS_DIR=/app/models
EXPOSE 8765
# Container healthcheck hits /health (answers even before weights load).
HEALTHCHECK --interval=30s --timeout=5s --start-period=20s --retries=3 \
CMD python -c "import urllib.request,sys; \
sys.exit(0 if urllib.request.urlopen('http://127.0.0.1:8765/health',timeout=3).status==200 else 1)"
CMD ["python", "-m", "uvicorn", "imageforge.api.server:app", \
"--host", "0.0.0.0", "--port", "8765", "--log-level", "info"]