-
Notifications
You must be signed in to change notification settings - Fork 90
120 lines (111 loc) · 4.12 KB
/
caa_build_and_push.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
name: (Callable) Build and push cloud-api-adaptor image
on:
workflow_call:
inputs:
registry:
default: 'quay.io/confidential-containers'
description: 'Image registry (e.g. "quay.io/confidential-containers") where the built image will be pushed to'
required: false
type: string
dev_arches:
default: 'linux/amd64'
description: 'Dev build arches. Expected a docker buildx "--platform" string format'
required: false
type: string
dev_tags:
default: ''
description: 'Comma-separated list of tags for the dev built image (e.g. latest,ci-dev). By default uses the values from hack/build.sh'
required: false
type: string
release_arches:
default: 'linux/amd64,linux/s390x,linux/ppc64le'
description: 'Release build arches. Expected a docker buildx "--platform" string format'
required: false
type: string
release_tags:
default: ''
description: 'Likewise but for the release built image'
required: false
type: string
git_ref:
default: 'main'
description: Git ref to checkout the cloud-api-adaptor repository. Defaults to main.
required: false
type: string
runner:
default: 'ubuntu-24.04'
description: The runner to execute the workflow on. Defaults to 'ubuntu-24.04'.
required: false
type: string
defaults:
run:
working-directory: src/cloud-api-adaptor
jobs:
build_push_job:
name: build and push
runs-on: ${{ inputs.runner }}
strategy:
fail-fast: false
matrix:
include:
- type: dev
arches: ${{ inputs.dev_arches }}
- type: release
arches: ${{ inputs.release_arches }}
steps:
- name: Checkout the code
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: "${{ inputs.git_ref }}"
- name: Rebase the code
if: github.event_name == 'pull_request_target'
working-directory: ./
run: |
./hack/ci-helper.sh rebase-atop-of-the-latest-target-branch
- name: Read properties from versions.yaml
run: |
sudo snap install yq
go_version="$(yq '.tools.golang' versions.yaml)"
[ -n "$go_version" ]
echo "GO_VERSION=${go_version}" >> "$GITHUB_ENV"
- name: Setup Golang version ${{ env.GO_VERSION }}
uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
cache-dependency-path: "**/go.sum"
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Install build dependencies
if: matrix.type == 'dev'
run: |
sudo apt-get update -y
sudo apt-get install -y libvirt-dev
- name: Login to quay Container Registry
if: ${{ startsWith(inputs.registry, 'quay.io') }}
uses: docker/login-action@v3
with:
registry: ${{ inputs.registry }}
username: ${{ secrets.QUAY_USERNAME }}
password: ${{ secrets.QUAY_PASSWORD }}
- name: Login to Github Container Registry
if: ${{ startsWith(inputs.registry, 'ghcr.io') }}
uses: docker/login-action@v3
with:
registry: ${{ inputs.registry }}
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push image
uses: nick-fields/retry@v3
with:
# We are not interested in timeout but this field is required
# so setting to 4x the time it usually take to complete.
timeout_minutes: 60
retry_wait_seconds: 120
max_attempts: 3
command: |
if [ ${{ matrix.type }} == "release" ]; then
cd src/cloud-api-adaptor && ARCHES=${{matrix.arches}} RELEASE_BUILD=true RELEASE_TAGS=${{ inputs.release_tags}} make image registry=${{ inputs.registry }}
else
cd src/cloud-api-adaptor && ARCHES=${{matrix.arches}} RELEASE_BUILD=false DEV_TAGS=${{ inputs.dev_tags }} make image registry=${{ inputs.registry }}
fi