feat(agent): add optional pinned CUDA deployment variant
This commit is contained in:
1 parent
495740292a
commit
5c52c0e8f9
32 files changed
+537
-81
No files matched your search
@@ -24,6 +24,7 @@ DOCKER_TOKEN = 'offline-docker-token-not-valid'
|
||||
RELEASE_TOKEN = 'offline-gitea-token-not-valid'
|
||||
SERVER_DIGEST = 'sha256:' + '1' * 64
|
||||
AGENT_DIGEST = 'sha256:' + '2' * 64
|
||||
GPU_AGENT_DIGEST = 'sha256:' + '3' * 64
|
||||
|
||||
|
||||
def run(command, *, cwd, env, label):
|
||||
@@ -77,9 +78,32 @@ if args[:1] == ['push']:
|
||||
sys.exit(0) # Simulated push only; no registry client exists in this stub.
|
||||
if args[:2] == ['image', 'inspect']:
|
||||
image = args[2].split(':', 1)[0]
|
||||
digest = 'sha256:' + ('2' if image.endswith('heimdall-agent') else '1') * 64
|
||||
if image.endswith('heimdall-agent-gpu'):
|
||||
digest = os.environ['OFFLINE_GPU_DIGEST']
|
||||
elif image.endswith('heimdall-agent'):
|
||||
digest = os.environ['OFFLINE_AGENT_DIGEST']
|
||||
else:
|
||||
digest = os.environ['OFFLINE_SERVER_DIGEST']
|
||||
print(image + '@' + digest)
|
||||
sys.exit(0)
|
||||
if args[:1] == ['save']:
|
||||
from pathlib import Path
|
||||
Path(args[args.index('-o') + 1]).write_bytes(b'offline-image-archive')
|
||||
sys.exit(0)
|
||||
if args[:2] == ['volume', 'create']:
|
||||
print(args[2])
|
||||
sys.exit(0)
|
||||
if args[:1] == ['create']:
|
||||
print('offline-scanner-container')
|
||||
sys.exit(0)
|
||||
if args[:1] == ['cp'] or args[:1] == ['rm'] or args[:2] == ['volume', 'rm']:
|
||||
sys.exit(0)
|
||||
if args[:2] == ['start', '--attach']:
|
||||
print('{"Results":[]}')
|
||||
sys.exit(0)
|
||||
if args[:1] == ['inspect']:
|
||||
print('exited 0')
|
||||
sys.exit(0)
|
||||
sys.exit(12)
|
||||
'''
|
||||
docker_path = fakebin / 'docker'
|
||||
@@ -172,6 +196,9 @@ sys.exit(12)
|
||||
'RELEASE_TOKEN': RELEASE_TOKEN,
|
||||
'RELEASE_SIGNING_KEY_B64': signing_key_b64,
|
||||
'OFFLINE_DOCKER_LOG': str(docker_log),
|
||||
'OFFLINE_SERVER_DIGEST': SERVER_DIGEST,
|
||||
'OFFLINE_AGENT_DIGEST': AGENT_DIGEST,
|
||||
'OFFLINE_GPU_DIGEST': GPU_AGENT_DIGEST,
|
||||
})
|
||||
run(['bash', 'scripts/ci/package.sh'], cwd=ROOT, env=env, label='package.sh')
|
||||
run(['bash', 'scripts/ci/publish.sh'], cwd=ROOT, env=env, label='publish.sh')
|
||||
@@ -186,11 +213,15 @@ sys.exit(12)
|
||||
assert manifest['version'] == TAG
|
||||
assert manifest['containerImage'] == 'eltruncho/heimdall-agent'
|
||||
assert manifest['containerImageDigest'] == AGENT_DIGEST
|
||||
assert manifest['containerImageGpu'] == 'eltruncho/heimdall-agent-gpu'
|
||||
assert manifest['containerImageGpuDigest'] == GPU_AGENT_DIGEST
|
||||
provenance = json.loads(release_state['assets']['provenance.json'])
|
||||
commit = subprocess.check_output(['git', 'rev-parse', 'HEAD'], cwd=ROOT, text=True).strip()
|
||||
assert provenance['commit'] == commit and provenance['ref'] == 'refs/tags/' + TAG
|
||||
agent_image = json.loads(release_state['assets']['agent-image.json'])
|
||||
assert agent_image == {'digest': AGENT_DIGEST, 'image': 'eltruncho/heimdall-agent'}
|
||||
gpu_agent_image = json.loads(release_state['assets']['agent-image-gpu.json'])
|
||||
assert gpu_agent_image == {'digest': GPU_AGENT_DIGEST, 'image': 'eltruncho/heimdall-agent-gpu'}
|
||||
for platform, digest in manifest['assets'].items():
|
||||
archive = f'heimdall-agent-{platform}-{TAG.removeprefix("v")}.tar.gz'
|
||||
assert hashlib.sha256(release_state['assets'][archive]).hexdigest() == digest
|
||||
@@ -205,21 +236,23 @@ sys.exit(12)
|
||||
assert filename in release_state['assets'], f'missing checksum asset {filename}'
|
||||
assert hashlib.sha256(release_state['assets'][filename]).hexdigest() == digest, filename
|
||||
image_digests = release_state['assets']['image-digests.txt'].decode().splitlines()
|
||||
assert len(image_digests) == 4
|
||||
assert len(image_digests) == 6
|
||||
assert sum(AGENT_DIGEST in item for item in image_digests) == 2
|
||||
assert sum(GPU_AGENT_DIGEST in item for item in image_digests) == 2
|
||||
docker_calls = [json.loads(line) for line in docker_log.read_text().splitlines()]
|
||||
assert sum(call[:1] == ['build'] for call in docker_calls) == 2
|
||||
assert sum(call[:1] == ['build'] for call in docker_calls) == 3
|
||||
pushes = {call[1] for call in docker_calls if call[:1] == ['push']}
|
||||
assert len(pushes) == 4
|
||||
assert len(pushes) == 6
|
||||
assert pushes == {
|
||||
f'eltruncho/heimdall:sha-{commit}', f'eltruncho/heimdall:1.2.3',
|
||||
f'eltruncho/heimdall-agent:sha-{commit}', f'eltruncho/heimdall-agent:1.2.3',
|
||||
f'eltruncho/heimdall-agent-gpu:sha-{commit}', f'eltruncho/heimdall-agent-gpu:1.2.3',
|
||||
}
|
||||
assert sum(call[:1] == ['login'] for call in docker_calls) == 1
|
||||
assert release_state['draft']['draft'] is True
|
||||
assert len(release_state['assets']) >= 9
|
||||
assert release_state['authorized'] >= 7
|
||||
print(f'Offline release simulation passed: package archives, P-256 signature, {len(release_state["assets"])} draft assets, checksums, image digests, and four simulated pushes.')
|
||||
print(f'Offline release simulation passed: package archives, P-256 signature, {len(release_state["assets"])} draft assets, checksums, CPU/GPU image digests, and six simulated pushes.')
|
||||
print('No real Docker CLI, Docker Hub registry, or Gitea server was contacted.')
|
||||
finally:
|
||||
server.shutdown()
|
||||
|
||||
@@ -6,13 +6,14 @@ version=$(cat artifacts/version 2>/dev/null || printf '0.0.0-ci.%s' "${sha:0:12}
|
||||
: "${BUILD_REPOSITORY:?Gitea repository is required}"
|
||||
source_url="${BUILD_SERVER_URL%/}/${BUILD_REPOSITORY}"
|
||||
case "${1:-all}" in
|
||||
all) components=(server agent) ;;
|
||||
server|agent) components=("$1") ;;
|
||||
*) echo 'Usage: images.sh [server|agent|all]' >&2; exit 2 ;;
|
||||
all) components=(server agent agent-gpu) ;;
|
||||
server|agent|agent-gpu) components=("$1") ;;
|
||||
*) echo 'Usage: images.sh [server|agent|agent-gpu|all]' >&2; exit 2 ;;
|
||||
esac
|
||||
for component in "${components[@]}"; do
|
||||
file=docker/Dockerfile
|
||||
[[ "$component" == agent ]] && file=docker/Dockerfile.agent
|
||||
[[ "$component" == agent-gpu ]] && file=docker/Dockerfile.agent.gpu
|
||||
docker build --pull --platform linux/amd64 -f "$file" --build-arg "VERSION=$version" \
|
||||
--label "org.opencontainers.image.revision=$sha" \
|
||||
--label "org.opencontainers.image.version=$version" \
|
||||
|
||||
+25
-2
@@ -44,19 +44,23 @@ PY
|
||||
(cd artifacts/packages && sha256sum --check SHA256SUMS)
|
||||
printf '%s' "${tag#v}" > artifacts/version
|
||||
bash scripts/ci/images.sh
|
||||
bash scripts/ci/security.sh agent-gpu
|
||||
# No mutation is attempted until all credentials, provenance and local builds pass.
|
||||
export DOCKER_CONFIG
|
||||
DOCKER_CONFIG=$(mktemp -d)
|
||||
trap 'rm -rf "$DOCKER_CONFIG"; rm -f "$signing_key"' EXIT
|
||||
server_image=eltruncho/heimdall
|
||||
agent_image=eltruncho/heimdall-agent
|
||||
agent_gpu_image=eltruncho/heimdall-agent-gpu
|
||||
: "${DOCKERHUB_USERNAME:?Docker Hub user is required}"
|
||||
: "${DOCKERHUB_TOKEN:?Docker Hub token is required}"
|
||||
printf '%s' "$DOCKERHUB_TOKEN" | docker login docker.io -u "$DOCKERHUB_USERNAME" --password-stdin
|
||||
: > artifacts/image-digests.txt
|
||||
for component in server agent; do
|
||||
for component in server agent agent-gpu; do
|
||||
if [[ "$component" == agent ]]; then
|
||||
image=$agent_image
|
||||
elif [[ "$component" == agent-gpu ]]; then
|
||||
image=$agent_gpu_image
|
||||
else
|
||||
image=$server_image
|
||||
fi
|
||||
@@ -91,11 +95,29 @@ with open('artifacts/packages/agent-image.json','w') as f:
|
||||
f.write('\n')
|
||||
PY
|
||||
(cd artifacts/packages && sha256sum agent-image.json >> SHA256SUMS)
|
||||
python3 - "$agent_gpu_image" <<'PY'
|
||||
import json,sys
|
||||
repository=sys.argv[1]
|
||||
matches=set()
|
||||
for line in open('artifacts/image-digests.txt'):
|
||||
ref=line.strip()
|
||||
if '@' not in ref: continue
|
||||
image,digest=ref.rsplit('@',1)
|
||||
if image == repository and digest.startswith('sha256:') and len(digest) == 71:
|
||||
matches.add(digest)
|
||||
if len(matches) != 1:
|
||||
raise SystemExit('Expected one immutable GPU agent image digest for configured repository')
|
||||
with open('artifacts/packages/agent-image-gpu.json','w') as f:
|
||||
json.dump({'image':repository,'digest':matches.pop()},f,sort_keys=True,separators=(',',':'))
|
||||
f.write('\n')
|
||||
PY
|
||||
(cd artifacts/packages && sha256sum agent-image-gpu.json >> SHA256SUMS)
|
||||
python3 - <<'PY'
|
||||
import hashlib,json,re
|
||||
from pathlib import Path
|
||||
root=Path('artifacts/packages')
|
||||
image=json.loads((root/'agent-image.json').read_text())
|
||||
gpu_image=json.loads((root/'agent-image-gpu.json').read_text())
|
||||
package_version=Path('artifacts/version').read_text().strip()
|
||||
version='v'+package_version
|
||||
assets={}
|
||||
@@ -110,7 +132,8 @@ for path in root.glob('heimdall-agent-*.tar.gz'):
|
||||
if not assets:
|
||||
raise SystemExit('No agent archive to sign')
|
||||
payload={'version':version,'assets':assets,'containerImage':image['image'],
|
||||
'containerImageDigest':image['digest']}
|
||||
'containerImageDigest':image['digest'],'containerImageGpu':gpu_image['image'],
|
||||
'containerImageGpuDigest':gpu_image['digest']}
|
||||
(root/'agent-update-manifest.json').write_text(
|
||||
json.dumps(payload,sort_keys=True,separators=(',',':'))+'\n')
|
||||
PY
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
mode=${1:?Expected server, agent or latest}
|
||||
case "$mode" in server|agent|latest) ;; *) echo 'Usage: push-images.sh server|agent|latest' >&2; exit 2 ;; esac
|
||||
mode=${1:?Expected server, agent, agent-gpu or latest}
|
||||
case "$mode" in server|agent|agent-gpu|latest) ;; *) echo 'Usage: push-images.sh server|agent|agent-gpu|latest' >&2; exit 2 ;; esac
|
||||
sha=$(git rev-parse HEAD)
|
||||
if [[ "$mode" == latest ]]; then components=(server agent); else components=("$mode"); fi
|
||||
export DOCKER_CONFIG
|
||||
@@ -11,6 +11,7 @@ repository() {
|
||||
case "$1" in
|
||||
server) printf 'eltruncho/heimdall' ;;
|
||||
agent) printf 'eltruncho/heimdall-agent' ;;
|
||||
agent-gpu) printf 'eltruncho/heimdall-agent-gpu' ;;
|
||||
esac
|
||||
}
|
||||
: "${DOCKERHUB_USERNAME:?Docker Hub user is required}"
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
mode=${1:-all}
|
||||
case "$mode" in dependencies|server|agent|all) ;; *) echo 'Usage: security.sh [dependencies|server|agent|all]' >&2; exit 2 ;; esac
|
||||
case "$mode" in dependencies|server|agent|agent-gpu|all) ;; *) echo 'Usage: security.sh [dependencies|server|agent|agent-gpu|all]' >&2; exit 2 ;; esac
|
||||
skip_restore=false
|
||||
if [[ $# -gt 1 ]]; then
|
||||
if [[ "$mode" == dependencies && $# == 2 && "${2}" == --no-restore ]]; then
|
||||
@@ -71,7 +71,7 @@ scan_image() (
|
||||
exit 1
|
||||
)
|
||||
case "$mode" in
|
||||
all) components=(server agent) ;;
|
||||
all) components=(server agent agent-gpu) ;;
|
||||
*) components=("$mode") ;;
|
||||
esac
|
||||
for component in "${components[@]}"; do
|
||||
|
||||
@@ -83,6 +83,23 @@ class TestPlanTests(unittest.TestCase):
|
||||
self.assertEqual(len(planner.plan(['global.json'])['suites']), len(planner.TESTS))
|
||||
self.assertEqual(planner.plan(['docs/README.md'])['suites'], [])
|
||||
|
||||
class GpuAgentImageTests(unittest.TestCase):
|
||||
def test_cpu_default_stays_independent_of_nvidia_runtime(self):
|
||||
dockerfile = (REPO_ROOT/'docker/Dockerfile.agent').read_text()
|
||||
compose = (REPO_ROOT/'docker/docker-compose.agent.dev.yml').read_text()
|
||||
self.assertNotIn('nvidia/cuda', dockerfile)
|
||||
self.assertNotIn('Agent__InferenceExecutionProvider: CUDA', compose)
|
||||
self.assertNotIn('driver: nvidia', compose)
|
||||
|
||||
def test_gpu_runtime_and_optional_overlay_pin_cuda_runtime_and_provider(self):
|
||||
dockerfile = (REPO_ROOT/'docker/Dockerfile.agent.gpu').read_text()
|
||||
compose = (REPO_ROOT/'docker/docker-compose.agent.dev.gpu-nvidia.yml').read_text()
|
||||
self.assertIn('nvidia/cuda:12.8.1-cudnn-runtime-ubuntu24.04@sha256:9175fa92f96de35a8cfb9493f0dfcf9435c7a597e9d95ad41d2cae382a95e3f9', dockerfile)
|
||||
self.assertIn('Microsoft.ML.OnnxRuntime.Gpu', (REPO_ROOT/'src/Heimdall.Agent/Heimdall.Agent.csproj').read_text())
|
||||
self.assertIn('Agent__InferenceExecutionProvider: CUDA', compose)
|
||||
self.assertIn('driver: nvidia', compose)
|
||||
self.assertIn('capabilities: [gpu]', compose)
|
||||
|
||||
class AdvisoryTests(unittest.TestCase):
|
||||
def check(self, data):
|
||||
with tempfile.TemporaryDirectory() as temp:
|
||||
@@ -150,5 +167,14 @@ class ReleaseTests(unittest.TestCase):
|
||||
with self.assertRaisesRegex(SystemExit, 'already public'):
|
||||
self.execute(public=True)
|
||||
|
||||
class OfflineReleaseAcceptanceTests(unittest.TestCase):
|
||||
def test_publish_signs_and_uploads_cpu_and_gpu_image_manifests(self):
|
||||
result = subprocess.run(
|
||||
[sys.executable, str(ROOT/'accept-release-offline.py')],
|
||||
cwd=REPO_ROOT, capture_output=True, text=True)
|
||||
self.assertEqual(result.returncode, 0, result.stdout + result.stderr)
|
||||
self.assertIn('CPU/GPU image digests', result.stdout)
|
||||
self.assertIn('six simulated pushes', result.stdout)
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
@@ -21,6 +21,10 @@ for gpu in nvidia amd intel; do
|
||||
--profile "gpu-$gpu-inventory"
|
||||
done
|
||||
|
||||
compose -f docker/docker-compose.agent.dev.yml \
|
||||
-f docker/docker-compose.agent.dev.gpu-nvidia.yml \
|
||||
--profile gpu-nvidia
|
||||
|
||||
for required in DATABASE_URL POSTGRES_PASSWORD JWT__KEY JWT__REFRESHKEY; do
|
||||
if env "$required=" docker compose --env-file .env.example \
|
||||
-f docker/docker-compose.yml config --quiet >/dev/null 2>&1; then
|
||||
|
||||
Reference in new issue
Block a user