diff --git a/.dockerignore b/.dockerignore index 05e8db2..c8a6475 100644 --- a/.dockerignore +++ b/.dockerignore @@ -26,6 +26,10 @@ Dockerfile .dockerignore tmp/ +# WebApp build artifacts (regenerated inside Docker) +bot/app/web/templates/subscription_webapp.css +bot/app/web/templates/subscription_webapp.min.*.js + # Byte-compiled / optimized / DLL files **/__pycache__/ **/*.py[cod] diff --git a/.gitignore b/.gitignore index d53fd8a..af83b61 100644 --- a/.gitignore +++ b/.gitignore @@ -10,6 +10,10 @@ scratch_*.py node_modules/ .git/ +# WebApp build artifacts (regenerated by `npm run build:webapp` / Docker build) +bot/app/web/templates/subscription_webapp.css +bot/app/web/templates/subscription_webapp.min.*.js + # Игнорировать кэш Python __pycache__/ diff --git a/Dockerfile b/Dockerfile index a5346d1..7a6aa89 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM python:3.12-slim AS builder +FROM python:3.12-slim AS python-builder WORKDIR /app @@ -7,16 +7,39 @@ COPY requirements.txt . RUN --mount=type=cache,target=/root/.cache/pip \ pip install --no-cache-dir -r requirements.txt + +FROM node:22-slim AS webapp-builder + +WORKDIR /webapp + +COPY package.json package-lock.json* ./ +RUN --mount=type=cache,target=/root/.npm \ + if [ -f package-lock.json ]; then npm ci; else npm install; fi + +COPY bot/app/web/templates ./bot/app/web/templates +COPY scripts/build_subscription_webapp_js.mjs ./scripts/build_subscription_webapp_js.mjs + +RUN npm run build:webapp + + FROM python:3.12-slim WORKDIR /app RUN useradd -u 10001 -m appuser -COPY --from=builder /usr/local/lib/python3.12/site-packages /usr/local/lib/python3.12/site-packages +COPY --from=python-builder /usr/local/lib/python3.12/site-packages /usr/local/lib/python3.12/site-packages COPY . . +# Replace template assets with freshly built ones +RUN rm -f bot/app/web/templates/subscription_webapp.css \ + bot/app/web/templates/subscription_webapp.min.*.js +COPY --from=webapp-builder /webapp/bot/app/web/templates/subscription_webapp.css \ + bot/app/web/templates/subscription_webapp.css +COPY --from=webapp-builder /webapp/bot/app/web/templates/subscription_webapp.min.*.js \ + bot/app/web/templates/ + RUN rm -rf /root/.cache RUN mkdir -p /app/logs /app/data && chown -R appuser:appuser /app/logs /app/data