Configure Vast.ai CI/CD integration with GitHub Actions and testing.
Use when setting up automated testing, configuring CI pipelines,
or integrating Vast.ai tests into your build process.
Trigger with phrases like "vastai CI", "vastai GitHub Actions",
"vastai automated tests", "CI vastai".
Integrate Vast.ai GPU provisioning into CI/CD pipelines. Run GPU-accelerated tests, model validation, and benchmarks as part of your automated workflow using GitHub Actions with the Vast.ai CLI.
Prerequisites
GitHub repository with Actions enabled
VASTAI_API_KEY stored as GitHub Actions secret
Docker image for GPU workload published to a registry
# scripts/ci_gpu_test.py — wrapper with budget controls
import subprocess, json, time, sys, os
MAX_COST = float(os.environ.get("CI_GPU_BUDGET", "1.00")) # $1 max per run
MAX_DURATION = int(os.environ.get("CI_GPU_TIMEOUT", "1800")) # 30 min
def ci_gpu_test(test_command):
# Search for cheapest offer
offers = json.loads(subprocess.run(
["vastai", "search", "offers",
"num_gpus=1 gpu_ram>=8 reliability>0.90 dph_total<=0.20",
"--order", "dph_total", "--raw", "--limit", "1"],
capture_output=True, text=True, check=True).stdout)
if not offers:
print("No GPU offers available — skipping GPU tests")
return 0
cost_per_hour = offers[0]["dph_total"]
max_hours = MAX_COST / cost_per_hour
print(f"GPU: {offers[0]['gpu_name']} at ${cost_per_hour:.3f}/hr "
f"(budget allows {max_hours:.1f}hrs)")
# Provision, run, destroy (with timeout)
# ... (use managed_instance pattern from sdk-patterns)
Step 3: Mock Mode for Non-GPU CI
# conftest.py — skip GPU tests when no API key available
import pytest, os
def pytest_collection_modifyitems(config, items):
if not os.environ.get("VASTAI_API_KEY"):
skip_gpu = pytest.mark.skip(reason="VASTAI_API_KEY not set")
for item in items:
if "gpu" in item.keywords:
item.add_marker(skip_gpu)
Output
GitHub Actions workflow with GPU instance lifecycle