DOCKER_TESTING - Alteriom/painlessMesh GitHub Wiki
Docker Build & Test Scripts for painlessMesh
Quick Start
Prerequisites
- Install Docker Desktop for Windows: https://www.docker.com/products/docker-desktop/
- Ensure Docker is running (check system tray)
Run Tests (Automated)
# Build and run all tests
docker-compose up painlessmesh-test
# Or using plain Docker
docker build -t painlessmesh-test .
docker run --rm -v ${PWD}:/workspace painlessmesh-test
Interactive Development Shell
# Start interactive shell
docker-compose run --rm painlessmesh-dev
# Inside the container, you can:
cmake -G Ninja .
ninja
./bin/catch_mqtt_bridge
./bin/catch_alteriom_packages
# etc.
Available Commands
Build Docker Image
docker-compose build
Run Specific Test
docker-compose run --rm painlessmesh-test ./bin/catch_mqtt_bridge
Run All Tests
docker-compose up painlessmesh-test
Clean Build Artifacts
docker-compose down -v
Rebuild from Scratch
docker-compose build --no-cache
docker-compose up painlessmesh-test
CI/CD Integration
GitHub Actions Example
name: Test with Docker
on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Build and Test
run: |
docker build -t painlessmesh-test .
docker run --rm painlessmesh-test
Local PowerShell Script
Create test.ps1:
#!/usr/bin/env pwsh
Write-Host "Building Docker image..." -ForegroundColor Cyan
docker build -t painlessmesh-test .
Write-Host "`nRunning tests..." -ForegroundColor Cyan
docker run --rm painlessmesh-test
if ($LASTEXITCODE -eq 0) {
Write-Host "`nā
All tests passed!" -ForegroundColor Green
} else {
Write-Host "`nā Tests failed!" -ForegroundColor Red
exit 1
}
Run with: .\test.ps1
Troubleshooting
Docker Not Running
Error: Cannot connect to the Docker daemon
Solution: Start Docker Desktop from Windows Start Menu
Port Conflicts
If you see port binding errors, stop conflicting containers:
docker ps
docker stop <container_id>
Disk Space Issues
Clean up unused images and containers:
docker system prune -a
Build Cache Issues
Force rebuild without cache:
docker-compose build --no-cache
What Gets Tested
The Docker environment runs all Catch2 tests:
- ā
catch_mqtt_bridge- MQTT command routing and parameter parsing - ā
catch_alteriom_packages- Alteriom package serialization - ā
catch_protocol- Protocol validation - ā
catch_router- Mesh routing logic - ā
catch_plugin- Plugin system - ā
And all other
catch_*.cpptests
Benefits of Docker Testing
- Consistent Environment - Same results on all machines
- No Local Installation - No need for CMake, Ninja, compilers
- CI/CD Ready - Same container in development and CI
- Isolated - Doesn't affect your Windows installation
- Reproducible - Anyone can run tests identically
Integration with VS Code
Install the "Docker" extension, then you can:
- Right-click
Dockerfileā "Build Image" - Right-click
docker-compose.ymlā "Compose Up" - View logs in VS Code terminal
Performance Tips
Use BuildKit for Faster Builds
$env:DOCKER_BUILDKIT=1
docker build -t painlessmesh-test .
Mount Source as Volume (Faster Iteration)
docker run --rm -v ${PWD}:/workspace painlessmesh-test
This way, changes to source files don't require rebuilding the image.
Advanced Usage
Run Single Test File
docker-compose run --rm painlessmesh-test bash -c "cmake -G Ninja . && ninja && ./bin/catch_mqtt_bridge"
Debug Build
docker-compose run --rm painlessmesh-dev
# Inside container:
cmake -G Ninja -DCMAKE_BUILD_TYPE=Debug .
ninja
gdb ./bin/catch_mqtt_bridge
Check for Memory Leaks (with Valgrind)
Add to Dockerfile:
RUN apt-get update && apt-get install -y valgrind
Then run:
docker-compose run --rm painlessmesh-test valgrind ./bin/catch_mqtt_bridge