Implements comprehensive automated system for weekly transaction freeze periods with priority-based contested player resolution. New Features: - Weekly freeze/thaw task (Monday 00:00 freeze, Saturday 00:00 thaw) - Priority resolution for contested transactions (worst teams get first priority) - Admin league management commands (/freeze-begin, /freeze-end, /advance-week) - Enhanced API client to handle string-based transaction IDs (moveids) - Service layer methods for transaction cancellation, unfreezing, and bulk operations - Offseason mode configuration flag to disable freeze operations Technical Changes: - api/client.py: URL-encode object_id parameter to handle colons in moveids - bot.py: Initialize and shutdown transaction freeze task - config.py: Add offseason_flag to BotConfig - services/league_service.py: Add update_current_state() for week/freeze updates - services/transaction_service.py: Add cancel/unfreeze methods with bulk support - tasks/transaction_freeze.py: Main freeze/thaw automation with error recovery - commands/admin/league_management.py: Manual admin controls for freeze system Infrastructure: - .gitlab-ci.yml and .gitlab/: GitLab CI/CD pipeline configuration - .mcp.json: MCP server configuration - Dockerfile.versioned: Versioned Docker build support - .dockerignore: Added .gitlab/ to ignore list Testing: - tests/test_tasks_transaction_freeze.py: Comprehensive freeze task tests The system uses team standings to fairly resolve contested players (multiple teams trying to acquire the same player), with worst-record teams getting priority. Includes comprehensive error handling, GM notifications, and admin reporting. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
316 lines
6.0 KiB
Markdown
316 lines
6.0 KiB
Markdown
# GitLab CI/CD Quick Reference
|
|
|
|
Quick commands and reminders for daily development.
|
|
|
|
---
|
|
|
|
## 🔄 Common Workflows
|
|
|
|
### Deploy Feature to Production
|
|
|
|
```bash
|
|
# 1. Develop feature
|
|
git checkout -b feature/my-feature develop
|
|
# ... make changes ...
|
|
git commit -m "Add my feature"
|
|
git push gitlab feature/my-feature
|
|
|
|
# 2. Merge to develop for staging test (optional)
|
|
git checkout develop
|
|
git merge feature/my-feature
|
|
git push gitlab develop
|
|
# → Auto-deploys to staging
|
|
|
|
# 3. Merge to main
|
|
git checkout main
|
|
git merge develop
|
|
git push gitlab main
|
|
|
|
# 4. In GitLab UI: CI/CD > Pipelines > Click ▶️ on deploy:production
|
|
```
|
|
|
|
### Emergency Rollback
|
|
|
|
```bash
|
|
# Option 1: VPS Script (fastest)
|
|
ssh user@vps "cd /opt/discord-bot && ./rollback.sh"
|
|
|
|
# Option 2: GitLab UI
|
|
# CI/CD > Pipelines > Click ▶️ on rollback:production
|
|
|
|
# Option 3: Manual
|
|
ssh user@vps
|
|
cd /opt/discord-bot
|
|
# Edit docker-compose.yml to previous version
|
|
docker-compose up -d
|
|
```
|
|
|
|
### Check Deployment Status
|
|
|
|
```bash
|
|
# Check running version on VPS
|
|
ssh user@vps "cd /opt/discord-bot && docker inspect discord-bot --format '{{.Config.Labels}}' | grep version"
|
|
|
|
# Check recent deployments
|
|
ssh user@vps "cd /opt/discord-bot && tail -10 deployments.log"
|
|
|
|
# Check bot health
|
|
ssh user@vps "cd /opt/discord-bot && docker-compose ps"
|
|
```
|
|
|
|
---
|
|
|
|
## 🏷️ Version Management
|
|
|
|
### Current Version Strategy
|
|
|
|
| Format | Example | Auto/Manual | When |
|
|
|--------|---------|-------------|------|
|
|
| Major | `v2.x.x` | Manual | Breaking changes |
|
|
| Minor | `v2.1.x` | Manual | New features |
|
|
| Patch | `v2.1.123` | Auto | Every build |
|
|
|
|
### Bump Version
|
|
|
|
Edit `.gitlab-ci.yml`:
|
|
```yaml
|
|
variables:
|
|
VERSION_MAJOR: "2"
|
|
VERSION_MINOR: "2" # ← Change this
|
|
```
|
|
|
|
Then:
|
|
```bash
|
|
git add .gitlab-ci.yml
|
|
git commit -m "Bump version to v2.2.x"
|
|
git push gitlab main
|
|
```
|
|
|
|
---
|
|
|
|
## 🐳 Docker Tags Generated
|
|
|
|
Every build creates:
|
|
- `v2.1.123` - Full semantic version
|
|
- `a1b2c3d` - Git commit SHA
|
|
- `main-a1b2c3d` - Branch + SHA
|
|
- `latest` - Latest main branch (production)
|
|
- `staging` - Latest develop branch (staging)
|
|
|
|
---
|
|
|
|
## 🔍 Useful Commands
|
|
|
|
### Check Pipeline Status
|
|
```bash
|
|
# From CLI (requires gitlab-ci-lint or gitlab CLI)
|
|
gitlab-ci-lint .gitlab-ci.yml
|
|
|
|
# Or visit:
|
|
# https://gitlab.com/yourusername/discord-bot/-/pipelines
|
|
```
|
|
|
|
### View Logs
|
|
```bash
|
|
# Bot logs
|
|
ssh user@vps "cd /opt/discord-bot && docker-compose logs -f bot"
|
|
|
|
# Redis logs
|
|
ssh user@vps "cd /opt/discord-bot && docker-compose logs -f redis"
|
|
|
|
# Deployment history
|
|
ssh user@vps "cd /opt/discord-bot && cat deployments.log | column -t -s '|'"
|
|
```
|
|
|
|
### Test Locally Before Push
|
|
```bash
|
|
cd discord-app-v2
|
|
python -m pytest --tb=short -q
|
|
```
|
|
|
|
### Build Docker Image Locally
|
|
```bash
|
|
cd discord-app-v2
|
|
docker build \
|
|
--build-arg VERSION="dev" \
|
|
--build-arg GIT_COMMIT=$(git rev-parse --short HEAD) \
|
|
--build-arg BUILD_DATE=$(date -u +"%Y-%m-%dT%H:%M:%SZ") \
|
|
-t discord-bot-v2:local .
|
|
```
|
|
|
|
---
|
|
|
|
## 🎯 GitLab CI/CD Variables
|
|
|
|
**Required Variables** (Settings > CI/CD > Variables):
|
|
|
|
| Variable | Type | Example |
|
|
|----------|------|---------|
|
|
| `DOCKER_USERNAME` | Masked | `youruser` |
|
|
| `DOCKER_PASSWORD` | Masked | `dckr_pat_abc123...` |
|
|
| `SSH_PRIVATE_KEY` | Masked | `-----BEGIN OPENSSH...` |
|
|
| `VPS_HOST` | Plain | `123.456.789.0` |
|
|
| `VPS_USER` | Plain | `ubuntu` |
|
|
|
|
---
|
|
|
|
## 🚨 Emergency Procedures
|
|
|
|
### Build Failing
|
|
|
|
1. Check GitLab pipeline logs
|
|
2. Run tests locally: `pytest`
|
|
3. Check Docker build: `docker build ...`
|
|
4. Fix issues
|
|
5. Push again
|
|
|
|
### Deploy Failing
|
|
|
|
1. Check SSH access: `ssh user@vps`
|
|
2. Check docker-compose.yml exists
|
|
3. Check .env.production has all vars
|
|
4. Check VPS disk space: `df -h`
|
|
5. Check Docker is running: `docker ps`
|
|
|
|
### Bot Not Starting After Deploy
|
|
|
|
```bash
|
|
# SSH to VPS
|
|
ssh user@vps
|
|
cd /opt/discord-bot
|
|
|
|
# Check logs
|
|
docker-compose logs bot | tail -50
|
|
|
|
# Check health
|
|
docker-compose ps
|
|
|
|
# Restart
|
|
docker-compose restart bot
|
|
|
|
# Nuclear option: full restart
|
|
docker-compose down
|
|
docker-compose up -d
|
|
```
|
|
|
|
### Rollback Needed Immediately
|
|
|
|
```bash
|
|
# Fastest: VPS script
|
|
ssh user@vps "cd /opt/discord-bot && ./rollback.sh"
|
|
|
|
# Confirm version
|
|
ssh user@vps "cd /opt/discord-bot && docker-compose ps"
|
|
```
|
|
|
|
---
|
|
|
|
## 📊 Health Checks
|
|
|
|
### Bot Health
|
|
```bash
|
|
# Check if bot is healthy
|
|
ssh user@vps "docker inspect discord-bot --format '{{.State.Health.Status}}'"
|
|
# Should show: healthy
|
|
|
|
# Check Discord connection (in Discord)
|
|
/version
|
|
```
|
|
|
|
### Redis Health
|
|
```bash
|
|
ssh user@vps "docker exec discord-redis redis-cli ping"
|
|
# Should show: PONG
|
|
```
|
|
|
|
### Full System Check
|
|
```bash
|
|
ssh user@vps << 'EOF'
|
|
cd /opt/discord-bot
|
|
echo "=== Container Status ==="
|
|
docker-compose ps
|
|
echo ""
|
|
echo "=== Recent Logs ==="
|
|
docker-compose logs --tail=10 bot
|
|
echo ""
|
|
echo "=== Deployment History ==="
|
|
tail -5 deployments.log
|
|
EOF
|
|
```
|
|
|
|
---
|
|
|
|
## 🔐 Security Reminders
|
|
|
|
- ✅ Never commit `.env` files
|
|
- ✅ Use GitLab CI/CD variables for secrets
|
|
- ✅ Mark all secrets as "Masked" in GitLab
|
|
- ✅ Rotate SSH keys periodically
|
|
- ✅ Use Docker Hub access tokens, not passwords
|
|
- ✅ Keep VPS firewall enabled
|
|
|
|
---
|
|
|
|
## 📈 Monitoring
|
|
|
|
### Check Metrics
|
|
```bash
|
|
# If Prometheus is set up
|
|
curl http://vps-ip:8000/metrics
|
|
|
|
# Check bot uptime
|
|
ssh user@vps "docker inspect discord-bot --format '{{.State.StartedAt}}'"
|
|
```
|
|
|
|
### Watch Live Logs
|
|
```bash
|
|
ssh user@vps "cd /opt/discord-bot && docker-compose logs -f --tail=100"
|
|
```
|
|
|
|
---
|
|
|
|
## 🎓 Tips & Tricks
|
|
|
|
### Skip CI for Minor Changes
|
|
```bash
|
|
git commit -m "Update README [skip ci]"
|
|
```
|
|
|
|
### Test in Staging First
|
|
```bash
|
|
# Push to develop → auto-deploys to staging
|
|
git push gitlab develop
|
|
|
|
# Test thoroughly, then merge to main
|
|
```
|
|
|
|
### View All Available Versions
|
|
```bash
|
|
# On Docker Hub
|
|
docker search yourusername/discord-bot-v2
|
|
|
|
# On VPS
|
|
ssh user@vps "docker images yourusername/discord-bot-v2"
|
|
```
|
|
|
|
### Clean Up Old Images
|
|
```bash
|
|
# On VPS (run monthly)
|
|
ssh user@vps "docker image prune -a -f"
|
|
```
|
|
|
|
---
|
|
|
|
## 📞 Getting Help
|
|
|
|
1. **Check Logs**: Always start with logs
|
|
2. **GitLab Pipeline**: Look at failed job output
|
|
3. **Docker Logs**: `docker-compose logs`
|
|
4. **Deployment Log**: `cat deployments.log`
|
|
|
|
---
|
|
|
|
**Last Updated**: January 2025
|
|
**Bot Version**: v2.1.x
|
|
**CI/CD Platform**: GitLab CI/CD
|