This guide covers building, testing, and contributing to the libvirt-volume-provisioner.
- Go 1.21 or higher
- Make
- libvirt-dev headers
- qemu-img
# Build for current platform
make build
# Build for Linux
make build-linux
# Build and install
sudo make install-systemd# Development image
make build-docker-dev
# Production image
make build-docker# Build .deb package
make deb
# Install locally
sudo dpkg -i libvirt-volume-provisioner_0.3.0_amd64.deb# Run all tests
make test
# Run tests with verbose output
go test -v ./...
# Run tests with coverage
go test -cover ./...
# Run specific test
go test -run TestAllocateImageFile ./...# Generate coverage report
go test -coverprofile=coverage.out ./...
# View coverage in browser (requires go-tool-cover)
go tool cover -html=coverage.out# Run all linters
make lint
# Individual linters
golangci-lint run
go vet ./...
go fmt ./...# Auto-fix formatting
go fmt ./...
# Auto-fix imports
goimports -w .# Clone repository
git clone https://github.com/rossigee/libvirt-volume-provisioner.git
cd libvirt-volume-provisioner
# Install dependencies
make deps
# Set environment variables
export MINIO_ENDPOINT="http://localhost:9000"
export MINIO_ACCESS_KEY="minioadmin"
export MINIO_SECRET_KEY="minioadmin"
export MINIO_USE_SSL="false"
export LVM_VOLUME_GROUP="vg0"
export LOG_LEVEL="debug"
export LOG_FORMAT="text"
# Run service
make run# Start MinIO in Docker
docker run -d \
--name minio \
-p 9000:9000 \
-e MINIO_ROOT_USER=minioadmin \
-e MINIO_ROOT_PASSWORD=minioadmin \
minio/minio server /data
# Create test bucket
mc mb local/vm-images
# Upload test image
mc cp ubuntu-20.04.qcow2 local/vm-images/.
├── cmd/
│ └── provisioner/ # Main entry point
├── internal/
│ ├── api/ # HTTP API handlers
│ ├── auth/ # Authentication
│ ├── jobs/ # Job management
│ ├── libvirt/ # libvirt integration
│ ├── lvm/ # LVM operations
│ ├── minio/ # MinIO client
│ ├── storage/ # Job database
│ └── retry/ # Retry logic
├── pkg/
│ └── types/ # Shared types
├── docs/ # Documentation
├── integration/ # Integration tests
├── Makefile # Build targets
└── README.md # Main documentation
- Follow Go conventions
- Use
go fmtfor formatting - Add comments for exported functions
- Write descriptive commit messages
- Keep lines under 100 characters
- Aim for >80% code coverage
- Test happy path and error paths
- Use table-driven tests for multiple scenarios
- Mock external dependencies (MinIO, libvirt, LVM)
Use semantic commit format:
type(scope): short description
Longer description if needed.
Fixes: #123
Types:
feat: New featurefix: Bug fixtest: Test-related changesdocs: Documentation changesrefactor: Code refactoringperf: Performance improvementschore: Build, CI, dependency updates
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Make your changes
- Run tests:
make test - Run linting:
make lint - Commit with semantic messages
- Push to your fork
- Create a Pull Request with description
- Ensure CI checks pass
- Request review from maintainers
Build with debug symbols:
# Build with debug info (larger binary)
go build -o libvirt-volume-provisioner -v \
-ldflags "-X main.version=dev" \
./cmd/provisioner
# Strip debug symbols (smaller binary)
strip libvirt-volume-provisioner# Enable CPU profiling
GODEBUG=http/2=0 pprof \
http://localhost:8080/debug/pprof/profile?seconds=30
# Analyze results
go tool pprof /tmp/profile.pb.gz# Get heap profile
curl http://localhost:8080/debug/pprof/heap > heap.pb.gz
# Analyze memory usage
go tool pprof heap.pb.gzSee Deployment for release procedures.