45 lines
2.2 KiB
Bash
45 lines
2.2 KiB
Bash
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
: "${REGISTRY_USER:?Dedicated registry user is required}"
|
|
: "${REGISTRY_TOKEN:?Dedicated registry token is required}"
|
|
: "${RELEASE_TOKEN:?Dedicated Gitea release token is required}"
|
|
: "${BUILD_SERVER_URL:?Gitea URL is required}"
|
|
: "${BUILD_REPOSITORY:?Repository is required}"
|
|
[[ "$BUILD_SERVER_URL" == https://sources.tordais.cc ]] || { echo 'Unexpected publication host' >&2; exit 1; }
|
|
[[ "$BUILD_REPOSITORY" == arnaud.dartois/Heimdall ]] || { echo 'Unexpected publication repository' >&2; exit 1; }
|
|
sha=$(git rev-parse HEAD)
|
|
tag=${BUILD_REF#refs/tags/}
|
|
[[ "$BUILD_REF" == refs/tags/v* ]] || exit 1
|
|
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 'v'+p['version'] != sys.argv[2]:
|
|
raise SystemExit('Artifact provenance does not match checkout/tag')
|
|
PY
|
|
(cd artifacts/packages && sha256sum --check SHA256SUMS)
|
|
printf '%s' "${tag#v}" > artifacts/version
|
|
bash scripts/ci/images.sh
|
|
# No mutation is attempted until all credentials, provenance and local builds pass.
|
|
export DOCKER_CONFIG
|
|
DOCKER_CONFIG=$(mktemp -d)
|
|
trap 'rm -rf "$DOCKER_CONFIG"' EXIT
|
|
printf '%s' "$REGISTRY_TOKEN" | docker login sources.tordais.cc -u "$REGISTRY_USER" --password-stdin
|
|
: > artifacts/image-digests.txt
|
|
for component in server agent; do
|
|
image="sources.tordais.cc/arnaud.dartois/heimdall-$component"
|
|
for image_tag in "sha-$sha" "${tag#v}"; 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 scripts/ci/release-gitea.py
|