Skip to content

Commit

Permalink
Fix retrieving manifest for single platform (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucacome committed Jan 30, 2023
1 parent 99580de commit f50d564
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 9 deletions.
25 changes: 20 additions & 5 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ jobs:
test1:
name: Test Update Needed
runs-on: ubuntu-22.04
continue-on-error: true
steps:
- name: Checkout Repository
uses: actions/checkout@v3
Expand All @@ -35,7 +34,6 @@ jobs:
test2:
name: Test Update Not Needed
runs-on: ubuntu-22.04
continue-on-error: true
steps:
- name: Checkout Repository
uses: actions/checkout@v3
Expand All @@ -56,7 +54,6 @@ jobs:
test3:
name: Test Update Needed on ARM64
runs-on: ubuntu-22.04
continue-on-error: true
steps:
- name: Checkout Repository
uses: actions/checkout@v3
Expand All @@ -78,7 +75,6 @@ jobs:
test4:
name: Test Update Needed on multiple platforms
runs-on: ubuntu-22.04
continue-on-error: true
steps:
- name: Checkout Repository
uses: actions/checkout@v3
Expand All @@ -100,7 +96,6 @@ jobs:
test5:
name: Test Update Not Needed on multiple platforms
runs-on: ubuntu-22.04
continue-on-error: true
steps:
- name: Checkout Repository
uses: actions/checkout@v3
Expand All @@ -118,3 +113,23 @@ jobs:
if [[ "${{ steps.test.outputs.needs-updating }}" != "false" ]]; then
exit 1
fi
test6:
name: Test single platform
runs-on: ubuntu-22.04
steps:
- name: Checkout Repository
uses: actions/checkout@v3
- name: Test Action
id: test
uses: ./
with:
base-image: alpine:latest
image: lucacome/alpine-amd64
- name: Get Test Output
run: echo "Workflow Docker Image ${{ steps.test.outputs.needs-updating }}"
- name: Check value
run: |
if [[ "${{ steps.test.outputs.needs-updating }}" != "false" ]]; then
exit 1
fi
15 changes: 11 additions & 4 deletions docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ get_manifests() {
local digest=$2
local token=$3

manifest_list=$(curl -sSL -H "Authorization: Bearer $token" \
-H "Accept: application/vnd.docker.distribution.manifest.list.v2+json,application/vnd.oci.image.index.v1+json" \
manifest_list=$(curl -sSL --dump-header headers -H "Authorization: Bearer $token" \
-H "Accept: application/vnd.docker.distribution.manifest.list.v2+json,application/vnd.oci.image.index.v1+json,application/vnd.docker.distribution.manifest.v2+json,application/vnd.oci.image.manifest.v1+json" \
"https://index.docker.io/v2/${repo}/manifests/${digest}" 2>/dev/null)

if jq -e -r '.errors[0].code' <<<"$manifest_list" >/dev/null; then
Expand All @@ -27,6 +27,13 @@ get_manifests() {
error "Response from $repo\n code: $error_code\n message: $message"
fi

headers=$(cat headers | awk -F ': ' '{sub(/\r/,"\n",$2); print $1","$2}' | grep 'docker-content-digest\|content-type' | jq -R 'split(",") | {(if .[0] == "content-type" then "type" else "digest" end): .[1]}' | jq -s 'reduce .[] as $item ({}; . * $item)')
manifest_v2=$(jq -r '. | select(.type == "application/vnd.docker.distribution.manifest.v2+json" or .type == "application/vnd.oci.image.manifest.v1+json") | [{digest: .digest, platform: "linux/amd64"}]' <<<"$headers")
if [ ! -z "$manifest_v2" ]; then
echo "$manifest_v2"
return
fi

jq -r '[.manifests[] | select(.platform.architecture | contains ("unknown") | not) | {digest: .digest, platform: (.platform.os +"/"+ .platform.architecture)}]' <<<"$manifest_list"

}
Expand All @@ -37,7 +44,7 @@ get_layers() {
local token=$3

digestOutput=$(curl -sSL -H "Authorization: Bearer $token" \
-H "Accept: application/vnd.docker.distribution.manifest.v1+json,application/vnd.oci.image.manifest.v1+json" \
-H "Accept: application/vnd.docker.distribution.manifest.v2+json,application/vnd.oci.image.manifest.v1+json" \
"https://index.docker.io/v2/${repo}/manifests/${digest}" 2>/dev/null)

if jq -e -r '.errors[0].code' <<<"$digestOutput" >/dev/null; then
Expand Down Expand Up @@ -102,7 +109,7 @@ manifests_image=$(get_manifests $image_repo ${image_tag:-latest} $image_token)

diff=false
# loop through plafforms split by comma
for platform in $(echo $platforms | tr ',' ' '); do
for platform in $(echo $platforms | tr -s ',' ' '); do
# get the digest for the platform
digest_base=$(jq -r ".[] | select(.platform == \"$platform\") | .digest" <<<"$manifests_base")

Expand Down

0 comments on commit f50d564

Please sign in to comment.