From 2a0e5e0de5f6219fe5bb37f9bf1e9da64bdcd0c2 Mon Sep 17 00:00:00 2001 From: "juancarlos.cavero" Date: Tue, 14 Jul 2026 15:32:01 +0200 Subject: [PATCH] chore(prod): production frontend build + skip AWS upload in cloud + /health MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - dashboard/Dockerfile: multi-stage — 'dev' (Vite HMR for local compose) and 'prod' (npm build -> nginx static serving, SPA fallback). Prod is the default target so Coolify builds the static app; VITE_API_URL is a build arg. - dashboard/nginx.conf: SPA routing + asset caching + basic security headers. - docker-compose.yml: local frontend targets the dev stage. - app.py: skip the redundant AWS S3 upload in cloud mode (R2 is the store now); add a /health liveness endpoint for uptime checks. Verified: prod image serves index.html + deep-link fallback (200). --- app.py | 13 ++++++++++--- dashboard/Dockerfile | 30 ++++++++++++++++++++++++------ dashboard/nginx.conf | 22 ++++++++++++++++++++++ docker-compose.yml | 4 +++- 4 files changed, 59 insertions(+), 10 deletions(-) create mode 100644 dashboard/nginx.conf diff --git a/app.py b/app.py index a42207e..dfe8ca3 100644 --- a/app.py +++ b/app.py @@ -489,9 +489,11 @@ async def run_job(job_id, job_data): jobs[job_id]['status'] = 'completed' jobs[job_id]['logs'].append("Process finished successfully.") - # Start S3 upload in background (silent, non-blocking) - loop = asyncio.get_event_loop() - loop.run_in_executor(None, upload_job_artifacts, output_dir, job_id) + # Self-host: silent AWS S3 backup. Cloud mode stores to R2 instead + # (see _archive_managed_job), so skip the redundant/paid AWS upload. + if not BILLING_ENABLED: + loop = asyncio.get_event_loop() + loop.run_in_executor(None, upload_job_artifacts, output_dir, job_id) # Find result JSON json_files = glob.glob(os.path.join(output_dir, "*_metadata.json")) @@ -525,6 +527,11 @@ async def run_job(job_id, job_data): jobs[job_id]['status'] = 'failed' jobs[job_id]['logs'].append(f"Execution error: {str(e)}") +@app.get("/health") +async def health(): + """Lightweight liveness probe for uptime monitoring / Coolify health checks.""" + return {"status": "ok"} + @app.get("/api/config") async def get_config(): return { diff --git a/dashboard/Dockerfile b/dashboard/Dockerfile index b807cb6..123e6ec 100644 --- a/dashboard/Dockerfile +++ b/dashboard/Dockerfile @@ -1,13 +1,31 @@ -FROM node:18-alpine +# Multi-stage: `dev` for local docker-compose (HMR), `prod` for Coolify/production. +# The prod stage is last, so `docker build` (and Coolify) produce the static build +# by default. Local docker-compose targets the `dev` stage explicitly. +# ---- deps + dev server (local) ---- +FROM node:18-alpine AS dev WORKDIR /app - COPY package.json package-lock.json* ./ - RUN npm install - COPY . . - EXPOSE 5173 - CMD ["npm", "run", "dev", "--", "--host"] + +# ---- production build ---- +FROM node:18-alpine AS build +WORKDIR /app +COPY package.json package-lock.json* ./ +RUN npm install +COPY . . +# Vite bakes env at BUILD time. Set VITE_API_URL to the backend's public URL +# (Coolify: add it as a build variable on the frontend service). Empty = same-origin. +ARG VITE_API_URL="" +ENV VITE_API_URL=$VITE_API_URL +RUN npm run build + +# ---- static serving (nginx) ---- +FROM nginx:alpine AS prod +COPY --from=build /app/dist /usr/share/nginx/html +COPY nginx.conf /etc/nginx/conf.d/default.conf +EXPOSE 80 +CMD ["nginx", "-g", "daemon off;"] diff --git a/dashboard/nginx.conf b/dashboard/nginx.conf new file mode 100644 index 0000000..ff17587 --- /dev/null +++ b/dashboard/nginx.conf @@ -0,0 +1,22 @@ +server { + listen 80; + server_name _; + root /usr/share/nginx/html; + index index.html; + + # Cache hashed assets aggressively; never cache index.html. + location /assets/ { + expires 1y; + add_header Cache-Control "public, immutable"; + try_files $uri =404; + } + + # SPA: serve index.html for any route (hash routing / deep links). + location / { + try_files $uri $uri/ /index.html; + } + + # Basic security headers. + add_header X-Content-Type-Options "nosniff" always; + add_header X-Frame-Options "SAMEORIGIN" always; +} diff --git a/docker-compose.yml b/docker-compose.yml index fa544be..0dfae06 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -11,7 +11,9 @@ services: restart: unless-stopped frontend: - build: ./dashboard + build: + context: ./dashboard + target: dev container_name: openshorts-frontend ports: - "5175:5173"