Skip to content

CI/CD Guide

Continuous Integration and Continuous Deployment for PiVirt.

This guide covers the CI/CD pipeline for PiVirt, including automated testing, building, and deployment.

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/workflows/ci.yml
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:latest
.github/workflows/release.yml
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 }}
Terminal window
# Run all unit tests
make test
# Run specific package tests
go test ./apps/pivirtd/...
# Run with coverage
make test-coverage
Terminal window
# Run integration tests
make test-integration
# Run with specific tags
go test -tags=integration ./tests/integration/...
Terminal window
# Run E2E tests
make test-e2e
# Run with specific environment
E2E_ENV=staging make test-e2e
# Build pipeline stages
stages:
- 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:
- main
.github/workflows/deploy-staging.yml
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 }}
.github/workflows/deploy-prod.yml
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 }}
deploy/staging.yaml
apiVersion: deployer.pilab.hu/v1
kind: Deployment
metadata:
name: "pivirt-staging"
namespace: "staging"
spec:
version: "v0.0.89"
replicas:
control_plane: 1
workers: 2
deploy/production.yaml
apiVersion: deployer.pilab.hu/v1
kind: Deployment
metadata:
name: "pivirt-production"
namespace: "production"
spec:
version: "v0.0.89"
replicas:
control_plane: 3
workers: 5
Terminal window
# Check pipeline status
gh run list
# View pipeline logs
gh run view <run-id> --log
Terminal window
# Check deployment status
deployer status -n staging
# View deployment logs
deployer logs -n staging --follow
Terminal window
# Check build logs
gh run view <run-id> --log
# Re-run failed job
gh run rerun <run-id> --failed
Terminal window
# Check deployment logs
deployer logs -n staging --tail 100
# Rollback deployment
deployer rollback -n staging --revision 3