Skip to content

Commit a9cd9f4

Browse files
adding bundle image tasks
1 parent 1993649 commit a9cd9f4

File tree

2 files changed

+330
-8
lines changed

2 files changed

+330
-8
lines changed

.tekton/ansible-ai-connect-operator-pull-request.yaml

Lines changed: 168 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,8 @@ spec:
162162
value: $(params.git-url)
163163
- name: revision
164164
value: $(params.revision)
165+
- name: fetchTags
166+
value: true
165167
runAfter:
166168
- init
167169
taskRef:
@@ -183,7 +185,6 @@ spec:
183185
workspace: workspace
184186
- name: basic-auth
185187
workspace: git-auth
186-
187188
- name: git-metadata
188189
runAfter:
189190
- clone-repository
@@ -202,8 +203,169 @@ spec:
202203
cd "$(workspaces.source.path)/source"
203204
echo -n $(date -d @$(git log -1 --format=%at) "+%Y%m%d%H%M") > $(results.commit-timestamp.path)
204205
results:
205-
- name: commit-timestamp
206-
206+
- name: commit-timestamp
207+
- name: common-get-operator-versions
208+
runAfter:
209+
- clone-repository
210+
workspaces:
211+
- name: source
212+
workspace: workspace
213+
taskSpec:
214+
workspaces:
215+
- name: source
216+
steps:
217+
- name: get-latest-tag
218+
image: alpine/git
219+
script: |
220+
#!/bin/sh
221+
set -euo pipefail
222+
cd "$(workspaces.source.path)/source"
223+
LATEST_TAG=$(git tag -l --sort=v:refname | tail -n1)
224+
echo -n $LATEST_TAG > $(results.operator_version_latest.path)
225+
226+
echo -n $LATEST_TAG
227+
228+
MAJOR=$(echo $LATEST_TAG | cut -d. -f1)
229+
MINOR=$(echo $LATEST_TAG | cut -d. -f2)
230+
PATCH=$(echo $LATEST_TAG | cut -d. -f3)
231+
PATCH=$((PATCH + 1))
232+
NEW_TAG="$MAJOR.$MINOR.$PATCH"
233+
echo -n $NEW_TAG > $(results.operator_version_next.path)
234+
echo -n $NEW_TAG
235+
236+
results:
237+
- name: operator_version_latest
238+
description: the _latest_ Operator version
239+
- name: operator_version_next
240+
description: The _next_ Operator version
241+
- name: bundle
242+
runAfter:
243+
- clone-repository
244+
- common-get-operator-versions
245+
workspaces:
246+
- name: source
247+
workspace: workspace
248+
taskSpec:
249+
params:
250+
- name: IMAGE
251+
default: quay.io/ansible/ansible-ai-connect-konflux
252+
- name: ADDITIONAL_TAGS
253+
default: ""
254+
- name: STORAGE_DRIVER
255+
default: overlay
256+
workspaces:
257+
- name: source
258+
steps:
259+
- name: bundle
260+
image: quay.io/operator-framework/operator-sdk:v1.10.0
261+
script: |
262+
cd "$(workspaces.source.path)/source"
263+
operator-sdk generate kustomize manifests -q
264+
265+
# install kustomize
266+
curl -s "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh" | bash
267+
mv kustomize /usr/local/bin/
268+
269+
cd config/manager
270+
271+
kustomize edit set image controller=$(params.IMAGE):0.1.0
272+
273+
cd ../..
274+
kustomize build config/manifests | operator-sdk generate bundle -q --overwrite --version 0.1.0
275+
operator-sdk bundle validate ./bundle
276+
volumeMounts:
277+
- name: varlibcontainers
278+
mountPath: /var/lib/containers
279+
securityContext:
280+
capabilities:
281+
add: ["SETFCAP"]
282+
volumes:
283+
- name: varlibcontainers
284+
emptyDir: {}
285+
- name: update-cluster-service-version
286+
runAfter:
287+
- bundle
288+
workspaces:
289+
- name: source
290+
workspace: workspace
291+
taskSpec:
292+
workspaces:
293+
- name: source
294+
steps:
295+
- name: update-cluster-service-version
296+
image: alpine/git
297+
script: |
298+
#!/bin/sh
299+
set -euo pipefail
300+
cd "$(workspaces.source.path)/source"
301+
if [[ "$(tasks.common-get-operator-versions.results.operator_version_latest)" == "0.0.0" ]]; then
302+
>&2 echo "No previous version found."
303+
exit 0
304+
fi
305+
306+
VERSION="$(tasks.common-get-operator-versions.results.operator_version_next)"
307+
PREV_VERSION="$(tasks.common-get-operator-versions.results.operator_version_latest)"
308+
if ! grep -qF "replaces: ansible-ai-connect-operator.v${PREV_VERSION}" bundle/manifests/ansible-ai-connect-operator.clusterserviceversion.yaml; then
309+
sed -i "/version: ${VERSION}/a\\
310+
replaces: ansible-ai-connect-operator.v${PREV_VERSION}" ./bundle/manifests/ansible-ai-connect-operator.clusterserviceversion.yaml
311+
fi
312+
- name: bundle-build-push
313+
runAfter:
314+
- update-cluster-service-version
315+
workspaces:
316+
- name: source
317+
workspace: workspace
318+
taskSpec:
319+
params:
320+
- name: IMAGE
321+
default: quay.io/ansible/ansible-ai-connect-konflux
322+
- name: ADDITIONAL_TAGS
323+
default: ""
324+
- name: STORAGE_DRIVER
325+
default: overlay
326+
workspaces:
327+
- name: source
328+
steps:
329+
- name: bundle-build
330+
image: quay.io/buildah/stable:v1.17.0
331+
script: |
332+
cd "$(workspaces.source.path)/source"
333+
334+
OPERATOR_VERSION_NEXT=$(tasks.common-get-operator-versions.results.operator_version_next)
335+
ADDITIONAL_TAGS="$(params.IMAGE):bundle-$OPERATOR_VERSION_NEXT-pr-{{pull_request_number}}-$(tasks.git-metadata.results.commit-timestamp) $(params.IMAGE):$OPERATOR_VERSION_NEXT"
336+
337+
buildah --storage-driver=$(params.STORAGE_DRIVER) bud \
338+
--no-cache -f bundle.Dockerfile -t $(params.IMAGE) .
339+
340+
for tag in $ADDITIONAL_TAGS; do
341+
buildah tag $(params.IMAGE) $tag
342+
done
343+
volumeMounts:
344+
- name: varlibcontainers
345+
mountPath: /var/lib/containers
346+
securityContext:
347+
capabilities:
348+
add: ["SETFCAP"]
349+
- name: bundle-push
350+
image: quay.io/buildah/stable:v1.17.0
351+
script: |
352+
OPERATOR_VERSION_NEXT=$(tasks.common-get-operator-versions.results.operator_version_next)
353+
ADDITIONAL_TAGS="$(params.IMAGE):bundle-$OPERATOR_VERSION_NEXT-pr-{{pull_request_number}}-$(tasks.git-metadata.results.commit-timestamp) $(params.IMAGE):$OPERATOR_VERSION_NEXT"
354+
355+
for tag in $ADDITIONAL_TAGS; do
356+
buildah --storage-driver=$(params.STORAGE_DRIVER) push \
357+
$tag
358+
done
359+
volumeMounts:
360+
- name: varlibcontainers
361+
mountPath: /var/lib/containers
362+
securityContext:
363+
capabilities:
364+
add: ["SETFCAP"]
365+
volumes:
366+
- name: varlibcontainers
367+
emptyDir: {}
368+
207369
- name: prefetch-dependencies
208370
params:
209371
- name: input
@@ -246,7 +408,7 @@ spec:
246408
- name: COMMIT_SHA
247409
value: $(tasks.clone-repository.results.commit)
248410
- name: BUILD_ARGS
249-
value: ["IMAGE_TAGS=pr-{{pull_request_number}} pr-{{pull_request_number}}.$(tasks.git-metadata.results.commit-timestamp)", "GIT_COMMIT=$(tasks.clone-repository.results.commit)"]
411+
value: ["IMAGE_TAGS=$(tasks.common-get-operator-versions.results.operator_version_next)-pr-{{pull_request_number}}-$(tasks.git-metadata.results.commit-timestamp)"]
250412
- name: BUILD_ARGS_FILE
251413
value: $(params.build-args-file)
252414
runAfter:
@@ -432,9 +594,10 @@ spec:
432594
- name: IMAGE
433595
value: $(tasks.build-container.results.IMAGE_URL)
434596
- name: ADDITIONAL_TAGS
435-
value: ["pr-{{pull_request_number}}", "pr-{{pull_request_number}}.$(tasks.git-metadata.results.commit-timestamp)"]
597+
value: ["$(tasks.common-get-operator-versions.results.operator_version_next)-pr-{{pull_request_number}}-$(tasks.git-metadata.results.commit-timestamp)"]
436598
runAfter:
437599
- build-container
600+
- common-get-operator-versions
438601
taskRef:
439602
params:
440603
- name: name

0 commit comments

Comments
 (0)