feat: 移除仓库内 nginx 并拆分前端运行时
This commit is contained in:
@@ -2,11 +2,11 @@
|
||||
|
||||
> **For Claude:** REQUIRED SUB-SKILL: Use superpowers:executing-plans to implement this plan task-by-task.
|
||||
|
||||
**Goal:** Convert the repository's only `docker-compose.yaml` from development deployment to production deployment using static frontend assets served by Nginx.
|
||||
**Goal:** Convert the repository's only `docker-compose.yaml` from development deployment to production deployment using standalone frontend and backend runtime images.
|
||||
|
||||
**Architecture:** The backend runs as a production FastAPI container, the frontend is built into static assets during image build, and Nginx serves the SPA while reverse proxying backend routes. PostgreSQL remains persistent through the existing `pg_data` bind mount.
|
||||
**Architecture:** The backend runs as a production FastAPI container, the frontend is built into a standalone runtime image that serves the SPA itself, and an external reverse proxy routes browser and API traffic to the correct container. PostgreSQL remains persistent through the existing `pg_data` bind mount.
|
||||
|
||||
**Tech Stack:** Docker Compose, FastAPI, Vue/Vite, Nginx, PostgreSQL
|
||||
**Tech Stack:** Docker Compose, FastAPI, Vue/Vite, Node.js, PostgreSQL
|
||||
|
||||
---
|
||||
|
||||
@@ -19,27 +19,27 @@
|
||||
|
||||
Update the Dockerfile so a Node build stage runs dependency install and `npm run build`, then a lightweight stage exposes the built `dist` directory for downstream use instead of running `npm run dev`.
|
||||
|
||||
**Step 2: Keep the output suitable for Nginx consumption**
|
||||
**Step 2: Keep the output suitable for frontend runtime consumption**
|
||||
|
||||
Ensure the final stage stores frontend assets in a predictable directory such as `/usr/share/nginx/html`.
|
||||
Ensure the final stage stores frontend assets in a predictable directory and starts a static server on a stable port.
|
||||
|
||||
**Step 3: Verify the image definition is syntactically valid**
|
||||
|
||||
Run: `docker compose config`
|
||||
Expected: compose renders successfully with no Dockerfile-related errors.
|
||||
|
||||
### Task 2: Productionize Nginx Runtime
|
||||
### Task 2: Productionize Frontend Runtime
|
||||
|
||||
**Files:**
|
||||
- Modify: `nginx/nginx.conf`
|
||||
- Modify: `frontend/Dockerfile`
|
||||
|
||||
**Step 1: Add static frontend serving**
|
||||
|
||||
Set the web root to the built frontend assets and add `try_files $uri $uri/ /index.html;` for SPA routing.
|
||||
Use the runtime image to expose a frontend port and serve the compiled SPA directly.
|
||||
|
||||
**Step 2: Keep backend reverse proxy behavior**
|
||||
**Step 2: Leave reverse proxy behavior to external infrastructure**
|
||||
|
||||
Preserve `/api/` and `/health` proxying to `backend:8000` with standard forwarded headers.
|
||||
Do not embed repository-owned reverse proxy configuration; document that `/` routes to `frontend` and `/api` plus `/health` route to `backend`.
|
||||
|
||||
**Step 3: Verify config structure through compose-backed startup**
|
||||
|
||||
@@ -55,13 +55,13 @@ Expected: compose renders successfully.
|
||||
|
||||
Delete `frontend`, `frontend-init`, and `backend-init`, and remove bind mounts, debug ports, and development commands that are only useful for hot reload or scaffolding.
|
||||
|
||||
**Step 2: Wire backend and nginx for production**
|
||||
**Step 2: Wire backend and frontend for production**
|
||||
|
||||
Allow the backend to use its Dockerfile default command, keep the database dependency, and expose only the ports needed for the production stack.
|
||||
|
||||
**Step 3: Build frontend assets into nginx**
|
||||
**Step 3: Add standalone frontend service**
|
||||
|
||||
Point the Nginx service build to a production image definition that includes the built frontend output.
|
||||
Point the frontend service build to `frontend/Dockerfile` and give it a registry-backed image reference.
|
||||
|
||||
**Step 4: Verify rendered compose**
|
||||
|
||||
@@ -79,12 +79,12 @@ Document that `docker-compose.yaml` is now the production deployment entrypoint.
|
||||
|
||||
**Step 2: Add minimal verification commands**
|
||||
|
||||
Document `docker compose up -d --build`, plus health checks for `/` and `/health`.
|
||||
Document `docker compose up -d --build`, plus direct health checks for the frontend and backend containers.
|
||||
|
||||
**Step 3: Verify behavior**
|
||||
|
||||
Run: `docker compose up -d --build`
|
||||
Expected: `db`, `backend`, and `nginx` start successfully.
|
||||
Expected: `db`, `backend`, and `frontend` start successfully.
|
||||
|
||||
### Task 5: End-to-End Verification
|
||||
|
||||
@@ -103,8 +103,8 @@ Expected: PASS
|
||||
|
||||
**Step 3: Check HTTP endpoints**
|
||||
|
||||
Run: `curl -i http://127.0.0.1/`
|
||||
Run: `curl -i http://127.0.0.1:4173/`
|
||||
Expected: `200 OK` and HTML payload
|
||||
|
||||
Run: `curl -i http://127.0.0.1/health`
|
||||
Run: `curl -i http://127.0.0.1:8000/health`
|
||||
Expected: successful backend health response
|
||||
|
||||
Reference in New Issue
Block a user