-
Notifications
You must be signed in to change notification settings - Fork 24
239 lines (209 loc) · 8.63 KB
/
collector-builder.yml
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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
name: Collector builder image build
on:
workflow_call:
inputs:
collector-tag:
type: string
required: true
description: |
The tag used to build the collector image
outputs:
collector-builder-tag:
description: The builder tag used by the build
value: ${{ jobs.build-builder-image.outputs.collector-builder-tag || 'master' }}
env:
COLLECTOR_TAG: ${{ inputs.collector-tag }}
DEFAULT_BUILDER_TAG: master
ANSIBLE_CONFIG: ${{ github.workspace }}/ansible/ansible.cfg
jobs:
builder-needs-rebuilding:
name: Determine if builder image needs to be built
runs-on: ubuntu-24.04
outputs:
build-image: ${{ steps.changed.outputs.builder-changed }}
steps:
- uses: actions/checkout@v4
- uses: dorny/paths-filter@v3
id: changed
with:
filters: |
builder-changed:
- builder/install/**
- builder/third_party/**
- builder/Dockerfile
- .github/workflows/collector-builder.yml
build-builder-image:
name: Build the builder image
runs-on: ubuntu-24.04
# Multiarch builds sometimes take for eeeeeeeeeever
timeout-minutes: 480
needs:
- builder-needs-rebuilding
if: |
needs.builder-needs-rebuilding.outputs.build-image == 'true' ||
(github.event_name == 'push' && (
github.ref_type == 'tag' || startsWith(github.ref_name, 'release-')
)) ||
contains(github.event.pull_request.labels.*.name, 'build-builder-image') ||
github.event_name == 'schedule'
outputs:
collector-builder-tag: ${{ steps.builder-tag.outputs.collector-builder-tag }}
strategy:
fail-fast: false
matrix:
arch: [amd64, ppc64le, s390x, arm64]
env:
PLATFORM: linux/${{ matrix.arch }}
BUILD_TYPE: ci
steps:
- uses: actions/checkout@v4
with:
submodules: true
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- uses: actions/setup-python@v5
with:
python-version: "3.10"
- uses: 'google-github-actions/auth@v2'
with:
credentials_json: '${{ secrets.GOOGLE_CREDENTIALS_COLLECTOR_SVC_ACCT }}'
- uses: 'google-github-actions/setup-gcloud@v2'
- uses: ./.github/actions/setup-vm-creds
with:
gcp-ssh-key: ${{ secrets.GCP_SSH_KEY }}
gcp-ssh-key-pub: ${{ secrets.GCP_SSH_KEY_PUB }}
s390x-ssh-key: ${{ secrets.IBM_CLOUD_S390X_SSH_PRIVATE_KEY }}
ppc64le-ssh-key: ${{ secrets.IBM_CLOUD_POWER_SSH_PRIVATE_KEY }}
ppc64le-ssh-key-pub: ${{ secrets.IBM_CLOUD_POWER_SSH_PUBLIC_KEY }}
s390x-key: ${{ secrets.IBM_CLOUD_S390x_API_KEY }}
ppc64le-key: ${{ secrets.IBM_CLOUD_POWER_API_KEY }}
redhat-username: ${{ secrets.REDHAT_USERNAME }}
redhat-password: ${{ secrets.REDHAT_PASSWORD }}
vm-type: all
job-tag: builder
- name: Create Build VMs
if: |
matrix.arch == 's390x' &&
(github.event_name != 'pull_request' || contains(github.event.pull_request.labels.*.name, 'run-multiarch-builds'))
run: |
make -C "${{ github.workspace }}/ansible" create-build-vms
- name: Define builder tag
id: builder-tag
run: |
COLLECTOR_BUILDER_TAG="${DEFAULT_BUILDER_TAG}"
if [[ "${{ github.event_name }}" == 'pull_request' || \
"${{ github.ref_type }}" == 'tag' || \
"${{ github.ref_name }}" =~ ^release- ]]; then
COLLECTOR_BUILDER_TAG="${{ inputs.collector-tag }}"
fi
echo "COLLECTOR_BUILDER_TAG=${COLLECTOR_BUILDER_TAG}" >> "$GITHUB_ENV"
echo "collector-builder-tag=${COLLECTOR_BUILDER_TAG}" >> "$GITHUB_OUTPUT"
- name: Create ansible vars
run: |
{
echo "---"
echo "stackrox_io_username: ${{ secrets.QUAY_STACKROX_IO_RW_USERNAME }}"
echo "stackrox_io_password: ${{ secrets.QUAY_STACKROX_IO_RW_PASSWORD }}"
echo "rhacs_eng_username: ${{ secrets.QUAY_RHACS_ENG_RW_USERNAME }}"
echo "rhacs_eng_password: ${{ secrets.QUAY_RHACS_ENG_RW_PASSWORD }}"
echo "collector_git_ref: ${{ github.ref }}"
echo "collector_builder_tag: ${{ env.COLLECTOR_BUILDER_TAG }}"
} > ${{ github.workspace }}/ansible/secrets.yml
- name: Build images
if: |
(github.event_name != 'pull_request' && matrix.arch != 's390x') ||
matrix.arch == 'amd64' ||
(contains(github.event.pull_request.labels.*.name, 'run-multiarch-builds') && matrix.arch != 's390x')
timeout-minutes: 480
run: |
ansible-galaxy install -r ansible/requirements.yml
ansible-playbook \
--connection local \
-i localhost, \
--limit localhost \
-e arch='${{ matrix.arch }}' \
-e @'${{ github.workspace }}/ansible/secrets.yml' \
ansible/ci-build-builder.yml
- name: Build s390x images
if: |
(github.event_name != 'pull_request' && matrix.arch == 's390x') ||
(contains(github.event.pull_request.labels.*.name, 'run-multiarch-builds') && matrix.arch == 's390x')
timeout-minutes: 480
run: |
ansible-playbook \
-i ansible/ci \
-e build_hosts='job_id_${{ env.JOB_ID }}' \
-e arch='${{ matrix.arch }}' \
-e @'${{ github.workspace }}/ansible/secrets.yml' \
ansible/ci-build-builder.yml
- name: Destroy VMs
if: always() && matrix.arch == 's390x'
run: |
make -C ansible destroy-vms
create-multiarch-manifest:
needs:
- build-builder-image
name: Create Multiarch manifest
runs-on: ubuntu-24.04
if: |
github.event_name != 'pull_request' ||
(needs.build-builder-image.outputs.collector-builder-tag != 'cache' &&
contains(github.event.pull_request.labels.*.name, 'run-multiarch-builds'))
env:
COLLECTOR_BUILDER_TAG: ${{ needs.build-builder-image.outputs.collector-builder-tag }}
ARCHS: amd64 ppc64le s390x arm64
steps:
- uses: actions/checkout@v4
- name: Login to quay.io/stackrox-io
uses: docker/login-action@v3
with:
registry: quay.io
username: ${{ secrets.QUAY_STACKROX_IO_RW_USERNAME }}
password: ${{ secrets.QUAY_STACKROX_IO_RW_PASSWORD }}
- name: Create and push multiarch manifest for builder to stackrox-io
uses: ./.github/actions/create-multiarch-manifest
with:
base-image: quay.io/stackrox-io/collector-builder:${{ env.COLLECTOR_BUILDER_TAG }}
archs: ${{ env.ARCHS }}
- name: Login to quay.io/rhacs-eng
uses: docker/login-action@v3
with:
registry: quay.io
username: ${{ secrets.QUAY_RHACS_ENG_RW_USERNAME }}
password: ${{ secrets.QUAY_RHACS_ENG_RW_PASSWORD }}
- name: Create and push multiarch manifest for builder to rhacs-eng
uses: ./.github/actions/create-multiarch-manifest
with:
base-image: quay.io/rhacs-eng/collector-builder:${{ env.COLLECTOR_BUILDER_TAG }}
archs: ${{ env.ARCHS }}
retag-x86-image:
needs:
- build-builder-image
name: Retag x86 builder image
runs-on: ubuntu-24.04
if: |
github.event_name == 'pull_request' &&
needs.build-builder-image.outputs.collector-builder-tag != 'cache' &&
!contains(github.event.pull_request.labels.*.name, 'run-multiarch-builds')
env:
COLLECTOR_BUILDER_TAG: ${{ needs.build-builder-image.outputs.collector-builder-tag }}
steps:
- name: Pull image to retag
run: |
docker pull "quay.io/stackrox-io/collector-builder:${COLLECTOR_BUILDER_TAG}-amd64"
- name: Retag and push stackrox-io
uses: stackrox/actions/images/retag-and-push@v1
with:
src-image: quay.io/stackrox-io/collector-builder:${{ env.COLLECTOR_BUILDER_TAG }}-amd64
dst-image: quay.io/stackrox-io/collector-builder:${{ env.COLLECTOR_BUILDER_TAG }}
username: ${{ secrets.QUAY_STACKROX_IO_RW_USERNAME }}
password: ${{ secrets.QUAY_STACKROX_IO_RW_PASSWORD }}
- name: Retag and push rhacs-eng
uses: stackrox/actions/images/retag-and-push@v1
with:
src-image: quay.io/stackrox-io/collector-builder:${{ env.COLLECTOR_BUILDER_TAG }}-amd64
dst-image: quay.io/rhacs-eng/collector-builder:${{ env.COLLECTOR_BUILDER_TAG }}
username: ${{ secrets.QUAY_RHACS_ENG_RW_USERNAME }}
password: ${{ secrets.QUAY_RHACS_ENG_RW_PASSWORD }}