Files
Heimdall/scripts/ci/publish.sh
T
arnaud.dartois ace7746695
Heimdall Gitea / Detect CI scope (push) Successful in 5s
Heimdall Gitea / Build and tests (push) Successful in 24m51s
Heimdall Gitea / Build and scan server image (push) Successful in 10m53s
Heimdall Gitea / Build and scan agent image (push) Successful in 10m33s
Heimdall Gitea / Build and scan NVIDIA Agent image (push) Successful in 14m22s
Heimdall Gitea / Publish Docker Hub latest tags (push) Successful in 2m3s
Heimdall Gitea / Publish signed main release (push) Failing after 44m2s
Heimdall Gitea / CI policy (push) Failing after 2s
feat(release): publish a signed release on every main merge (#312)
Refs #293

## Résumé
Chaque push de merge sur `main`, y compris documentation seule, passe les validations puis publie automatiquement une release signée par commit. Les notes listent les PR fusionnées. La release reste inaccessible à `latest` jusqu’à la fin de l’upload; les jobs retardés pour un commit dépassé publient une prérelease pour ne pas rétrograder `latest`. La version Central est affichée dans le menu latéral.

Aucun tag Git manuel ne déclenche le workflow. Gitea requiert un identifiant de tag pour l’objet Release; `ci-<SHA complet>` est créé automatiquement par l’API après les validations.

## Validation observée
- Restore verrouillé du projet Web.Tests réussi.
- `NavigationTests.MainLayout_AfficheVersionDuServeur` : 1/1 passé.
- Simulation offline : release complète publiée après upload, 10 assets, signature P-256, checksums, digests CPU/GPU et six pushes simulés; aucun Gitea/Docker Hub réel contacté.
- Compose source : `/healthz` sain et `/api/version` retournant `0.0.0-local`; ressources et tag exact retirés et vérifiés absents.
- `bash -n`, `py_compile`, parsing YAML et `git diff --check` réussis.

Le premier merge réel, la publication Gitea/Docker Hub et la lecture de `/releases/latest` depuis Central déployé restent à valider; l’issue #293 reste ouverte.

Skill : `skills/release-automation/SKILL.md`.

Reviewed-on: #312
Co-authored-by: Arnaud Dartois <admin@tordais.cc>
2026-11-09 10:10:22 +01:00

147 lines
6.6 KiB
Bash

#!/usr/bin/env bash
set -euo pipefail
: "${RELEASE_TOKEN:?Dedicated Gitea release token is required}"
: "${RELEASE_SIGNING_KEY_B64:?Publisher ECDSA P-256 private key is required}"
: "${BUILD_SERVER_URL:?Gitea URL is required}"
: "${EXPECTED_BUILD_SERVER_URL:?Expected Gitea URL is required}"
: "${BUILD_REPOSITORY:?Repository is required}"
python3 - "$BUILD_SERVER_URL" "$EXPECTED_BUILD_SERVER_URL" <<'PY'
import sys
from urllib.parse import urlsplit
actual, expected = (urlsplit(value) for value in sys.argv[1:])
def valid_origin(value):
return (value.scheme == 'https' and bool(value.hostname) and
value.path in ('', '/') and not value.query and not value.fragment and
value.username is None and value.password is None)
if (not valid_origin(actual) or not valid_origin(expected) or
actual.hostname.lower() != expected.hostname.lower() or
(actual.port or 443) != (expected.port or 443)):
raise SystemExit('Unexpected publication host')
PY
[[ "$BUILD_REPOSITORY" == arnaud.dartois/Heimdall ]] || { echo 'Unexpected publication repository' >&2; exit 1; }
sha=$(git rev-parse HEAD)
umask 077
signing_key=$(mktemp)
trap 'rm -f "$signing_key"' EXIT
printf '%s' "$RELEASE_SIGNING_KEY_B64" | base64 -d > "$signing_key"
openssl pkey -in "$signing_key" -noout >/dev/null
openssl ec -in "$signing_key" -noout -text 2>/dev/null | grep -q 'ASN1 OID: prime256v1' || {
echo 'Release signing key must use ECDSA P-256' >&2
exit 1
}
openssl pkey -in "$signing_key" -pubout -out artifacts/packages/agent-release-public.pem
(cd artifacts/packages && sha256sum agent-release-public.pem >> SHA256SUMS)
[[ "$BUILD_REF" == refs/heads/main ]] || { echo 'Release publication is restricted to verified main merges' >&2; exit 1; }
tag="ci-$sha"
python3 - "$sha" "$tag" <<'PY'
import json,sys
with open('artifacts/packages/provenance.json') as f:p=json.load(f)
if p['commit'] != sys.argv[1] or p['version'] != '0.0.0-ci.' + sys.argv[1][:12] or p['ref'] != 'refs/heads/main':
raise SystemExit('Artifact provenance does not match verified main commit')
PY
(cd artifacts/packages && sha256sum --check SHA256SUMS)
version=$(python3 -c 'import json;print(json.load(open("artifacts/packages/provenance.json"))["version"])')
printf '%s' "$version" > artifacts/version
bash scripts/ci/images.sh
for image_component in server agent agent-gpu; do
bash scripts/ci/security.sh "$image_component"
done
# 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 agent-gpu; do
if [[ "$component" == agent ]]; then
image=$agent_image
elif [[ "$component" == agent-gpu ]]; then
image=$agent_gpu_image
else
image=$server_image
fi
for image_tag in "sha-$sha" "$version"; do
if docker manifest inspect "$image:$image_tag" >/dev/null 2>&1; then
docker pull "$image:$image_tag"
revision=$(docker image inspect "$image:$image_tag" --format '{{index .Config.Labels "org.opencontainers.image.revision"}}')
[[ "$revision" == "$sha" ]] || { echo 'Refusing to overwrite an image from another commit' >&2; exit 1; }
else
docker tag "heimdall-$component:ci-$sha" "$image:$image_tag"
docker push "$image:$image_tag"
fi
docker image inspect "$image:$image_tag" --format '{{range .RepoDigests}}{{println .}}{{end}}' >> artifacts/image-digests.txt
done
done
cp artifacts/image-digests.txt artifacts/packages/image-digests.txt
(cd artifacts/packages && sha256sum image-digests.txt >> SHA256SUMS)
python3 - "$agent_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 agent image digest for configured repository')
with open('artifacts/packages/agent-image.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.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=package_version
assets={}
for path in root.glob('heimdall-agent-*.tar.gz'):
suffix=f'-{package_version}.tar.gz'
if not path.name.endswith(suffix):
continue
platform=path.name[len('heimdall-agent-'):-len(suffix)]
if not re.fullmatch(r'[a-z0-9-]+',platform):
raise SystemExit('Invalid agent archive platform')
assets[platform]=hashlib.sha256(path.read_bytes()).hexdigest()
if not assets:
raise SystemExit('No agent archive to sign')
payload={'version':version,'assets':assets,'containerImage':image['image'],
'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
openssl dgst -sha256 -sign "$signing_key" \
-out artifacts/packages/agent-update-manifest.sig artifacts/packages/agent-update-manifest.json
(cd artifacts/packages && sha256sum agent-update-manifest.json agent-update-manifest.sig >> SHA256SUMS)
python3 scripts/ci/release-gitea.py