Change caching method, add comments as requested #144
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: Docker meta | |
id: meta | |
uses: docker/metadata-action@v5 | |
with: | |
images: ghcr.io/tiiuae/tii-depthai-ctrl | |
tags: | | |
type=ref,event=branch | |
type=ref,event=pr | |
type=semver,pattern={{version}} | |
type=sha | |
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: Format tags as registry refs | |
id: registry_refs | |
env: | |
TAGS: ${{ steps.meta.outputs.json }} | |
run: | | |
echo tags=$(echo $TAGS | jq '.tags[] | "type=registry,ref=" + . | @text') >> $GITHUB_OUTPUT | |
- 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: ${{ steps.registry_refs.outputs.tags }} | |
cache-to: inline | |
tags: ${{ steps.meta.outputs.tags }} | |
labels: ${{ steps.meta.outputs.labels }} |