This document describes the Continuous Integration and Continuous Deployment setup for the LinkKeeper project.
The CI pipeline runs automatically on:
- Push to
mainanddevelopbranches - Pull requests to
mainanddevelopbranches
- Environment: Ubuntu latest with PostgreSQL 16
- Steps:
- Checkout code
- Set up Go 1.23
- Install dependencies (including test libraries)
- Run
go fmtcheck - Run
go vetstatic analysis - Run all tests with race detector and coverage
- Upload coverage report to Codecov
- Environment: Ubuntu latest
- Steps:
- Checkout code
- Set up Go 1.23
- Run golangci-lint with 5-minute timeout
- Dependencies: Requires Test and Lint jobs to pass
- Steps:
- Checkout code
- Set up Go 1.23
- Build all three services (api-service, user-service, bot-service)
- Dependencies: Requires Test and Lint jobs to pass
- Trigger: Only on push to
mainbranch - Steps:
- Checkout code
- Set up Docker Buildx
- Build Docker images for all services
- Uses GitHub Actions cache for faster builds
Enabled linters:
bodyclose- Checks HTTP response body is closederrcheck- Checks for unchecked errorsgovet- Go vet analysisineffassign- Detects ineffectual assignmentsstaticcheck- Static analysis checksgosec- Security checksgocritic- Comprehensive Go code analysismisspell- Spell checkingdupl- Code duplication detectiongocyclo- Cyclomatic complexity- And more...
- Line length limit: 140 characters
- Minimum complexity for warning: 15
- Timeout: 5 minutes
Install hooks:
task hooks:install
# or
pre-commit install-
pre-commit/pre-commit-hooks:
- Remove trailing whitespace
- Fix end of files
- Check YAML syntax
- Detect large files
- Check for merge conflicts
- Detect private keys
-
dnephin/pre-commit-golang:
- Run
go fmt - Run
go vet - Run
go mod tidy - Run unit tests (with 30s timeout, short mode)
- Run
-
Local hooks:
- Run full test suite with race detector
task ci:localThis will run:
- Code formatting (
go fmt) - Linting (
go vet,golangci-lint) - All tests with coverage
# Format code
task fmt
# Run linter
task lint
# Run tests
task test
# Run tests with coverage
task test:coverage
# Run only unit tests
task test:unit
# Run only integration tests
task test:integrationCODECOV_TOKEN- (Optional) For Codecov integration
POSTGRES_DSN- Database connection stringTELEGRAM_TOKEN- Telegram bot tokenHTTP_ADDR- Service HTTP address
All services use multi-stage Docker builds:
- Build stage: Use
golang:latestwith full toolchain - Runtime stage: Use
debian:bookworm-slimfor smaller images
- GitHub Actions uses build cache to speed up builds
- Cache keys based on Go modules hash
# Build specific service
docker build -f build/api-service/Dockerfile -t api-service .
docker build -f build/user-service/Dockerfile -t user-service .
docker build -f build/bot-service/Dockerfile -t bot-service .
# Build all services
docker-compose build
# Build with task
task docker:build-
main- Production-ready code- Full CI pipeline + Docker builds
- Should always be stable
- Protected branch (requires PR reviews)
-
develop- Development branch- Full CI pipeline
- Integration of features
- Can be unstable
feature/*- New featuresbugfix/*- Bug fixeshotfix/*- Urgent production fixes
- Create feature branch from
develop - Make changes and commit
- Push and create PR to
develop - CI checks run automatically
- After review and CI pass, merge to
develop - Periodically merge
developtomain
- ✅ All tests pass
- ✅ No linter warnings
- ✅ Code coverage maintained
- ✅ Code review approved
- ✅ No merge conflicts
- ✅ Code formatted
- ✅
go vetpasses - ✅ Unit tests pass
- GitHub Actions notifications
- Codecov coverage reports
- Slack/Discord notifications
- Performance regression detection
- Security vulnerability scanning
- Dependency update notifications
- Deploy previews for frontend
-
Staging Deployment
- Automatic deployment on merge to
develop - Deploy to staging environment
- Run smoke tests
- Automatic deployment on merge to
-
Production Deployment
- Manual approval required
- Deploy on merge to
main - Blue-green deployment
- Automatic rollback on failure
-
Container Registry
- Push images to Docker Hub/GitHub Container Registry
- Tag with version/commit SHA
- Keep last 10 versions
# Clean cache
go clean -cache -testcache
# Run with same flags as CI
go test -v -race -coverprofile=coverage.out -covermode=atomic ./...
# Check formatting
gofmt -s -l .
# Run linter
golangci-lint run --timeout=5m# Clear Docker cache
docker system prune -a
# Build without cache
docker-compose build --no-cache
# Check Dockerfile syntax
docker build --check -f build/api-service/Dockerfile .# Update hooks
pre-commit autoupdate
# Run manually
pre-commit run --all-files
# Skip hooks (emergency only)
git commit --no-verify- Always run tests locally before pushing
- Keep commits small and focused
- Write meaningful commit messages (use Conventional Commits)
- Don't skip CI checks (only in emergencies)
- Monitor CI failures and fix quickly
- Keep dependencies updated regularly
- Add tests for bug fixes before fixing
- Review CI logs when tests fail
Use Conventional Commits:
<type>(<scope>): <subject>
<body>
<footer>
Types:
feat: New featurefix: Bug fixdocs: Documentation changesstyle: Code style changes (formatting)refactor: Code refactoringtest: Adding or updating testschore: Maintenance tasksci: CI/CD changes
Examples:
feat(user-service): add user registration endpoint
fix(api): handle nil pointer in link creation
test(user): add integration tests for user service
ci: add coverage upload to codecov