A distributed system for testing Git commits in isolated Kubernetes environments using WebSocket communication. Built to catch regressions before they hit production.
- Real-time Test Pipeline - WebSocket-based test orchestration
- K8s Isolation - Dedicated namespaces per test session
- Commit-by-Commit Testing - Test multiple commits in sequence
- Custom Test Commands - Override default test behavior
- Failure Forensics - Detailed error logging and output capture
sequenceDiagram
Client->>Server: Connect via WS
Client->>Server: Send commit+test command
Server->>K8s: Create namespace
Server->>K8s: Deploy test pod
K8s->>TestPod: Clone repo
K8s->>TestPod: Checkout commit
K8s->>TestPod: Run tests
TestPod->>Server: JSON results
Server->>Client: Return results
Choose your connection method β [ AWS EKS | Manual Kubeconfig ]
graph TD
A[Connection Type] --> B{AWS EKS?}
B -->|Yes| C[Use AWS Mode]
B -->|No| D[Use Manual Config]
D --> E[Standalone Kubeconfig]
Requirements:
- AWS credentials with EKS access
- Cluster name and region
# .env configuration
KUBECONFIG_MODE=aws
AWS_ACCESS_KEY_ID=AKIA...
AWS_SECRET_ACCESS_KEY=secret
AWS_DEFAULT_REGION=us-west-2
KUBE_CLUSTER_NAME=prod-clusterFor: Non-AWS clusters or pre-configured access
Steps:
-
Place kubeconfig in project root:
mkdir -p kubeconfig cp ~/.kube/config kubeconfig/prod-cluster.yaml -
Configure environment:
# .env KUBECONFIG_MODE=manual KUBECONFIG_FILE=./kubeconfig/prod-cluster.yaml -
Verify connection:
docker compose run --rm backendim-brain kubectl cluster-info
| Error | Solution |
|---|---|
server has asked for credentials |
Ensure AWS creds are set even in manual mode for AWS-based configs |
x509 certificate unknown |
Embed CA cert directly in kubeconfig |
permission denied |
Check kubeconfig file permissions: chmod 600 kubeconfig/* |
no such file |
Verify volume mount path in docker-compose.yml |
backend.im-infra/
βββ deployments/ # Kubernetes deployment templates
β βββ templates/
β βββ fastapi/ # FastAPI-specific resources
β βββ Dockerfile # Base image for FastAPI test pods
β βββ test-pod.yaml # Pod specification for FastAPI tests
βββ scripts/ # Operational scripts
β βββ git_handler.sh # Handles repo cloning/checkout
β βββ healthcheck.sh # Service health monitoring
β βββ install-awscli.sh # AWS CLI setup in containers
β βββ install-kubectl.sh # Kubectl installation
β βββ kube-init.sh # Cluster connection bootstrap
β βββ namespace_handler.py # K8s namespace management
β βββ test-runner.py # Core test execution logic
βββ app/ # Example FastAPI service (test subject)
β βββ main.py # Sample API endpoints
β βββ tests/ # Test cases for example service
β β βββ test_success.py # Valid test cases
β β βββ test_fail.py # Intentional failure cases
β βββ pyproject.toml # Python project config
βββ internal/ # Go server implementation
β βββ handlers/ # WebSocket connection handling
β β βββ websocket.go # WS message processing
β βββ models/ # Data structures
β β βββ message.go # WS message formats
β βββ services/ # Core business logic
β βββ namespace_service.go # K8s ns operations
β βββ test_service.go # Test execution orchestration
βββ cmd/ # Server entrypoints
β βββ server/
β βββ main.go # WebSocket server main
βββ config/ # Configuration files
β βββ config.json # Active configuration
β βββ config.example.json # Configuration template
βββ docker/ # Container definitions
β βββ Dockerfile # Main application image
β βββ docker-compose.yml # Local development setup
βββ .github/
βββ workflows/ # CI/CD pipelines
βββ cd.yml # Deployment automation
- Kubernetes cluster (Docker Desktop K8s works)
kubectlconfigured and working- Python 3.9+ (client side)
- Go 1.18+ (server side)
git clone https://github.com/obiMadu/backend.im-infra
cd backend.im-infra# Install dependencies
make deps
# Start server (port 8080)
make runpython3 -m venv .venv
source .venv/bin/activate
pip install -r app/requirements.txt
# Copy and edit config
cp config.example.json config.json
nano config.json # Set your repo and commitspython3 scripts/client.pyconfig.json
{
"ws_url": "ws://your-server-url/ws",
"repo_url": "https://github.com/your/repo.git",
"user_id": "your-user-id",
"chat_id": "your-chat-id",
"project_type": "fastapi",
"test_command": "pytest -v tests/network/",
"commits": ["HEAD~2", "HEAD~1", "HEAD"]
}Override default test behavior in config.json:
{
"test_command": "mvn test -Dtest=SmokeTestSuite"
}Supported formats:
- Simple commands:
npm test - Chained commands:
make test && coverage report - Script paths:
bash tests/e2e.sh
Create required K8s templates:
mkdir -p deployments/templates/fastapi/
# Add your test-pod.yaml here# Verify server is running
curl -I http://localhost:8080/health
# Check firewall rules
sudo ufw allow 8080/tcpCheck pod logs:
kubectl logs -n im-chat-14-user-14 test-pod- Client connects via WebSocket
- Server creates isolated K8s namespace
- Test pod deploys with project-specific template
- Repo is cloned/updated in pod
- Target commit is checked out
- Custom test command executes
- Results stream back via WebSocket
Q: How are resources cleaned up?
Namespaces persist for debugging. Manual cleanup:
kubectl delete namespace im-chat-14-user-14Q: Can I modify the test pod?
Edit templates in deployments/templates/<project-type>/test-pod.yaml
Q: What's the performance overhead?
Each test run uses ~300MB RAM. Scale namespaces as needed.
AGPL-3.0 - Fuck around and find out edition
