- 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, 滚动升级)
2.2 KiB
2.2 KiB
GoChat Rolling Upgrade Strategy
Reference: Chatwoot deployment uses zero-downtime upgrade pattern
Overview
GoChat follows a blue-green deployment strategy for production upgrades, ensuring zero downtime during version transitions.
Upgrade Process
Step 1: Pre-flight Checks
- Verify new Docker image is built and pushed:
docker pull gochat/gochat:${NEW_VERSION} - Run database migrations on a staging environment first
- Verify backward compatibility of migrations (new code must work with old schema)
- Check feature flags — new features should be disabled by default
Step 2: Database Migration
# Run migrations BEFORE deploying new code
# Migrations must be backward-compatible
docker compose -f docker-compose.prod.yml exec gochat /app/gochat migrate up
Step 3: Blue-Green Deployment (Docker Compose)
# 1. Deploy new version as "green" alongside "blue" (current)
docker compose -f docker-compose.prod.yml up -d --no-deps gochat-green
# 2. Wait for health check to pass
curl -f http://gochat-green:3000/health
# 3. Switch traffic (update nginx/upstream config)
# nginx: switch upstream from blue to green
# 4. Drain old connections on blue
# Wait 30s for in-flight requests to complete
# 5. Stop blue
docker compose -f docker-compose.prod.yml stop gochat
Step 4: Verification
- Smoke test: hit /health endpoint
- Check logs for errors:
docker compose logs gochat --since 5m - Verify metrics: Prometheus dashboard should show normal traffic
- Monitor for 15 minutes before finalizing
Step 5: Rollback (if needed)
# Docker Compose rollback
docker compose -f docker-compose.prod.yml exec gochat /app/gochat migrate down ${N}
docker compose -f docker-compose.prod.yml up -d --no-deps gochat-${OLD_VERSION}
Migration Compatibility Rules
- Migrations MUST be additive only in production (add columns, never remove)
- Column removals require a 2-phase migration: soft-remove then hard-remove
- New columns should have defaults or be nullable
- Renames require a 3-phase migration: add new → copy data → remove old
Worker Upgrade
Workers drain naturally: set a shutdown deadline, let in-flight jobs finish, then stop. New workers pick up queued jobs from Redis.