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
