fix(photo-ai): build weights in an isolated stage and stop blocking app deploys

Prefetch moved to a separate python:3.10-slim stage that only sees weights.py/fetch-weights.py, so editing app.py or vendor/ no longer invalidates the 360 MB weights layer. Weight catalog and download helpers extracted to photo-ai/weights.py; fetch-weights.py no longer imports app (torch). Cache mount switched to sharing=shared: a canceled build could leave the exclusive lock held and hang the next build forever; downloads now use a pid-unique tmp file, so concurrent builds cannot corrupt it. Docs recommend 'docker compose up -d --build app' for app updates instead of rebuilding photo-ai/face-id.
This commit is contained in:
dev
2026-10-23 10:09:58 +03:00
parent 7a2f8893a6
commit d0a17c5f62
8 changed files with 203 additions and 133 deletions
+19 -11
View File
@@ -1,4 +1,21 @@
# syntax=docker/dockerfile:1
FROM python:3.10-slim AS weights
ARG PHOTO_AI_PREFETCH=codeformer
WORKDIR /seed
COPY weights.py fetch-weights.py ./
RUN --mount=type=cache,target=/var/cache/photo-ai-weights,sharing=shared \
mkdir -p /opt/photo-ai-seed && \
if [ -n "$PHOTO_AI_PREFETCH" ] && [ "$PHOTO_AI_PREFETCH" != "none" ]; then \
PHOTO_AI_PREFETCH="$PHOTO_AI_PREFETCH" python fetch-weights.py /opt/photo-ai-seed /var/cache/photo-ai-weights || echo "предзагрузка весов не удалась, сервис скачает их при первом запросе"; \
else \
echo "предзагрузка весов отключена (PHOTO_AI_PREFETCH=$PHOTO_AI_PREFETCH)"; \
fi
FROM python:3.10-slim
ARG TORCH_VARIANT=cpu
@@ -39,23 +56,14 @@ RUN BASICSR_DEG=$(python -c "import basicsr; import os; print(os.path.join(os.pa
echo "basicsr degradations.py not found, skipping patch"; \
fi
COPY app.py ./
COPY fetch-weights.py ./
COPY weights.py app.py fetch-weights.py ./
COPY vendor/ ./vendor/
ENV PHOTO_AI_MODELS_DIR=/models
ENV MODEL_PATH=/models/RealESRGAN_x2plus.pth
ENV PHOTO_AI_SEED_DIR=/opt/photo-ai-seed
ARG PHOTO_AI_PREFETCH=codeformer
RUN --mount=type=cache,target=/var/cache/photo-ai-weights,sharing=locked \
mkdir -p "$PHOTO_AI_SEED_DIR" && \
if [ -n "$PHOTO_AI_PREFETCH" ] && [ "$PHOTO_AI_PREFETCH" != "none" ]; then \
python fetch-weights.py "$PHOTO_AI_SEED_DIR" /var/cache/photo-ai-weights || echo "предзагрузка весов не удалась, сервис скачает их при первом запросе"; \
else \
echo "предзагрузка весов отключена (PHOTO_AI_PREFETCH=$PHOTO_AI_PREFETCH)"; \
fi
COPY --from=weights /opt/photo-ai-seed /opt/photo-ai-seed
VOLUME /models