-
Notifications
You must be signed in to change notification settings - Fork 140
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
create bundle repos automatically if missing
- A check is currently ran checking that every task bundle has its own Quay repository - If the task bundle does not have its own repository, the check will fail and the repository has to be created manually - Automate the repository creation via a task, but only in the on-push pipelinerun (once a PR is approved and merged) for security reasons
- Loading branch information
Showing
4 changed files
with
120 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
#!/usr/bin/bash | ||
|
||
set -o errexit | ||
set -o pipefail | ||
set -o nounset | ||
|
||
SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" | ||
cd "$SCRIPTDIR/../.." | ||
|
||
CATALOG_NAMESPACES=( | ||
konflux-ci/tekton-catalog | ||
) | ||
|
||
locate_bundle_repo() { | ||
local -r quay_namespace="$1" | ||
local -r type="$2" | ||
local -r object="$3" | ||
|
||
curl -I -s -L -w "%{http_code}\n" -o /dev/null "https://quay.io/v2/${quay_namespace}/${type}-${object}/tags/list" | ||
} | ||
|
||
locate_in_all_namespaces() { | ||
local -r type="$1" | ||
local -r object="$2" | ||
|
||
for quay_namespace in "${CATALOG_NAMESPACES[@]}"; do | ||
found=$(locate_bundle_repo "$quay_namespace" "$type" "$object") | ||
|
||
# konflux-ci/tekton-catalog | ||
if [[ $quay_namespace = */* ]]; then | ||
# tekton-catalog/ | ||
quay_repo_prefix="${quay_namespace#*/}/" | ||
# konflux-ci | ||
quay_namespace=${quay_namespace%%/*} | ||
else | ||
quay_repo_prefix="" | ||
fi | ||
|
||
echo "Checking ${quay_namespace}/${quay_repo_prefix}${object}, http code: ${found}" | ||
if [ "$found" != "200" ]; then | ||
echo "Missing $type bundle repo: ${quay_repo_prefix}${object} in ${quay_namespace}, creating..." | ||
payload=$( | ||
jq -n \ | ||
--arg namespace "$quay_namespace" \ | ||
--arg repository "$quay_repo_prefix$object" \ | ||
--arg visibility "public" \ | ||
--arg description "" \ | ||
'$ARGS.named' | ||
) | ||
if ! err_msg=$(curl --oauth2-bearer "${QUAY_TOKEN}" "https://quay.io/api/v1/repository" --json "$payload" | jq '.error_message // empty'); | ||
then | ||
echo "curl returned an error when creating the repository. See the error above." | ||
exit 1 | ||
fi | ||
|
||
if [ -n "$err_msg" ]; then | ||
echo "Quay returned an error when creating the repository: ${err_msg}" | ||
exit 1 | ||
fi | ||
fi | ||
done | ||
} | ||
|
||
echo "Checking existence of task bundle repositories..." | ||
echo | ||
|
||
# tasks | ||
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 | ||
|
||
locate_in_all_namespaces task "$task_name" | ||
done < <(find task/*/*/ -maxdepth 0 -type d -print0) | ||
|
||
echo | ||
echo "Checking existence of pipeline bundle repositories..." | ||
echo | ||
|
||
# pipelines | ||
pl_names=() | ||
# Split by newlines into an array | ||
while IFS=$'\n' read -r line; | ||
do pl_names+=("$line"); | ||
done <<<"$(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 | ||
echo "Checking pipeline: ${pl_name}" | ||
locate_in_all_namespaces pipeline "$pl_name" | ||
done |