diff --git a/.github/actions/ortdocker/action.yml b/.github/actions/ortdocker/action.yml index 9dfff2b04175c..a27b606c1784d 100644 --- a/.github/actions/ortdocker/action.yml +++ b/.github/actions/ortdocker/action.yml @@ -58,10 +58,16 @@ runs: run: | pip install -q -U pip requests + if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then + INVALIDATE_CACHE=1 + export INVALIDATE_CACHE + fi result=$(python ./.github/actions/ortdocker/check_image.py) - echo $result echo "result=$result" >> $GITHUB_OUTPUT + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + - name: Set up Docker build if: steps.check_image.outputs.result != 'found' uses: docker/setup-buildx-action@v3 @@ -92,6 +98,7 @@ runs: uses: docker/build-push-action@v5 with: context: . + platforms: linux/amd64,linux/arm64 target: ${{ inputs.name }} push: ${{ github.event_name == 'push' || github.event_name == 'workflow_dispatch' }} load: false @@ -108,6 +115,7 @@ runs: uses: docker/build-push-action@v5 with: context: . + platforms: linux/amd64,linux/arm64 target: ${{ inputs.name }} push: ${{ github.event_name == 'push' || github.event_name == 'workflow_dispatch' }} load: false diff --git a/.github/actions/ortdocker/check_image.py b/.github/actions/ortdocker/check_image.py index 4ab1f931347f0..21be591974f9a 100644 --- a/.github/actions/ortdocker/check_image.py +++ b/.github/actions/ortdocker/check_image.py @@ -17,6 +17,7 @@ import hashlib import os +import sys import requests @@ -28,11 +29,18 @@ org = os.getenv("GITHUB_REPOSITORY_OWNER") name = os.getenv("INPUT_NAME") base_version = os.getenv("INPUT_VERSION") -unique_id = hashlib.sha256(os.getenv("BUILD_ARGS").encode()).hexdigest() +build_args = os.getenv("BUILD_ARGS") +invalidate_cache = True if os.getenv("INVALIDATE_CACHE") else False +unique_id = hashlib.sha256(build_args.encode()).hexdigest() if build_args else "uniq" # We base the version on the base_version and the unique_id version = f"{base_version}-sha.{unique_id[:8]}" +# In case of need invalidate the cache from images we just return the version +if invalidate_cache: + print(version) + sys.exit(0) + url = f"https://api.github.com/orgs/{org}/packages/container/ort%2F{name}/versions" headers = { diff --git a/.github/workflows/docker-ort.yml b/.github/workflows/docker-ort.yml index 1435e572864a8..e0b83fac2d67d 100644 --- a/.github/workflows/docker-ort.yml +++ b/.github/workflows/docker-ort.yml @@ -305,6 +305,9 @@ jobs: ORT_VERSION=$(./gradlew -q properties --property version | sed -nr "s/version: (.+)/\1/p") echo "ORT_VERSION=${ORT_VERSION}" >> $GITHUB_ENV + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + - name: Set up Docker build uses: docker/setup-buildx-action@v3 @@ -332,6 +335,7 @@ jobs: uses: docker/build-push-action@v5 with: context: . + platforms: linux/amd64,linux/arm64 target: minimal push: ${{ github.event_name == 'push' || github.event_name == 'workflow_dispatch' || github.event_name == 'schedule' }} load: false @@ -371,6 +375,9 @@ jobs: ORT_VERSION=$(./gradlew -q properties --property version | sed -nr "s/version: (.+)/\1/p") echo "ORT_VERSION=${ORT_VERSION}" >> $GITHUB_ENV + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + - name: Set up Docker build uses: docker/setup-buildx-action@v3 @@ -398,6 +405,7 @@ jobs: uses: docker/build-push-action@v5 with: context: . + platforms: linux/amd64,linux/arm64 target: run push: ${{ github.event_name == 'push' || github.event_name == 'workflow_dispatch' || github.event_name == 'schedule' }} load: false