-
Notifications
You must be signed in to change notification settings - Fork 85
240 lines (221 loc) · 9.62 KB
/
build-and-publish.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
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
240
---
name: Build and Publish Images
on:
workflow_dispatch:
inputs:
branch:
description: 'Branch to build from (make sure to use workflow from the same branch).'
required: true
type: choice
options:
- redhat-3.6
- redhat-3.7
schedule:
- cron: '30 3 * * *' # run before e2e-nightly to ensure a fresh operator build
push:
# NOTE: if you trigger this on your branch, ensure its name follows the redhat-X.Y format!
branches:
- redhat-** # IMPORTANT! this must match the .jobs.set-version.env.BRANCH_PREFIX env (save the **).
jobs:
set-version:
if: ${{ contains(github.ref, 'redhat-') }}
name: Set version from branch name
env:
BRANCH_PREFIX: redhat- # IMPORTANT! this must match the .on.push.branches prefix!
REGISTRY: quay.io/projectquay
REPO_NAME: ${{ github.event.repository.name }}
TAG_SUFFIX: -unstable
outputs:
tag: ${{ steps.format-tag.outputs.tag }}
runs-on: 'ubuntu-latest'
steps:
- name: Format version
id: version-from-branch
run: |
# use the given branch name when the workflow is manually run,
# or the GITHUB_REF_NAME otherwise (the branch that triggered the workflow)
INPUT_BRANCH=${{ github.event.inputs.branch }}
BRANCH_NAME=${INPUT_BRANCH:-$GITHUB_REF_NAME}
# remove the prefix from the branch name
VERSION=${BRANCH_NAME/${{ env.BRANCH_PREFIX }}/}
echo "::set-output name=version::${VERSION}"
- name: Format tag with version
id: format-tag
run: echo "::set-output name=tag::${{ steps.version-from-branch.outputs.version }}${{ env.TAG_SUFFIX }}"
quay-image:
if: ${{ contains(github.ref, 'redhat-') }}
name: Calculate Quay Image Digest
runs-on: 'ubuntu-latest'
outputs:
digest: ${{ steps.set-output.outputs.digest }}
env:
IMAGE_REGISTRY: quay.io/projectquay
TAG: ${{needs.set-version.outputs.tag}}
needs: set-version
steps:
- name: Pull Image
id: pull-image
run: docker pull "${IMAGE_REGISTRY}"/quay:"${TAG}"
- name: Set Output
id: set-output
run: echo "::set-output name=digest::$(docker inspect --format='{{index .RepoDigests 0}}' ${IMAGE_REGISTRY}/quay:${TAG})"
clair-image:
if: ${{ contains(github.ref, 'redhat-') }}
name: Calculate Clair Image Digest
runs-on: 'ubuntu-latest'
outputs:
digest: ${{ steps.set-output.outputs.digest }}
env:
IMAGE_REGISTRY: quay.io/projectquay
TAG: nightly
steps:
- name: Pull Image
id: pull-image
run: docker pull "${IMAGE_REGISTRY}"/clair:"${TAG}"
- name: Set Output
id: set-output
run: echo "::set-output name=digest::$(docker inspect --format='{{index .RepoDigests 0}}' ${IMAGE_REGISTRY}/clair:${TAG})"
builder-image:
if: ${{ contains(github.ref, 'redhat-') }}
name: Calculate Builder Image Digest
runs-on: 'ubuntu-latest'
outputs:
digest: ${{ steps.set-output.outputs.digest }}
env:
IMAGE_REGISTRY: quay.io/projectquay
TAG: ${{needs.set-version.outputs.tag}}
needs: set-version
steps:
- name: Pull Image
id: pull-image
run: docker pull "${IMAGE_REGISTRY}"/quay-builder:"${TAG}"
- name: Set Output
id: set-output
run: echo "::set-output name=digest::$(docker inspect --format='{{index .RepoDigests 0}}' ${IMAGE_REGISTRY}/quay-builder:${TAG})"
qemu-builder-image:
if: ${{ contains(github.ref, 'redhat-') }}
name: Calculate Qemu Builder Image Digest
runs-on: 'ubuntu-latest'
outputs:
digest: ${{ steps.set-output.outputs.digest }}
env:
IMAGE_REGISTRY: quay.io/projectquay
TAG: main
steps:
- name: Pull Image
id: pull-image
run: docker pull "${IMAGE_REGISTRY}"/quay-builder-qemu:"${TAG}"
- name: Set Output
id: set-output
run: echo "::set-output name=digest::$(docker inspect --format='{{index .RepoDigests 0}}' ${IMAGE_REGISTRY}/quay-builder-qemu:${TAG})"
operator-image:
if: ${{ contains(github.ref, 'redhat-') }}
name: Publish Operator Image
runs-on: 'ubuntu-latest'
outputs:
digest: ${{ steps.set-output.outputs.digest }}
env:
OPERATOR_IMAGE: quay.io/projectquay/quay-operator:${{needs.set-version.outputs.tag}}
needs: set-version
steps:
- name: Check out the repo
uses: actions/checkout@v2
with:
ref: ${{ github.event.inputs.branch || github.ref_name }}
- name: Login to Quay.io
uses: docker/login-action@v1
with:
registry: quay.io
username: ${{ secrets.QUAY_USER }}
password: ${{ secrets.QUAY_TOKEN }}
- name: Build and push
id: docker_build
uses: docker/build-push-action@v2
with:
push: true
tags: ${{ env.OPERATOR_IMAGE }}
- name: Set digest output
id: set-output
run: |
docker pull "${OPERATOR_IMAGE}"
echo "::set-output name=digest::$(docker inspect --format='{{index .RepoDigests 0}}' ${OPERATOR_IMAGE})"
operator-index-images:
if: ${{ contains(github.ref, 'redhat-') }}
name: Publish Catalog Index Image
runs-on: 'ubuntu-latest'
needs: [quay-image, clair-image, builder-image, qemu-builder-image, operator-image, set-version]
env:
OPERATOR_NAME: quay-operator-test
BUNDLE: quay.io/projectquay/quay-operator-bundle
INDEX: quay.io/projectquay/quay-operator-index
TAG: ${{needs.set-version.outputs.tag}}
steps:
- name: Check out the repo
uses: actions/checkout@v2
with:
ref: ${{ github.event.inputs.branch || github.ref_name }}
- name: Login to Quay.io
uses: docker/login-action@v1
with:
registry: quay.io
username: ${{ secrets.QUAY_USER }}
password: ${{ secrets.QUAY_TOKEN }}
- name: Update CSV Image Versions
uses: mikefarah/yq@master
with:
cmd: |
yq eval -i '
.metadata.name = strenv(OPERATOR_NAME) |
.metadata.annotations.quay-version = strenv(TAG) |
.metadata.annotations.containerImage = "${{needs.operator-image.outputs.digest}}" |
del(.spec.replaces) |
.spec.install.spec.deployments[0].name = strenv(OPERATOR_NAME) |
.spec.install.spec.deployments[0].spec.template.spec.containers[0].image = "${{needs.operator-image.outputs.digest}}" |
.spec.install.spec.deployments[0].spec.template.spec.containers[0].env[] |= select(.name == "RELATED_IMAGE_COMPONENT_QUAY") .value = "${{needs.quay-image.outputs.digest}}" |
.spec.install.spec.deployments[0].spec.template.spec.containers[0].env[] |= select(.name == "RELATED_IMAGE_COMPONENT_CLAIR") .value = "${{needs.clair-image.outputs.digest}}" |
.spec.install.spec.deployments[0].spec.template.spec.containers[0].env[] |= select(.name == "RELATED_IMAGE_COMPONENT_BUILDER") .value = "${{needs.builder-image.outputs.digest}}" |
.spec.install.spec.deployments[0].spec.template.spec.containers[0].env[] |= select(.name == "RELATED_IMAGE_COMPONENT_BUILDER_QEMU") .value = "${{needs.qemu-builder-image.outputs.digest}}" |
.spec.install.spec.deployments[0].spec.template.spec.containers[0].env[] |= select(.name == "RELATED_IMAGE_COMPONENT_POSTGRES") .value = "centos/postgresql-10-centos7@sha256:de1560cb35e5ec643e7b3a772ebaac8e3a7a2a8e8271d9e91ff023539b4dfb33" |
.spec.install.spec.deployments[0].spec.template.spec.containers[0].env[] |= select(.name == "RELATED_IMAGE_COMPONENT_REDIS") .value = "centos/redis-32-centos7@sha256:06dbb609484330ec6be6090109f1fa16e936afcf975d1cbc5fff3e6c7cae7542"
' bundle/manifests/quay-operator.clusterserviceversion.yaml
- name: Update Bundle Annotations
uses: mikefarah/yq@master
with:
cmd: |
yq eval -i '
.annotations."operators.operatorframework.io.bundle.channel.default.v1" = "test" |
.annotations."operators.operatorframework.io.bundle.channels.v1" = "test"
' bundle/metadata/annotations.yaml
- name: Publish Bundle Image
uses: docker/build-push-action@v2
with:
context: ./bundle
file: ./bundle/Dockerfile
push: true
tags: ${{ env.BUNDLE }}:${{ env.TAG }}
- name: Get bundle image digest
id: bundle-image
run: |
docker pull ${{ env.BUNDLE }}:${{ env.TAG }}
echo "::set-output name=digest::$(docker inspect --format='{{index .RepoDigests 0}}' ${{ env.BUNDLE }}:${{ env.TAG }})"
- name: Publish Catalog Index
env:
OPM_DOWNLOAD_URL: https://mirror.openshift.com/pub/openshift-v4/x86_64/clients/ocp/stable-4.6
OPM_TAR: opm-linux.tar.gz
run: |
wget "${OPM_DOWNLOAD_URL}/${OPM_TAR}"
tar xvf "${OPM_TAR}"
./opm index add --build-tool docker --bundles "${{steps.bundle-image.outputs.digest}}" --tag "${INDEX}:${TAG}"
docker push "${INDEX}:${TAG}"
- name: Notify slack
if: ${{ contains(github.ref, 'redhat-') && always() }}
uses: rtCamp/action-slack-notify@v2
env:
SLACK_CHANNEL: team-quay-bots
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}
SLACK_COLOR: ${{ job.status }}
SLACK_TITLE: "${{ github.workflow }}: ${{ job.status }}"
SLACK_MESSAGE: |
* **Repo**: ${{ github.repository }}
* **Workflow**: ${{ github.workflow }}
* **Result**: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}