8.4 KiB
CI/CD Configuration Guide
This project includes comprehensive CI/CD configurations for multiple platforms. Choose the one that best fits your infrastructure.
Table of Contents
GitHub Actions
Location
.github/workflows/ci.yml- Main CI/CD pipeline.github/workflows/release.yml- Release automation
Features
- ✅ Lint and type checking
- ✅ Unit and E2E tests
- ✅ Docker build and push to GHCR
- ✅ Security scanning with Trivy
- ✅ Automated deployments to staging/production
- ✅ Release creation with ZIP artifacts
Setup
-
Enable GitHub Actions in your repository settings
-
Configure secrets (Settings → Secrets and variables → Actions):
CODECOV_TOKEN # Optional: for code coverage reporting SLACK_WEBHOOK # Optional: for Slack notifications STAGING_WEBHOOK_URL # Webhook for staging deployment PRODUCTION_WEBHOOK_URL # Webhook for production deployment -
Enable GitHub Packages for Docker image storage (automatically enabled)
-
Branch Protection (recommended):
- Require status checks to pass before merging
- Require pull request reviews
Usage
- Push to
develop→ Runs tests and deploys to staging - Push to
main→ Runs full pipeline and deploys to production - Create tag
v*→ Triggers release workflow
GitLab CI
Location
.gitlab-ci.yml
Features
- ✅ Multi-stage pipeline with dependency caching
- ✅ Parallel test execution
- ✅ Docker build and push to GitLab Registry
- ✅ Security scanning and audit reports
- ✅ Manual approval for production deployments
Setup
-
Configure CI/CD variables (Settings → CI/CD → Variables):
STAGING_WEBHOOK_URL # Webhook for staging deployment PRODUCTION_WEBHOOK_URL # Webhook for production deployment -
Enable GitLab Container Registry (enabled by default)
-
Configure runners with Docker executor:
[[runners]] name = "docker-runner" executor = "docker" [runners.docker] image = "node:20-alpine" privileged = true
Usage
- Pipeline runs automatically on push
- Jobs are cached for faster execution
- Production deployment requires manual approval
Jenkins
Location
Jenkinsfile
Features
- ✅ Declarative pipeline with parallel stages
- ✅ Integration with Slack for notifications
- ✅ Artifact archiving and HTML report publishing
- ✅ Manual approval for production deployments
- ✅ Automatic workspace cleanup
Setup
-
Install required plugins:
- Pipeline
- NodeJS
- Docker Pipeline
- Slack Notification
- HTML Publisher
-
Configure Node.js (Manage Jenkins → Tools):
- Add Node.js installation named "Node 20"
- Version: 20.x
-
Configure credentials:
docker-registry-credentials # Username/password for GHCR -
Set environment variables in Jenkins configuration:
GIT_REPO_OWNER GIT_REPO_NAME STAGING_WEBHOOK_URL PRODUCTION_WEBHOOK_URL SLACK_CHANNEL -
Create multibranch pipeline:
- New Item → Multibranch Pipeline
- Add source: Git/GitHub
- Script Path: Jenkinsfile
Usage
- Pipeline triggers on SCM changes (polling or webhooks)
- View results in Blue Ocean interface
- Approve production deployments manually
CircleCI
Location
.circleci/config.yml
Features
- ✅ Workflow orchestration with job dependencies
- ✅ Docker layer caching for faster builds
- ✅ Slack notifications via orb
- ✅ Test result and artifact storage
- ✅ Approval step for production deployments
Setup
-
Connect repository to CircleCI
-
Configure environment variables (Project Settings → Environment Variables):
DOCKER_USERNAME # GitHub username DOCKER_PASSWORD # GitHub personal access token STAGING_WEBHOOK_URL # Webhook for staging deployment PRODUCTION_WEBHOOK_URL # Webhook for production deployment SLACK_ACCESS_TOKEN # Optional: for Slack notifications SLACK_DEFAULT_CHANNEL # Optional: default Slack channel -
Enable Docker Layer Caching (requires paid plan):
- Project Settings → Advanced → Enable Docker Layer Caching
Usage
- Pipeline runs on every push
- Manual approval required for production on
mainbranch - View detailed insights in CircleCI dashboard
Docker Setup
Files
Dockerfile- Multi-stage build for productiondocker-compose.yml- Local development and deploymentnginx.conf- Nginx configuration for serving app.dockerignore- Excludes unnecessary files
Build and Run Locally
# Build image
docker build -t codeforge:local .
# Run container
docker run -p 3000:80 codeforge:local
# Or use docker-compose
docker-compose up -d
Production Deployment
The Docker image is automatically built and pushed to GHCR:
# Pull latest image
docker pull ghcr.io/<username>/<repo>:latest
# Run in production
docker run -d \
-p 80:80 \
--name codeforge \
--restart unless-stopped \
ghcr.io/<username>/<repo>:latest
Health Checks
The container includes a health check endpoint at /health:
curl http://localhost:3000/health
# Response: healthy
Common Configuration
Environment Variables
All CI/CD platforms use these common environment variables:
| Variable | Description | Required |
|---|---|---|
NODE_VERSION |
Node.js version | Yes (default: 20) |
REGISTRY |
Docker registry URL | Yes (default: ghcr.io) |
IMAGE_NAME |
Docker image name | Yes |
STAGING_WEBHOOK_URL |
Staging deployment webhook | Optional |
PRODUCTION_WEBHOOK_URL |
Production deployment webhook | Optional |
CODECOV_TOKEN |
Codecov integration token | Optional |
SLACK_WEBHOOK |
Slack webhook URL | Optional |
Branch Strategy
main- Production branch, deploys to productiondevelop- Development branch, deploys to stagingfeature/*- Feature branches, runs tests onlyv*tags - Triggers release creation
Pipeline Stages
All pipelines follow a similar structure:
- Lint - ESLint and TypeScript checks
- Test - Unit tests with coverage
- Build - Application build
- E2E - Playwright end-to-end tests
- Security - npm audit and Trivy scan
- Docker - Build and push image
- Deploy - Staging (auto) and Production (manual)
Deployment Webhooks
Configure deployment webhooks to integrate with your hosting platform:
# Example webhook payload
{
"image": "ghcr.io/<username>/<repo>:latest",
"sha": "abc123",
"environment": "production"
}
Supported platforms:
- Vercel
- Netlify
- AWS ECS/EKS
- Kubernetes
- Custom deployment scripts
Troubleshooting
GitHub Actions
Issue: Docker push fails
Solution: Check GITHUB_TOKEN permissions in repository settings
Settings → Actions → General → Workflow permissions → Read and write
GitLab CI
Issue: Runner fails to pull image
Solution: Check runner has access to Docker
docker info # Should work on runner
Jenkins
Issue: Pipeline hangs on input step
Solution: Check Jenkins has sufficient executors
Manage Jenkins → Configure System → # of executors
CircleCI
Issue: Build fails with out of memory
Solution: Increase resource class in config.yml
resource_class: large # or xlarge
Additional Resources
- GitHub Actions Documentation
- GitLab CI/CD Documentation
- Jenkins Pipeline Documentation
- CircleCI Documentation
- Docker Documentation
Security Best Practices
- Never commit secrets to the repository
- Use environment variables for sensitive data
- Enable branch protection on main/develop branches
- Require code reviews before merging
- Run security scans in every pipeline
- Keep dependencies updated using Dependabot/Renovate
- Use signed commits for production deployments
- Implement RBAC for deployment approvals
License
This CI/CD configuration is part of CodeForge and follows the same license as the main project.