Skip to content

Commit

Permalink
create bundle repos automatically if missing
Browse files Browse the repository at this point in the history
  • Loading branch information
tnevrlka committed Nov 22, 2024
1 parent 36293fb commit 06be9f4
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 28 deletions.
4 changes: 2 additions & 2 deletions .tekton/pull-request.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ spec:
name: e2e-test
# Added a timeout due to https://issues.redhat.com/browse/STONEBLD-2265
timeout: "2h"
- name: check-task-pipeline-repo-existence
- name: create-repositories-if-missing
when:
- input: "tasks_pipelines"
operator: "in"
Expand All @@ -236,7 +236,7 @@ spec:
- build-bundles
taskSpec:
steps:
- name: fail-when-repo-is-missed
- name: run-check-repos
image: quay.io/konflux-ci/pull-request-builds:appstudio-utils-{{revision}}
workingDir: $(workspaces.source.path)/source
script: |
Expand Down
23 changes: 23 additions & 0 deletions .tekton/push.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,29 @@ spec:
workspaces:
- name: source

- name: create-repositories-if-missing
runAfter:
- build-bundles
taskSpec:
steps:
- name: run-check-repos
image: quay.io/konflux-ci/pull-request-builds:appstudio-utils-{{revision}}
workingDir: $(workspaces.source.path)/source
script: |
#!/usr/bin/env bash
.tekton/scripts/check-task-pipeline-bundle-repos.sh
env:
- name: QUAY_TOKEN
valueFrom:
secretKeyRef:
name: konflux-ci-repo-creator
key: quaytoken
workspaces:
- name: source
workspaces:
- name: source
workspace: workspace

- name: update-infra-repo
runAfter:
- build-bundles
Expand Down
49 changes: 23 additions & 26 deletions .tekton/scripts/check-task-pipeline-bundle-repos.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/usr/bin/bash

set -o errexit
set -o pipefail
set -o nounset
#set -o errexit
#set -o pipefail
#set -o nounset

SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
cd "$SCRIPTDIR/../.."
Expand All @@ -16,6 +16,7 @@ locate_bundle_repo() {
local -r type="$2"
local -r object="$3"

echo "Calling https://quay.io/v2/${quay_namespace}/${type}-${object}/tags/list..."
curl -I -s -L -w "%{http_code}\n" -o /dev/null "https://quay.io/v2/${quay_namespace}/${type}-${object}/tags/list"
}

Expand All @@ -27,48 +28,44 @@ locate_in_all_namespaces() {

for quay_namespace in "${CATALOG_NAMESPACES[@]}"; do
found=$(locate_bundle_repo "$quay_namespace" "$type" "$object")
echo "Checking ${quay_namespace}/${type}-${object}, http code: ${found}"
if [ "$found" != "200" ]; then
echo "Missing $type bundle repo: ${quay_namespace}/${type}-${object}"
echo "Missing $type bundle repo: ${quay_namespace}/${type}-${object}, creating..."
echo "DEBUG: Creating quay repository https://quay.io/${quay_namespace}/${type}-${object}..."
# curl --oauth2-bearer "${QUAY_TOKEN}" 'https://quay.io/api/v1/repository' --json '{
# "namespace": '"${quay_namespace}"',
# "repository": "tekton-catalog/'"${type}-${object}"'",
# "visibility": "public",
# "description": ""
# }'
rc=1
fi
done

return "$rc"
}

has_missing_repo=

echo "Checking existence of task and pipeline bundle repositories ..."

# tasks
for task_dir in $(find task/*/*/ -maxdepth 0 -type d); do
if [ ! -f $task_dir/kustomization.yaml ]; then
while IFS= read -r -d '' task_dir
do
if [ ! -f "$task_dir"/kustomization.yaml ]; then
# expected structure: task/${name}/${version}/${name}.yaml
task_name=$(basename "$(dirname "$task_dir")")
task_name=$(yq < "$task_dir/$task_name.yaml" .metadata.name)
else
task_name=$(oc kustomize "$task_dir" | yq .metadata.name)
fi
echo "Checking ${task_dir}..."

if ! locate_in_all_namespaces task "$task_name"; then
has_missing_repo=yes
fi
done
locate_in_all_namespaces task "$task_name"
done < <(find task/*/*/ -maxdepth 0 -type d -print0)

# pipelines
pl_names=($(oc kustomize pipelines/ | yq -o json '.metadata.name' | jq -r))
pl_names=("$(oc kustomize pipelines/ | yq -o json '.metadata.name' | jq -r)")
# Currently, only one pipeline for core services CI
pl_names+=($(oc kustomize pipelines/core-services/ | yq -o json '"core-services-" + .metadata.name' | jq -r))
for pl_name in ${pl_names[@]}; do
if ! locate_in_all_namespaces pipeline "$pl_name"; then
has_missing_repo=yes
fi
pl_names+=("$(oc kustomize pipelines/core-services/ | yq -o json '"core-services-" + .metadata.name' | jq -r)")
for pl_name in "${pl_names[@]}"; do
locate_in_all_namespaces pipeline "$pl_name"
done

if [ -n "$has_missing_repo" ]; then
echo "Please contact Build team - #forum-konflux-build that the missing repos should be created in:"
echo "- https://quay.io/organization/konflux-ci"
exit 1
else
echo "Done"
fi

0 comments on commit 06be9f4

Please sign in to comment.