feat(deploy): dev compose runs full stack with source mounts, delve, shared volumes; vite proxy target via env (dlv --accept-multiclient, GOPROXY=goproxy.cn in dev image)

This commit is contained in:
2026-09-07 21:04:40 +08:00
parent 0ea918fae6
commit 0de824cc6a
5 changed files with 44 additions and 4 deletions
+3 -1
View File
@@ -3,6 +3,8 @@ WORKDIR /app
FROM base AS dev FROM base AS dev
# 源码由 compose 挂载进 /app;镜像只带工具链 + delve # 源码由 compose 挂载进 /app;镜像只带工具链 + delve
# 国内直连 proxy.golang.org 会超时,goproxy.cn 走直连
ENV GOPROXY=https://goproxy.cn,direct
RUN go install github.com/go-delve/delve/cmd/dlv@latest RUN go install github.com/go-delve/delve/cmd/dlv@latest
EXPOSE 8080 2345 EXPOSE 8080 2345
CMD ["sh", "-c", "go mod download && dlv debug ./cmd/server --headless --listen=0.0.0.0:2345 --api-version=2 --continue --log"] CMD ["sh", "-c", "go mod download && dlv debug ./cmd/server --headless --listen=0.0.0.0:2345 --api-version=2 --accept-multiclient --continue --log"]
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
+40 -2
View File
@@ -1,10 +1,48 @@
# dev:源码热挂载 + target: dev 镜像 + delve :2345,infra 端口暴露宿主,healthcheck 门控
# 起停用 down(不是 rm),否则 web 的匿名 node_modules 卷会成孤儿
name: booklib name: booklib
services: services:
postgres: postgres:
image: postgres:16-alpine image: postgres:16-alpine
environment: { POSTGRES_USER: lib, POSTGRES_PASSWORD: lib, POSTGRES_DB: lib } environment: { POSTGRES_USER: lib, POSTGRES_PASSWORD: lib, POSTGRES_DB: lib }
ports: ["5433:5432"] ports: ["5432:5432"]
volumes: [postgres_data:/var/lib/postgresql/data]
healthcheck: { test: ["CMD-SHELL", "pg_isready -U lib"], interval: 2s, timeout: 2s, retries: 30 } healthcheck: { test: ["CMD-SHELL", "pg_isready -U lib"], interval: 2s, timeout: 2s, retries: 30 }
redis: redis:
image: redis:7-alpine image: redis:7-alpine
ports: ["6380:6379"] command: ["redis-server", "/usr/local/etc/redis/redis.conf"]
ports: ["6379:6379"]
volumes:
- ./redis/redis.conf:/usr/local/etc/redis/redis.conf:ro
- redis_data:/data
api:
build: { context: .., dockerfile: backend/Dockerfile.dev, target: dev }
command: sh -c "go mod download && dlv debug ./cmd/server --headless --listen=0.0.0.0:2345 --api-version=2 --accept-multiclient --continue --log"
environment:
DATABASE_URL: postgres://lib:lib@postgres:5432/lib?sslmode=disable
REDIS_URL: redis://redis:6379
JWT_SECRET: ${JWT_SECRET}
ADMIN_USER: ${ADMIN_USER}
ADMIN_PASSWORD: ${ADMIN_PASSWORD}
BOOKS_DIR: /data/books
CACHE_DIR: /data/books/cache
SCAN_INTERVAL_SEC: ${SCAN_INTERVAL_SEC:-60}
volumes:
- ../backend:/app
- ./api/storage:/data/books
ports: ["${DELVE_PORT:-2345}:2345"]
depends_on:
postgres: { condition: service_healthy }
redis: { condition: service_started }
web:
build: { context: .., dockerfile: web/Dockerfile.dev, target: dev }
command: npm run dev -- --host 0.0.0.0
environment: { VITE_PROXY_TARGET: http://api:8080 }
volumes:
- ../web:/app
- /app/node_modules
ports: ["5173:5173"]
depends_on: [api]
volumes:
postgres_data:
redis_data:
+1 -1
View File
@@ -46,5 +46,5 @@ export default defineConfig({
}, },
}), }),
], ],
server: { proxy: { "/api": "http://localhost:8080" } }, server: { proxy: { "/api": process.env.VITE_PROXY_TARGET ?? "http://localhost:8080" } },
}); });