-
Notifications
You must be signed in to change notification settings - Fork 1
162 lines (144 loc) · 5.1 KB
/
tii-depthai-ctrl.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
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
env:
REGISTRY_IMAGE: ghcr.io/tiiuae/tii-depthai-ctrl
jobs:
prepare:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- id: set-matrix
run: |
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
matrix_json="{\"include\": ["
for platform in "${matrix_list[@]}"; do
matrix_json+="{\"platform\":\"$platform\"},"
done
matrix_json="${matrix_json%,}]}"
echo "matrix=${matrix_json}" >> $GITHUB_OUTPUT
echo $matrix_json
build:
needs: prepare
runs-on: ubuntu-latest
strategy:
matrix: ${{fromJson(needs.prepare.outputs.matrix)}}
outputs:
short_git_sha: ${{ steps.vars.outputs.SHORT_GIT_SHA }}
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
- name: Setup QEMU
uses: docker/setup-qemu-action@v3
with:
platforms: ${{ matrix.platform }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Set short git commit SHA
id: vars
run: |
calculatedSha=$(git rev-parse --short ${{ github.sha }})
echo "SHORT_GIT_SHA=$calculatedSha" >> $GITHUB_OUTPUT
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY_IMAGE }}
tags: |
type=ref,event=branch,suffix=-${{ matrix.platform }}
type=ref,event=pr,suffix=-${{ matrix.platform }}
type=semver,pattern={{version}},suffix=-${{ matrix.platform }}
type=sha,suffix=-${{ matrix.platform }}
type=raw,value=latest,enable=${{ endsWith(github.ref, github.event.repository.default_branch) && matrix.platform == 'amd64' }}
- 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: linux/${{ matrix.platform }}
pull: true
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 }}
provenance: false
merge:
runs-on: ubuntu-latest
needs:
- prepare
- build
steps:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY_IMAGE }}
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Create combined image
run : |
AMEND_LIST=""
for platform in $(echo '${{ needs.prepare.outputs.matrix }}' | jq -r '.include[].platform'); do
echo "Adding ${{ env.REGISTRY_IMAGE }}:sha-${{ needs.build.outputs.short_git_sha }}-$platform to the amend list"
AMEND_LIST+="--amend ${{ env.REGISTRY_IMAGE }}:sha-${{ needs.build.outputs.short_git_sha }}-$platform "
done
docker manifest create ${{ env.REGISTRY_IMAGE }}:sha-${{ needs.build.outputs.short_git_sha }} $AMEND_LIST
- name: Push image to the registry
run: |
docker manifest push ${{ env.REGISTRY_IMAGE }}:sha-${{ needs.build.outputs.short_git_sha }}