36 lines
1.7 KiB
Bash
36 lines
1.7 KiB
Bash
#!/bin/sh
|
|
set -eu
|
|
set +x
|
|
: "${REGISTRY_USER:?bind registry credentials}"
|
|
: "${REGISTRY_TOKEN:?bind registry credentials}"
|
|
image=git.yebilly.me/ssw590-group1/pricing
|
|
commit=$(git rev-parse HEAD)
|
|
reports=build/delivery/reports
|
|
mkdir -p "$reports" build/delivery/releases
|
|
export DOCKER_CONFIG
|
|
DOCKER_CONFIG=$(mktemp -d)
|
|
trap 'rm -rf "$DOCKER_CONFIG"' EXIT
|
|
printf '%s' "$REGISTRY_TOKEN" | docker login --username "$REGISTRY_USER" --password-stdin git.yebilly.me
|
|
# Never overwrite a source-commit tag during a retry.
|
|
if docker manifest inspect "$image:$commit" > "$reports/existing-manifest.json" 2> "$reports/manifest-check.log"; then
|
|
docker pull "$image:$commit"
|
|
else
|
|
if ! grep -Eqi 'manifest unknown|no such manifest|not found' "$reports/manifest-check.log"; then
|
|
cat "$reports/manifest-check.log" >&2
|
|
exit 1
|
|
fi
|
|
if [ -n "${DELIVERY_BUILDER:-}" ]; then
|
|
docker buildx build --builder "$DELIVERY_BUILDER" --load --platform linux/amd64 \
|
|
--build-arg "APP_COMMIT=$commit" -t "$image:$commit" delivery/app
|
|
else
|
|
docker build --platform linux/amd64 --build-arg "APP_COMMIT=$commit" -t "$image:$commit" delivery/app
|
|
fi
|
|
python3 delivery/ci/security.py image --image "$image:$commit" --reports "$reports/image-gate"
|
|
docker push "$image:$commit"
|
|
docker pull "$image:$commit"
|
|
fi
|
|
digest=$(docker image inspect "$image:$commit" --format '{{index .RepoDigests 0}}')
|
|
python3 delivery/ci/security.py image --image "$digest" --reports "$reports/published-image-gate"
|
|
printf '%s\n' "$digest" > "$reports/published-digest.txt"
|
|
python3 delivery/ci/release.py create --image "$digest" --build-url "$BUILD_URL" --output build/delivery/releases
|