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 13, 2024
1 parent b2f800c commit c4ef107
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 39 deletions.
16 changes: 0 additions & 16 deletions .tekton/pull-request.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -197,22 +197,6 @@ spec:
name: e2e-test
# Added a timeout due to https://issues.redhat.com/browse/STONEBLD-2265
timeout: "2h"
- name: check-task-pipeline-repo-existence
runAfter:
- build-bundles
taskSpec:
steps:
- name: fail-when-repo-is-missed
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
workspaces:
- name: source
workspaces:
- name: source
workspace: workspace
- name: ec-task-checks
runAfter:
- fetch-repository
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
42 changes: 19 additions & 23 deletions .tekton/scripts/check-task-pipeline-bundle-repos.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,50 +25,46 @@ locate_in_all_namespaces() {

local rc=0

echo "Missing $type bundle repo: ${quay_namespace}/${type}-${object}, creating..."
for quay_namespace in "${CATALOG_NAMESPACES[@]}"; do
found=$(locate_bundle_repo "$quay_namespace" "$type" "$object")
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}/tekton-catalog/${object}..."
# curl --oauth2-bearer "${QUAY_TOKEN}" 'https://quay.io/api/v1/repository' --json '{
# "namespace": '"${quay_namespace}"',
# "repository": "tekton-catalog/'"${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 c4ef107

Please sign in to comment.