diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index dd0ab0c..35434b9 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/docker.sh b/docker.sh index c6056a3..c0f899c 100755 --- a/docker.sh +++ b/docker.sh @@ -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 @@ -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" } @@ -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 @@ -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")