Baseimage upgrade to support multi-arch builds #133
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: tii-depthai-ctrl | |
on: | |
push: | |
pull_request: | |
workflow_dispatch: | |
inputs: | |
build_amd64: | |
description: 'Build for AMD64' | |
required: true | |
default: true | |
type: boolean | |
build_arm64: | |
description: 'Build for ARM64' | |
required: true | |
default: false | |
type: boolean | |
build_riscv64: | |
description: 'Build for RISCV64' | |
required: true | |
default: false | |
type: boolean | |
permissions: | |
contents: read | |
packages: write | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
submodules: recursive | |
- name: Determine platforms | |
id: platforms | |
run: | | |
qemu_platforms="" | |
docker_platforms="" | |
default_branch="${{ github.event.repository.default_branch }}" | |
matrix_list=() | |
if [[ "${{ github.event_name }}" == "push" && "${{ github.ref }}" == "refs/heads/$default_branch" ]]; then | |
matrix_list=("amd64" "arm64" "riscv64") | |
elif [[ "${{ github.event_name }}" == "pull_request" && "${{ github.base_ref }}" == "$default_branch" ]]; then | |
matrix_list=("amd64" "arm64" "riscv64") | |
elif [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then | |
if [[ "${{ github.event.inputs.build_amd64 }}" == 'true' ]]; then | |
matrix_list+=("amd64") | |
fi | |
if [[ "${{ github.event.inputs.build_arm64 }}" == 'true' ]]; then | |
matrix_list+=("arm64") | |
fi | |
if [[ "${{ github.event.inputs.build_riscv64 }}" == 'true' ]]; then | |
matrix_list+=("riscv64") | |
fi | |
else | |
# Maybe push or some other trigger | |
matrix_list=("amd64") | |
fi | |
for platform in "${matrix_list[@]}"; do | |
qemu_platforms+="$platform," | |
docker_platforms+="linux/$platform," | |
done | |
echo "qemu=${qemu_platforms%?}" >> $GITHUB_OUTPUT | |
echo "docker=${docker_platforms%?}" >> $GITHUB_OUTPUT | |
echo "Building for $qemu_platforms" | |
- name: Setup QEMU | |
uses: docker/setup-qemu-action@v3 | |
with: | |
platforms: ${{ steps.platforms.outputs.qemu }} | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Set image tag format without suffix | |
run: | | |
echo "IMAGE_TAG_FORMAT=type=sha" >> $GITHUB_ENV | |
if: github.event_name == 'push' | |
- name: Set image tag format with suffix | |
# it is possible that run_number should be used instead run_attempt | |
# run_attempt is unique number on every run and run_attempt resets to 1 if re-build is not used | |
# content of image_sha_tag_suffix is defined in fog-ros-baseimage dispatcher workflow. | |
run: | | |
echo "IMAGE_TAG_FORMAT=type=sha,suffix=-${{ github.event.client_payload.image_sha_tag_suffix }}" >> $GITHUB_ENV | |
if: github.event_name == 'repository_dispatch' | |
- name: Docker meta | |
id: meta | |
uses: docker/metadata-action@v5 | |
with: | |
images: ghcr.io/tiiuae/tii-depthai-ctrl | |
tags: | | |
type=ref,event=branch | |
type=semver,pattern={{version}} | |
type=raw,value=latest | |
${{ env.IMAGE_TAG_FORMAT }} | |
type=raw,value=latest,enable=${{ endsWith(github.ref, github.event.repository.default_branch) }} | |
- name: Login to GitHub Container Registry | |
uses: docker/login-action@v3 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Build container image and push | |
uses: docker/build-push-action@v5 | |
with: | |
context: . | |
file: Dockerfile | |
platforms: ${{ steps.platforms.outputs.docker }} | |
push: true | |
no-cache: false | |
cache-from: type=gha | |
cache-to: type=gha,mode=max | |
tags: ${{ steps.meta.outputs.tags }} | |
labels: ${{ steps.meta.outputs.labels }} |