## Summary This PR sets up the complete CI/CD infrastructure for the Chat Switchboard project, implementing automated testing, linting, building, and Docker containerization. ## Changes ### CI/CD Workflows 1. **`.gitea/workflows/backend.yml`** - Backend CI pipeline - Automated Go module initialization - Test execution with coverage reporting - Code linting with golangci-lint - Binary compilation with version tags - Artifact upload for debugging 2. **`.gitea/workflows/frontend.yml`** - Frontend CI pipeline - JavaScript linting with ESLint - CSS validation with Prettier - Standalone HTML build via build.sh - HTML structure validation - Build artifact management 3. **`.gitea/workflows/docker.yml`** - Docker CI pipeline - Backend container building and testing - Frontend container building - Automatic image tagging on tags/branches - Registry push on main branch - Multi-arch manifest creation ### Docker Configuration - `server/Dockerfile` - Multi-stage Go backend container with health checks - `Dockerfile.frontend` - Nginx frontend container with gzip compression - `nginx.conf` - Optimized nginx config with security headers ### Dependencies - `server/go.mod` - Initialized Go module with Gin and godotenv ### Documentation - `docs/CICD_SETUP.md` - Comprehensive CI/CD documentation ## Features - ✅ Auto-trigger on push/PR to main/develop - ✅ Test coverage reporting - ✅ Code quality checks (golangci-lint, ESLint) - ✅ Build artifact management (7-day retention) - ✅ Semantic versioning support (v* tags) - ✅ Multi-stage Docker builds - ✅ Container health checks - ✅ Security headers in nginx - ✅ Gzip compression - ✅ Non-root container execution ## Testing The workflows will automatically run on this PR. Once merged, all future PRs and pushes to main/develop will trigger the appropriate CI checks. ## Acceptance Criteria - ✅ All PRs run CI checks - ✅ Docker images auto-build on tags - ✅ Standalone build generates on each commit ## Next Steps (Manual) 1. Merge this PR to `main` 2. Create `develop` branch: `git checkout main && git checkout -b develop && git push origin develop` 3. Configure branch protection in Gitea (Settings → Branches → Add protection rule for main/develop) 4. Test with a sample PR to verify CI runs ## Breaking Changes None. This is purely infrastructure setup with no impact on existing functionality. Reviewed-on: xcaliber/chat-switchboard#22
5.3 KiB
CI/CD Infrastructure Setup - Chat Switchboard
This document outlines the CI/CD infrastructure that has been set up for the Chat Switchboard project.
Overview
The project uses Gitea Actions for CI/CD, configured with three primary workflows:
- Backend CI - Go backend testing, linting, and building
- Frontend CI - JavaScript/CSS linting and standalone build
- Docker CI - Container image building and publishing
Workflows
Backend CI (.gitea/workflows/backend.yml)
Triggers:
- Push to
server/**orgo.modonmainordevelop - Pull requests targeting
mainordevelop
Jobs:
- test - Runs Go tests with coverage
- lint - Runs golangci-lint
- build - Compiles Go binary (requires test & lint to pass)
Features:
- Auto-initializes Go module if missing
- Uploads coverage reports to Codecov
- Builds with version tags from git
- Caches Go modules for faster builds
Frontend CI (.gitea/workflows/frontend.yml)
Triggers:
- Push to
frontend/**,src/**, orbuild.shonmainordevelop - Pull requests targeting
mainordevelop
Jobs:
- lint - ESLint for JavaScript, Prettier for CSS
- build - Generates standalone HTML via build.sh
- validate - Validates HTML structure
Features:
- Auto-generates eslint config if missing
- Validates build output structure
- Uploads standalone build as artifact
Docker CI (.gitea/workflows/docker.yml)
Triggers:
- Push to
mainordevelopwith Dockerfile changes - Pull requests targeting
mainordevelop - Tag creation (
v*pattern)
Jobs:
- build - Builds and tests containers
- metadata - Generates image tags
- push - Pushes images to registry
- manifest - Creates multi-arch manifests (main branch only)
Features:
- Multi-stage Docker builds
- Cache from GitHub Actions cache
- Auto-tagging based on git refs
- Security headers in nginx config
- Health checks for containers
Docker Images
Backend Image
Location: server/Dockerfile
Build Process:
- Multi-stage build (builder → runtime)
- Auto-generates version from git tags
- Non-root user for security
- Health check endpoint
Usage:
docker build -t chat-switchboard-backend ./server
docker run -p 8080:8080 chat-switchboard-backend
Frontend Image
Location: Dockerfile.frontend
Build Process:
- Builds standalone HTML in builder stage
- Serves via nginx in production stage
- Gzip compression enabled
- Security headers added
Usage:
docker build -t chat-switchboard-frontend -f Dockerfile.frontend .
docker run -p 80:80 chat-switchboard-frontend
Branch Strategy
Branches:
main- Production branchdevelop- Development branch (to be created)- Feature branches - Created from
develop
Workflow:
- Create feature branch from
develop - Make changes and push
- Create PR to
develop - CI runs automatically on PR
- Merge to
developafter review - Create PR from
developtomainfor releases
Getting Started
For Developers
-
Clone the repository
git clone https://git.gobha.me/xcaliber/chat-switchboard.git cd chat-switchboard -
Create feature branch
git checkout -b feature/my-feature develop -
Make changes and test locally
# Backend cd server && go test ./... # Frontend ./build.sh -
Push and create PR
git push origin feature/my-feature # Create PR via web interface -
CI will automatically run on your PR
For Maintainers
-
Branch Protection (requires admin access)
- Go to Repository Settings → Branches
- Add protection rule for
mainanddevelop - Require pull request reviews
- Require status checks to pass
- Select required CI checks
-
Creating a Release
# Create tag git tag -a v1.0.0 -m "Release v1.0.0" git push origin v1.0.0This will:
- Trigger Docker CI
- Build and push images with version tag
- Update
latesttag on main branch
Environment Variables
Docker Registry
Images are pushed to GitHub Container Registry:
- Backend:
ghcr.io/xcaliber/chat-switchboard-backend - Frontend:
ghcr.io/xcaliber/chat-switchboard-frontend
Authentication is handled via GITHUB_TOKEN.
Monitoring & Logs
Docker Health Checks
Both containers include health checks:
- Backend:
/healthendpoint - Frontend: HTTP check on port 80
CI Status
Check CI status in:
- Gitea repository → Actions tab
- Pull request checks section
Troubleshooting
Common Issues
1. Go module initialization fails
cd server
go mod init git.gobha.me/xcaliber/chat-switchboard
go mod tidy
2. Frontend build fails
chmod +x build.sh
./build.sh
3. Docker build fails
# Check if Dockerfile exists
ls -la server/Dockerfile
ls -la Dockerfile.frontend
# Build manually
docker build -t test ./server
Viewing CI Logs
- Go to Repository → Actions
- Select the workflow run
- View job logs for details
Future Enhancements
Planned improvements:
- Semantic versioning automation
- Automatic changelog generation
- Integration tests in CI
- Security scanning (Trivy, Snyk)
- Performance benchmarks
- Multi-arch builds (arm64/amd64)