Skip to content

Commit

Permalink
Merge pull request #6 from WyriHaximus/support-multiple-images
Browse files Browse the repository at this point in the history
Support multiple images
  • Loading branch information
WyriHaximus authored Dec 20, 2024
2 parents 4137518 + 581daf2 commit b1a46b8
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 7 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ jobs:
with:
dockerfile: tests/Dockerfile
image: ghcr.io/home-assistant/home-assistant:2024.12.2
- name: Multiple images
expected: '["linux/arm64","linux/amd64"]'
with:
image: ghcr.io/home-assistant/home-assistant:2024.12.2,ghcr.io/wyrihaximusnet/php:8.3-zts-alpine-dev
steps:
- uses: actions/checkout@v4
- name: OCI Image Supported Platforms
Expand Down
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,17 @@ The Dockerfile to get its supported platforms
* *Default*: `Dockerfile`
* *Example*: `Dockerfile-alpine-zts`

### image

Passing anything into the `image` input will disable checking for the passed `dockerfile` input value, and will get the
platforms for the image(s) you give it. When you pass it two or more, for example `ghcr.io/home-assistant/home-assistant:2024.12.2,ghcr.io/wyrihaximusnet/php:8.3-zts-alpine-dev`,
it will get the platforms for all of them but only return the platforms that are supported by all of them.

* *Required*: `No`
* *Type*: `string`
* *Default*: ``
* *Example*: `ghcr.io/wyrihaximusnet/php:8.3-zts-alpine-slim`

## Output

This action only outputs a list of platforms as JSON through `platform`.
Expand All @@ -37,7 +48,7 @@ jobs:
# Note: No checkout needed, the action will handle that for you in the most optimized way possible
- id: supported-arch-matrix
name: Generate Arch
uses: wyrihaximus/github-action-oci-image-supported-archs@v1
uses: wyrihaximus/github-action-oci-image-supported-platforms@v1
build-docker-image:
name: Build ${{ matrix.platform }} image
strategy:
Expand Down
20 changes: 14 additions & 6 deletions action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ inputs:
required: false
default: 'Dockerfile'
image:
description: The OCI image to get its supported platforms
description: The OCI image to get its supported platforms, optionally a comma seperated list of images can be supplied and the intersection of the supported platforms will be the output
required: false
default: ''
outputs:
Expand All @@ -33,7 +33,7 @@ runs:
shell: bash
run: |
printf "from=%s" $(cat ${{ inputs.dockerfile }} | grep FROM | tail -n 1 | docker run -q -i --rm ghcr.io/wyrihaximusnet/php:8.3-nts-alpine-slim php -r 'echo explode(" ", trim(fgets(STDIN)))[1];') >> $GITHUB_OUTPUT
- name: Image Wizzard
- name: Image 🧙
id: image
shell: bash
run: |
Expand All @@ -46,7 +46,15 @@ runs:
id: platform
shell: bash
run: |
printf "platform=%s" $(docker manifest inspect ${{ steps.image.outputs.image }} | docker run --rm -i -q ghcr.io/jqlang/jq:1.7.1 '([.manifests[].platform | select(.os != "unknown")]?) | .[] | (.os + "/" + .architecture)' | docker run --rm -i -q ghcr.io/jqlang/jq:1.7.1 -s -c '.') >> $GITHUB_OUTPUT
github:
head_ref:
getPlatformsForImage () {
docker manifest inspect $1 | docker run --rm -i -q ghcr.io/jqlang/jq:1.7.1 '([.manifests[].platform | select(.os != "unknown")]?) | .[] | (.os + "/" + .architecture)' | docker run --rm -i -q ghcr.io/jqlang/jq:1.7.1 -s -c '.'
}
getPlatformsIntersected () {
echo $1 | docker run -q -i --rm ghcr.io/wyrihaximusnet/php:8.3-nts-alpine-slim php -r 'echo json_encode(array_intersect(...array_values(json_decode(trim(fgets(STDIN)), true))), JSON_UNESCAPED_SLASHES);'
}
export -f getPlatformsForImage
if [[ "${{ steps.image.outputs.image }}" == *","* ]]; then
printf "platform=%s" $(getPlatformsIntersected $(echo "${{ steps.image.outputs.image }}" | tr ',' '\n'| xargs -I % bash -c 'getPlatformsForImage "%"' | docker run --rm -i -q ghcr.io/jqlang/jq:1.7.1 -s -c '.')) >> $GITHUB_OUTPUT
else
printf "platform=%s" $(getPlatformsForImage ${{ steps.image.outputs.image }}) >> $GITHUB_OUTPUT
fi

0 comments on commit b1a46b8

Please sign in to comment.