Skip to content

Commit f50d564

Browse files
authored
Fix retrieving manifest for single platform (#23)
1 parent 99580de commit f50d564

File tree

2 files changed

+31
-9
lines changed

2 files changed

+31
-9
lines changed

.github/workflows/test.yml

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ jobs:
1414
test1:
1515
name: Test Update Needed
1616
runs-on: ubuntu-22.04
17-
continue-on-error: true
1817
steps:
1918
- name: Checkout Repository
2019
uses: actions/checkout@v3
@@ -35,7 +34,6 @@ jobs:
3534
test2:
3635
name: Test Update Not Needed
3736
runs-on: ubuntu-22.04
38-
continue-on-error: true
3937
steps:
4038
- name: Checkout Repository
4139
uses: actions/checkout@v3
@@ -56,7 +54,6 @@ jobs:
5654
test3:
5755
name: Test Update Needed on ARM64
5856
runs-on: ubuntu-22.04
59-
continue-on-error: true
6057
steps:
6158
- name: Checkout Repository
6259
uses: actions/checkout@v3
@@ -78,7 +75,6 @@ jobs:
7875
test4:
7976
name: Test Update Needed on multiple platforms
8077
runs-on: ubuntu-22.04
81-
continue-on-error: true
8278
steps:
8379
- name: Checkout Repository
8480
uses: actions/checkout@v3
@@ -100,7 +96,6 @@ jobs:
10096
test5:
10197
name: Test Update Not Needed on multiple platforms
10298
runs-on: ubuntu-22.04
103-
continue-on-error: true
10499
steps:
105100
- name: Checkout Repository
106101
uses: actions/checkout@v3
@@ -118,3 +113,23 @@ jobs:
118113
if [[ "${{ steps.test.outputs.needs-updating }}" != "false" ]]; then
119114
exit 1
120115
fi
116+
117+
test6:
118+
name: Test single platform
119+
runs-on: ubuntu-22.04
120+
steps:
121+
- name: Checkout Repository
122+
uses: actions/checkout@v3
123+
- name: Test Action
124+
id: test
125+
uses: ./
126+
with:
127+
base-image: alpine:latest
128+
image: lucacome/alpine-amd64
129+
- name: Get Test Output
130+
run: echo "Workflow Docker Image ${{ steps.test.outputs.needs-updating }}"
131+
- name: Check value
132+
run: |
133+
if [[ "${{ steps.test.outputs.needs-updating }}" != "false" ]]; then
134+
exit 1
135+
fi

docker.sh

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ get_manifests() {
1717
local digest=$2
1818
local token=$3
1919

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

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

30+
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)')
31+
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")
32+
if [ ! -z "$manifest_v2" ]; then
33+
echo "$manifest_v2"
34+
return
35+
fi
36+
3037
jq -r '[.manifests[] | select(.platform.architecture | contains ("unknown") | not) | {digest: .digest, platform: (.platform.os +"/"+ .platform.architecture)}]' <<<"$manifest_list"
3138

3239
}
@@ -37,7 +44,7 @@ get_layers() {
3744
local token=$3
3845

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

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

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

0 commit comments

Comments
 (0)