Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix retrieving manifest for single platform #23

Merged
merged 1 commit into from
Jan 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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