CI/CD Guide
Continuous Integration and Continuous Deployment for PiVirt.
Overview
Section titled “Overview”This guide covers the CI/CD pipeline for PiVirt, including automated testing, building, and deployment.
CI/CD Architecture
Section titled “CI/CD Architecture”flowchart LR
COMMIT["Commit<br/>(GitHub)"] --> BUILD["Build<br/>(Compile)"]
BUILD --> TEST["Test<br/>(Unit / Int)"]
TEST --> PKG["Package<br/>(Docker / Binary)"]
PKG --> DEPLOY["Deploy<br/>(Staging / Prod)"]
GitHub Actions
Section titled “GitHub Actions”Workflow Configuration
Section titled “Workflow Configuration”name: CI
on: push: branches: [main, develop] pull_request: branches: [main]
jobs: test: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4
- name: Set up Go uses: actions/setup-go@v5 with: go-version: '1.22'
- name: Run tests run: make test
- name: Run lint run: make lint
- name: Upload coverage uses: codecov/codecov-action@v4
build: needs: test runs-on: ubuntu-latest steps: - uses: actions/checkout@v4
- name: Set up Go uses: actions/setup-go@v5 with: go-version: '1.22'
- name: Build binaries run: make build
- name: Upload artifacts uses: actions/upload-artifact@v4 with: name: binaries path: bin/
docker: needs: build runs-on: ubuntu-latest steps: - uses: actions/checkout@v4
- name: Set up Docker Buildx uses: docker/setup-buildx-action@v3
- name: Login to registry uses: docker/login-action@v3 with: registry: registry.pilab.hu username: ${{ secrets.REGISTRY_USERNAME }} password: ${{ secrets.REGISTRY_PASSWORD }}
- name: Build and push uses: docker/build-push-action@v5 with: push: true tags: | registry.pilab.hu/pivirt/pivirtd:${{ github.sha }} registry.pilab.hu/pivirt/pivirtd:latestRelease Workflow
Section titled “Release Workflow”name: Release
on: push: tags: - 'v*'
jobs: release: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4
- name: Set up Go uses: actions/setup-go@v5 with: go-version: '1.22'
- name: Build release binaries run: make release-build
- name: Create GitHub Release uses: softprops/action-gh-release@v1 with: files: | bin/pivirtd-linux-amd64 bin/pivirtd-linux-arm64 bin/pvcli-linux-amd64 bin/pvcli-darwin-arm64 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}Testing
Section titled “Testing”Unit Tests
Section titled “Unit Tests”# Run all unit testsmake test
# Run specific package testsgo test ./apps/pivirtd/...
# Run with coveragemake test-coverageIntegration Tests
Section titled “Integration Tests”# Run integration testsmake test-integration
# Run with specific tagsgo test -tags=integration ./tests/integration/...End-to-End Tests
Section titled “End-to-End Tests”# Run E2E testsmake test-e2e
# Run with specific environmentE2E_ENV=staging make test-e2eBuild Pipeline
Section titled “Build Pipeline”Build Stages
Section titled “Build Stages”# Build pipeline stagesstages: - compile - test - package - deploy
compile: stage: compile script: - make build artifacts: paths: - bin/
test: stage: test script: - make test dependencies: - compile
package: stage: package script: - make docker-build dependencies: - compile
deploy: stage: deploy script: - deployer apply -f deploy/staging.yaml dependencies: - package only: - mainDeployment Pipeline
Section titled “Deployment Pipeline”Staging Deployment
Section titled “Staging Deployment”name: Deploy to Staging
on: push: branches: [develop]
jobs: deploy: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4
- name: Deploy to staging run: | deployer apply -f deploy/staging.yaml env: DEPLOYER_TOKEN: ${{ secrets.DEPLOYER_TOKEN }}Production Deployment
Section titled “Production Deployment”name: Deploy to Production
on: push: tags: - 'v*'
jobs: deploy: runs-on: ubuntu-latest environment: production steps: - uses: actions/checkout@v4
- name: Deploy to production run: | deployer apply -f deploy/production.yaml env: DEPLOYER_TOKEN: ${{ secrets.DEPLOYER_TOKEN }}Environment Management
Section titled “Environment Management”Environment Configuration
Section titled “Environment Configuration”apiVersion: deployer.pilab.hu/v1kind: Deploymentmetadata: name: "pivirt-staging" namespace: "staging"spec: version: "v0.0.89" replicas: control_plane: 1 workers: 2apiVersion: deployer.pilab.hu/v1kind: Deploymentmetadata: name: "pivirt-production" namespace: "production"spec: version: "v0.0.89" replicas: control_plane: 3 workers: 5Monitoring
Section titled “Monitoring”Pipeline Metrics
Section titled “Pipeline Metrics”# Check pipeline statusgh run list
# View pipeline logsgh run view <run-id> --logDeployment Metrics
Section titled “Deployment Metrics”# Check deployment statusdeployer status -n staging
# View deployment logsdeployer logs -n staging --followTroubleshooting
Section titled “Troubleshooting”Build Failures
Section titled “Build Failures”# Check build logsgh run view <run-id> --log
# Re-run failed jobgh run rerun <run-id> --failedDeployment Failures
Section titled “Deployment Failures”# Check deployment logsdeployer logs -n staging --tail 100
# Rollback deploymentdeployer rollback -n staging --revision 3