feat: 添加docker部署

This commit is contained in:
Leon
2025-12-30 01:21:09 +08:00
parent bbaffe4916
commit 562dc8de5f
7 changed files with 214 additions and 7 deletions

6
frontend/.dockerignore Normal file
View File

@@ -0,0 +1,6 @@
.git
node_modules
dist
**/*.log
npm-debug.log*

22
frontend/Dockerfile Normal file
View File

@@ -0,0 +1,22 @@
#
# Multi-stage build for Vue (Vite) frontend, served by Nginx.
#
# Build:
# docker build -f frontend/Dockerfile -t feedsystem-frontend .
#
FROM node:24-alpine AS build
WORKDIR /src
COPY frontend/package.json frontend/package-lock.json ./
RUN npm ci
COPY frontend/ ./
RUN npm run build
FROM nginx:1.27-alpine
COPY frontend/nginx.conf /etc/nginx/conf.d/default.conf
COPY --from=build /src/dist /usr/share/nginx/html
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]

23
frontend/nginx.conf Normal file
View File

@@ -0,0 +1,23 @@
server {
listen 80;
server_name _;
root /usr/share/nginx/html;
index index.html;
# SPA routing (Vue Router history mode)
location / {
try_files $uri $uri/ /index.html;
}
# Reverse proxy to backend (strip /api prefix)
location /api/ {
proxy_pass http://backend:8080/;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}