chore(prod): production frontend build + skip AWS upload in cloud + /health
- 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).
This commit is contained in:
parent
0ba4fac47b
commit
2a0e5e0de5
4 changed files with 59 additions and 10 deletions
9
app.py
9
app.py
|
|
@ -489,7 +489,9 @@ 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)
|
||||
# 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)
|
||||
|
||||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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;"]
|
||||
|
|
|
|||
22
dashboard/nginx.conf
Normal file
22
dashboard/nginx.conf
Normal file
|
|
@ -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;
|
||||
}
|
||||
|
|
@ -11,7 +11,9 @@ services:
|
|||
restart: unless-stopped
|
||||
|
||||
frontend:
|
||||
build: ./dashboard
|
||||
build:
|
||||
context: ./dashboard
|
||||
target: dev
|
||||
container_name: openshorts-frontend
|
||||
ports:
|
||||
- "5175:5173"
|
||||
|
|
|
|||
Loading…
Reference in a new issue