refactor: 统一 DB/Redis 配置为 DSN 模式 + 移除 Helm/K8s 部署

- DatabaseConfig: Host/Port/User/Password/Name/DBName/SSLMode → 单个 DSN 字段
- RedisConfig: Host/Port/Password/DB/URL → 单个 DSN 字段
- 环境变量: GOCHAT_DATABASE_* (7个) → GOCHAT_DATABASE_DSN, GOCHAT_REDIS_* (5个) → GOCHAT_REDIS_DSN
- validator.go: DSN URL 解析校验 (scheme + host)
- redis.go: redis.ParseURL(cfg.DSN) 直连
- 所有 docker-compose / CI / shell 脚本 / .env 同步更新
- 删除 deploy/helm/ 整个目录 (20个文件)
- CI 删除 helm-validate / deploy-staging / deploy-production 三个 job
- 文档同步更新 (README, 架构设计, PRD, 滚动升级)
This commit is contained in:
Rogee
2026-07-29 20:58:10 +08:00
parent 851ca7e372
commit 92f0d51375
46 changed files with 185 additions and 1464 deletions
+6 -108
View File
@@ -68,13 +68,8 @@ jobs:
env:
GOCHAT_ENV: test
GOCHAT_TEST_DB: ${{ matrix.db-mode }}
POSTGRES_HOST: localhost
POSTGRES_PORT: 5432
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: gochat_test
REDIS_HOST: localhost
REDIS_PORT: 6379
GOCHAT_DATABASE_DSN: postgres://postgres:postgres@localhost:5432/gochat_test?sslmode=disable
GOCHAT_REDIS_DSN: redis://localhost:6379
GOPROXY: https://goproxy.cn,direct
run: go test -v -race -coverprofile=coverage.out -timeout 180s ./internal/... ./pkg/... ./cmd/...
@@ -84,13 +79,8 @@ jobs:
working-directory: backend
env:
GOCHAT_ENV: test
POSTGRES_HOST: localhost
POSTGRES_PORT: 5432
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: gochat_test
REDIS_HOST: localhost
REDIS_PORT: 6379
GOCHAT_DATABASE_DSN: postgres://postgres:postgres@localhost:5432/gochat_test?sslmode=disable
GOCHAT_REDIS_DSN: redis://localhost:6379
run: go test -v -timeout 120s ./tests/e2e/...
# Benchmark (quick sanity check, not full bench)
@@ -99,11 +89,7 @@ jobs:
env:
GOCHAT_ENV: test
GOCHAT_TEST_DB: ${{ matrix.db-mode }}
POSTGRES_HOST: localhost
POSTGRES_PORT: 5432
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: gochat_test
GOCHAT_DATABASE_DSN: postgres://postgres:postgres@localhost:5432/gochat_test?sslmode=disable
run: go test -bench=. -benchtime=1s -run=^$ -timeout 60s ./internal/service/... ./pkg/crypto/...
# Coverage report
@@ -210,92 +196,4 @@ jobs:
image-ref: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.sha }}
format: 'table'
exit-code: '1'
severity: 'CRITICAL,HIGH'
# ---- Stage 4: Validate Helm Chart ----
helm-validate:
name: Validate Helm Chart
needs: test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Helm
uses: azure/setup-helm@v3
with:
version: 'v3.14.0'
- name: Set up kubeval
run: |
curl -sfL https://github.com/yannh/kubeconform/releases/download/v0.6.4/kubeconform-linux-amd64.tar.gz | tar -xz
chmod +x kubeconform && mv kubeconform /usr/local/bin/
- name: Lint Helm chart
run: helm lint deploy/helm/gochat/
- name: Template and validate Helm chart
run: |
helm template gochat deploy/helm/gochat/ \
--values deploy/helm/gochat/values.yaml \
--values deploy/helm/gochat/values-production.yaml \
| kubeconform -summary -kubernetes-version 1.29.0
# ---- Stage 5: Deploy to Staging ----
deploy-staging:
name: Deploy to Staging
needs: [build, helm-validate]
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/develop'
environment: staging
steps:
- uses: actions/checkout@v4
- name: Deploy to staging
uses: stefanprodan/helm-gh-action@v1.7.0
with:
context: ./deploy/helm/gochat
chart-ref: ./deploy/helm/gochat
cluster-config: staging-k8s-config
kube-config: ${{ secrets.KUBE_CONFIG_STAGING }}
namespace: gochat-staging
values: values.yaml
value-files: >-
values-staging.yaml
release-name: gochat-staging
atomic: true
# Post-deploy health check
- name: Health check
run: |
chmod +x backend/scripts/health_check.sh
GOCHAT_HOST=gochat-staging GOCHAT_PORT=3000 ./backend/scripts/health_check.sh --full --timeout 30
# ---- Stage 6: Deploy to Production ----
deploy-production:
name: Deploy to Production
needs: [build, helm-validate]
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/heads/release/')
environment: production
steps:
- uses: actions/checkout@v4
- name: Deploy to production
uses: stefanprodan/helm-gh-action@v1.7.0
with:
context: ./deploy/helm/gochat
chart-ref: ./deploy/helm/gochat
cluster-config: production-k8s-config
kube-config: ${{ secrets.KUBE_CONFIG_PRODUCTION }}
namespace: gochat-production
values: values.yaml
value-files: >-
values-production.yaml
release-name: gochat-production
atomic: true
# Post-deploy health check
- name: Health check
run: |
chmod +x backend/scripts/health_check.sh
GOCHAT_HOST=gochat-production GOCHAT_PORT=3000 ./backend/scripts/health_check.sh --full --timeout 30
severity: 'CRITICAL,HIGH'