-
Notifications
You must be signed in to change notification settings - Fork 245
Link to migration bundles #1861
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -38,9 +38,12 @@ VCS_URL=https://github.com/konflux-ci/build-definitions | |
| VCS_REF=$(git rev-parse HEAD) | ||
|
|
||
| declare -r ARTIFACT_TYPE_TEXT_XSHELLSCRIPT="text/x-shellscript" | ||
| declare -r ANNOTATION_TASK_MIGRATION="dev.konflux-ci.task.migration" | ||
| declare -r TEST_TASKS=${TEST_TASKS:-""} | ||
|
|
||
| declare -r ANNOTATION_TASK_MIGRATION="dev.konflux-ci.task.migration" | ||
| # The annotation value points to the task bundle which has a migration that's most recent to the task with the annotation | ||
| declare -r ANNOTATION_PREVIOUS_MIGRATION_BUNDLE="dev.konflux-ci.task.previous-migration-bundle" | ||
|
mmorhun marked this conversation as resolved.
|
||
|
|
||
| AUTH_JSON= | ||
| if [ -e "$XDG_RUNTIME_DIR/containers/auth.json" ]; then | ||
| AUTH_JSON="$XDG_RUNTIME_DIR/containers/auth.json" | ||
|
|
@@ -228,6 +231,7 @@ build_push_task() { | |
| local -r task_bundle=$3 | ||
| local -r task_file_sha=$4 | ||
| local -r has_migration=$5 | ||
| local -r prev_bundle_digest=$6 | ||
|
mmorhun marked this conversation as resolved.
|
||
|
|
||
| local -r task_description=$(yq e '.spec.description' "$prepared_task_file" | head -n 1) | ||
|
|
||
|
|
@@ -250,9 +254,11 @@ build_push_task() { | |
| ANNOTATIONS+=("dev.tekton.docs.usage=${VCS_URL}/tree/${VCS_REF}/${task_dir}/USAGE.md") | ||
| fi | ||
| if [ "$has_migration" == "true" ]; then | ||
| ANNOTATIONS+=("dev.konflux-ci.task.migration=true") | ||
| ANNOTATIONS+=("${ANNOTATION_TASK_MIGRATION}=true") | ||
| fi | ||
|
|
||
| ANNOTATIONS+=("${ANNOTATION_PREVIOUS_MIGRATION_BUNDLE}=${prev_bundle_digest}") | ||
|
|
||
| local -a ANNOTATION_FLAGS=() | ||
| for annotation in "${ANNOTATIONS[@]}"; do | ||
| ANNOTATION_FLAGS+=("--annotate" "$(escape_tkn_bundle_arg "$annotation")") | ||
|
|
@@ -431,6 +437,50 @@ attach_migration_file() { | |
| return 0 | ||
| } | ||
|
|
||
| # Find previous bundle that has a migration and output its digest. | ||
| find_previous_migration_bundle_digest() { | ||
| local -r task_name=${1:?Missing task name} | ||
| local -r task_version=${2:?Missing task version} | ||
|
|
||
| local bundle_ref | ||
| bundle_ref=$(generate_tagged_task_bundle "$task_name" "$task_version") | ||
| local ns_repo=${bundle_ref%:*} # remove tag | ||
| ns_repo=${ns_repo#*/} # remove registry | ||
| # Retain the tag used for matching tag names | ||
| local -r name_pattern="${bundle_ref##*:}-" | ||
|
mmorhun marked this conversation as resolved.
|
||
| unset bundle_ref | ||
|
|
||
| local -r params="onlyActiveTags=true&filter_tag_name=like:${name_pattern}&limit=1" | ||
| local -r url_list_tags="https://quay.io/api/v1/repository/${ns_repo}/tag/?${params}" | ||
|
|
||
| local manifest_digest | ||
| manifest_digest=$(curl --fail -sL "$url_list_tags" | jq -r '.tags[].manifest_digest') | ||
| if [ -z "$manifest_digest" ]; then | ||
| # There is no tag yet. That would mean this is the first time to build the task bundle. | ||
| return 0 | ||
| fi | ||
| curl --fail -sL -o /tmp/manifest.json "https://quay.io/v2/${ns_repo}/manifests/${manifest_digest}" | ||
|
|
||
| local has_migration | ||
| has_migration=$(jq -r ".annotations.\"${ANNOTATION_TASK_MIGRATION}\"" </tmp/manifest.json) | ||
| if [ "$has_migration" == "true" ]; then | ||
| echo "$manifest_digest" | ||
| return 0 | ||
| fi | ||
|
|
||
| local prev_bundle_digest | ||
| prev_bundle_digest=$(jq -r ".annotations.\"${ANNOTATION_PREVIOUS_MIGRATION_BUNDLE}\"" </tmp/manifest.json) | ||
| if [ -n "$prev_bundle_digest" ] && [ "$prev_bundle_digest" != "null" ]; then | ||
| # This bundle points to a previous bundle that has migration. | ||
| echo "$prev_bundle_digest" | ||
| return 0 | ||
| fi | ||
|
|
||
| # Otherwise, output empty to indicate not point any bundle. | ||
| echo | ||
| return 0 | ||
| } | ||
|
|
||
| build_push_tasks() { | ||
| local build_data | ||
| local task_bundle_with_digest | ||
|
|
@@ -440,6 +490,7 @@ build_push_tasks() { | |
| local task_bundle | ||
| local output | ||
| local has_migration | ||
| local previous_migration_bundle_digest | ||
|
|
||
| find task/*/* -maxdepth 0 -type d | awk -F '/' '{ print $0, $2, $3 }' | \ | ||
| while read -r task_dir task_name task_version | ||
|
|
@@ -479,9 +530,15 @@ build_push_tasks() { | |
| task_bundle_with_digest=${task_bundle}@${digest} | ||
| echo "info: use existing $task_bundle_with_digest" 1>&2 | ||
| else | ||
| echo "info: finding the previous task bundle that has a migration" 1>&2 | ||
| previous_migration_bundle_digest=$(find_previous_migration_bundle_digest "$task_name" "$task_version") | ||
|
|
||
| echo "info: push new bundle $task_bundle" 1>&2 | ||
|
|
||
| output=$(build_push_task "$task_dir" "$prepared_task_file" "$task_bundle" "$task_file_sha" "$has_migration") | ||
| output=$( | ||
| build_push_task "$task_dir" "$prepared_task_file" "$task_bundle" "$task_file_sha" \ | ||
| "$has_migration" "$previous_migration_bundle_digest" | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| ) | ||
| echo "$output" >&2 | ||
| echo | ||
|
|
||
|
|
@@ -503,7 +560,6 @@ build_push_tasks() { | |
|
|
||
| build_push_tasks | ||
|
|
||
|
|
||
| # Used for build-definitions pull request CI only | ||
| if [ -n "$ENABLE_SOURCE_BUILD" ]; then | ||
| for pipeline_yaml in "$GENERATED_PIPELINES_DIR"/*.yaml; do | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.