Skip to content

Commit

Permalink
fix: Correct script paths and add repo digest script (#8)
Browse files Browse the repository at this point in the history
* fix: add repo digest script

* make script executable

* adjust path to script in publish-index-manifest action
  • Loading branch information
xeniape authored Oct 11, 2024
1 parent 01e3c0f commit 013e648
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
33 changes: 33 additions & 0 deletions .scripts/get_repo_digest.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/usr/bin/env bash

# The script outputs the image manifest uri with the SHA256 digest, for example:
# oci.stackable.tech/sdp/hello-world@sha256:917f800259ef4915f976e93987b752fd64debf347568610d7f685d20220fc88a
set -euo pipefail

# There is only one input to this script, which contains the entire image
# manifest uri, like: oci.stackable.tech/sdp/hello-world:0.0.1-SNAPSHOT-stackable0.0.0-dev-arm64
IMAGE_MANIFEST_URI="$1"

# Here, we cut off the image manifest tag to get the image repository uri, for
# example: oci.stackable.tech/sdp/hello-world
IMAGE_REPOSITORY_URI="$(echo "$IMAGE_MANIFEST_URI" | cut -d : -f 1)"

IMAGE_REPO_DIGEST=$(
docker inspect "$IMAGE_MANIFEST_URI" --format json | \
jq -r \
--arg IMAGE_REPOSITORY_URI "$IMAGE_REPOSITORY_URI" \
--arg IMAGE_MANIFEST_URI "$IMAGE_MANIFEST_URI" \
'
map(select(.RepoTags[] | contains($IMAGE_MANIFEST_URI)))[0]
| .RepoDigests[]
| select(. | startswith($IMAGE_REPOSITORY_URI))
'
)

# Ensure IMAGE_REPO_DIGEST is not empty
if [[ -z "$IMAGE_REPO_DIGEST" ]]; then
>&2 echo "Repo Digest is empty, but is required for signing"
exit 1
fi

echo "$IMAGE_REPO_DIGEST"
2 changes: 1 addition & 1 deletion publish-image/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ runs:
docker image push "$IMAGE_MANIFEST_URI"
# Output for the next step
echo "IMAGE_REPO_DIGEST=$($GITHUB_ACTION_PATH/.scripts/get_repo_digest.sh $IMAGE_MANIFEST_URI)" | tee -a "$GITHUB_ENV"
echo "IMAGE_REPO_DIGEST=$($GITHUB_ACTION_PATH/../.scripts/get_repo_digest.sh $IMAGE_MANIFEST_URI)" | tee -a "$GITHUB_ENV"
- name: Sign the container image (${{ env.IMAGE_REPO_DIGEST }})
shell: bash
Expand Down
2 changes: 1 addition & 1 deletion publish-index-manifest/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ runs:
set -euo pipefail
# Get the image index manifest digest
DIGEST=$($GITHUB_ACTION_PATH/.scripts/get_manifest_digest.sh "$IMAGE_INDEX_URI")
DIGEST=$($GITHUB_ACTION_PATH/../.scripts/get_manifest_digest.sh "$IMAGE_INDEX_URI")
# Construct the image repo digest, which for example contains:
# docker.stackable.tech/stackable/kafka@sha256:91...
Expand Down

0 comments on commit 013e648

Please sign in to comment.