Skip to content

Commit

Permalink
feat(docker): Enable multiarch build for amd64 and arm64
Browse files Browse the repository at this point in the history
Signed-off-by: Helio Chissini de Castro <[email protected]>
  • Loading branch information
heliocastro committed Jan 25, 2024
1 parent edbb3ad commit 9fcbfb5
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
10 changes: 9 additions & 1 deletion .github/actions/ortdocker/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
10 changes: 9 additions & 1 deletion .github/actions/ortdocker/check_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import hashlib
import os
import sys

import requests

Expand All @@ -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 True
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 = {
Expand Down
8 changes: 8 additions & 0 deletions .github/workflows/docker-ort.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 9fcbfb5

Please sign in to comment.