From 9e9f57957e03d58e807b304c95a570eb9d3707a3 Mon Sep 17 00:00:00 2001 From: Alexander Stepchenko Date: Fri, 18 Oct 2024 14:20:51 +0300 Subject: [PATCH] remove shell implementation of image-build --- image-build | 281 ---------------------------------------------------- 1 file changed, 281 deletions(-) delete mode 100755 image-build diff --git a/image-build b/image-build deleted file mode 100755 index 012e0fe..0000000 --- a/image-build +++ /dev/null @@ -1,281 +0,0 @@ -#!/bin/sh - -set -uo pipefail - -PROG='image-build' -HELP_MSG="$(cat < - -Options: - -b package repository branch - -r OCI destination registry - -t task id - --latest also tag this image as latest - --push push the image to the registry after build - --skip-build if push is true, then skip the build stage - --dry-run only print what would be done - --prefix image name prefix - --help show this text and exit - -Notes: - The image is only pushed to the destination registry - if the option --push is present. -EOF -)" - -function show_help() { - printf '%s' "$HELP_MSG" - exit -} - -function show_usage() { - echo "$PROG: $1" >&2 - echo "Try \`image-build --help' for more information." >&2 - exit 1 -} - -TEMP="$(getopt -n "$PROG" -o b:r:t: -l help,latest,push,skip-build,dry-run,prefix:: -- "$@")" || show_usage "" - -eval set -- "$TEMP" - -branch='sisyphus' -registry='registry.altlinux.org' -task_id= -latest= -push= -skip_build= -dry_run= -prefix= -while :; do - case "$1" in - --) shift; break ;; - -b) shift; branch="$1" ;; - -r) shift; registry="$1" ;; - -t) shift; task_id="$1" ;; - --latest) latest="1" ;; - --push) push="1" ;; - --skip-build) skip_build="1" ;; - --dry-run) dry_run="1" ;; - --prefix) shift; prefix="$1" ;; - -h|--help) show_help ;; - *) show_usage "unrecognized option: $1" ;; - esac - shift -done - -[ "$#" -ge 2 ] || show_usage "not enough arguments" - -image="$1" -package="$2" - -declare -A package_urls -package_urls["c10f2"]="http://update.altsp.su/pub/distributions/ALTLinux/c10f2/branch/files/x86_64/RPMS/" -package_urls["p10"]="http://ftp.altlinux.org/pub/distributions/archive/p10/release/latest/files/x86_64/RPMS/" -package_urls["sisyphus"]="http://ftp.altlinux.org/pub/distributions/archive/sisyphus/latest/files/x86_64/RPMS/" - -function handle_error() { - echo "$PROG: $1" >&2 - exit 2 -} - -function get_binary_package_version() { - local branch="$1" - local package="$2" - - local line; - line="$(curl -s "${package_urls["$branch"]}" | grep "$package")" - [ "$?" -eq 0 ] || handle_error "package not found: $package" - - local version; - version="$(echo "$line" | sed -E "s/.*href=\"$package-(.+)-.+\".+/\1/")" - [ "$?" -eq 0 ] || handle_error "package version not found: $package" - - echo "$version" -} - -function api_get_source_package_version() { - local branch="$1" - local package="$2" - - local version; - version="$(curl -s "https://rdb.altlinux.org/api/site/package_versions_from_tasks?branch=$branch&name=$package" | jq -e -r '.versions[0].version')" - [ "$?" -eq 0 ] || handle_error "error getting package version: no package $package for branch $branch" - - echo "$version" -} - -function api_get_source_package_version_from_task() { - local task_id="$1" - local package="$2" - - local version; - version="$(curl -s "https://rdb.altlinux.org/api/task/packages/$task_id" | jq -e -r --arg package "$package" '.subtasks[].source | select(.name == $package).version')" - [ "$?" -eq 0 ] || handle_error "error getting package version: no package $package in task $task_id" - - echo "$version" -} - -function string_count() { - local substring="$1" - awk -F"$substring" '{ print NF-1 }' -} - -case "$image" in - 'etcd' | \ - 'flannel' | \ - 'flannel-cni-plugin' | \ - 'pause' | \ - 'cert-manager-acmesolver' | \ - 'cert-manager-cainjector' | \ - 'cert-manager-controller' | \ - 'cert-manager-startupapicheck' | \ - 'cert-manager-webhook') - image="k8s/$image" - - version= - additional_options= - - if [ -n "$task_id" ]; then - version="$(api_get_source_package_version_from_task "$task_id" "$package")" - [ "$?" -eq 0 ] || handle_error "error getting remote rpm package version: $package, task: $task_id" - - tasks_file='/tmp/k8s-tasks.toml' - jq --null-input --arg branch "$branch" --arg task_id "$task_id" --arg image "$image" '{ - $branch: {$task_id: [$image]}, - }' | dasel -r json -w toml > "$tasks_file" - - additional_options+="--tasks $tasks_file " - else - version="$(api_get_source_package_version "$branch" "$package")" - [ "$?" -eq 0 ] || handle_error "error getting remote rpm package version: $package, branch: $branch" - fi - - tags_file="/tmp/k8s-tags.toml" - case "$image" in - 'k8s/flannel-cni-plugin') - num_dots="$(echo "$version" | string_count '.')" - if [ "$num_dots" -eq 2 ]; then - jq --null-input --arg image "$image" --arg branch "$branch" --arg version "v$version-flannel1" '{ - $image: {$branch: [$version]}, - }' | dasel -r json -w toml > "$tags_file" - elif [ "$num_dots" -eq 3 ]; then - # up to the last number in version - flannel_version="${version%.*}" - # the last number in version - flannel_release="${version##*.}" - jq --null-input --arg image "$image" --arg branch "$branch" --arg version "v$flannel_version-flannel$flannel_release" '{ - $image: {$branch: [$version]}, - }' | dasel -r json -w toml > "$tags_file" - else - handle_error "wrong version for package $package: $version" - fi - ;; - 'k8s/etcd') - jq --null-input --arg image "$image" --arg branch "$branch" --arg version "$version-0" '{ - $image: {$branch: [$version]}, - }' | dasel -r json -w toml > "$tags_file" - ;; - 'k8s/pause') - jq --null-input --arg image "$image" --arg branch "$branch" --arg version "$version" '{ - $image: {$branch: [$version]}, - }' | dasel -r json -w toml > "$tags_file" - ;; - *) - jq --null-input --arg image "$image" --arg branch "$branch" --arg version "v$version" '{ - $image: {$branch: [$version]}, - }' | dasel -r json -w toml > "$tags_file" - ;; - esac - - if [ -n "$latest" ]; then - additional_options+="--latest $branch " - fi - - if [ -z "$push" ]; then - additional_options+='--skip-stages push ' - elif [ -n "$skip_build" ]; then - additional_options+='--stages push ' - fi - - if [ -n "$dry_run" ]; then - additional_options+='--dry-run ' - fi - - ./build.py \ - --branch "$branch" \ - --registry "$registry" \ - --overwrite-organization "$prefix" \ - --images "$image" \ - --tags "$tags_file" \ - $additional_options - ;; - 'kube-apiserver' | 'kube-controller-manager' | 'kube-scheduler' | 'kube-proxy' | 'coredns') - image="k8s/$image" - - version= - additional_options= - - if [ -n "$task_id" ]; then - version="$(api_get_source_package_version_from_task "$task_id" "$package")" - [ "$?" -eq 0 ] || handle_error "error getting remote rpm package version: $package, task: $task_id" - - tasks_file='/tmp/k8s-tasks.toml' - jq --null-input --arg branch "$branch" --arg task_id "$task_id" --arg image "$image" '{ - $branch: {$task_id: [$image]}, - }' | dasel -r json -w toml > "$tasks_file" - - additional_options+="--tasks $tasks_file " - else - version="$(api_get_source_package_version "$branch" "$package")" - [ "$?" -eq 0 ] || handle_error "error getting remote rpm package version: $package, branch: $branch" - fi - - # if binary package - #version_str="$(echo "$package" | sed -E 's/kubernetes(.+)-.+/\1/')" - #[ "$?" -eq 0 ] || handle_error "error getting specified rpm package version: $package" - - sed_arg= - case "$image" in - 'k8s/coredns') - sed_arg='s/coredns(.+)/\1/' - ;; - *) - sed_arg='s/kubernetes(.+)/\1/' - ;; - esac - - # if source package - version_str="$(echo "$package" | sed -E "$sed_arg")" - [ "$?" -eq 0 ] || handle_error "error getting specified rpm package version: $package" - - tags_file="/tmp/k8s-tags.toml" - jq --null-input --arg image "$image" --arg branch "$branch" --arg version "v$version" '{ - $image: {$branch: [$version]}, - }' | dasel -r json -w toml > "$tags_file" - - if [ -n "$latest" ]; then - additional_options+="--latest $branch " - fi - - if [ -z "$push" ]; then - additional_options+="--skip-stages push " - elif [ -n "$skip_build" ]; then - additional_options+="--stages push " - fi - - if [ -n "$dry_run" ]; then - additional_options+="--dry-run " - fi - - ./build.py \ - --branch "$branch" \ - --registry "$registry" \ - --overwrite-organization "$prefix" \ - --images "$image" \ - --tags "$tags_file" \ - --package-version "$version_str" \ - $additional_options - ;; -esac