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

feat(docker): Enable multiarch build for amd64 and arm64 #8174

Merged
merged 1 commit into from
Jan 26, 2024
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
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 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 = {
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
Loading