From 48a7358420a0d0fd89f0da3334fe26c9a35b15c9 Mon Sep 17 00:00:00 2001 From: Palash Gandhi <87093175+pgandhi-delphix@users.noreply.github.com> Date: Thu, 22 Jun 2023 09:30:03 -0700 Subject: [PATCH] DLPX-85904 Remove hardcoded git branch from appliance-build (#726) PR URL: https://www.github.com/delphix/appliance-build/pull/726 --- branch.config | 13 --------- scripts/aptly-repo-from-debs.sh | 4 +-- scripts/build-ancillary-repository.sh | 28 +------------------ scripts/common.sh | 40 ++++++++++++++++++++++----- scripts/run-live-build.sh | 39 +++++++++++--------------- 5 files changed, 51 insertions(+), 73 deletions(-) delete mode 100644 branch.config diff --git a/branch.config b/branch.config deleted file mode 100644 index 714ae614..00000000 --- a/branch.config +++ /dev/null @@ -1,13 +0,0 @@ -# -# Copyright (c) 2019 by Delphix. All rights reserved. -# - -# -# The "BRANCH" parameter tracks the upstream branch of appliance-build. It is -# used to determine which branch of the linux package mirror will be used for -# the build if UPSTREAM_PRODUCT_BRANCH is not set. UPSTREAM_PRODUCT_BRANCH is -# set when appliance build is built by the appliance-build Jenkins job. The -# UPSTREAM_BRANCH parameter should be updated by the release lead on branching -# - -UPSTREAM_BRANCH="develop" diff --git a/scripts/aptly-repo-from-debs.sh b/scripts/aptly-repo-from-debs.sh index a2ea12ca..4141545d 100755 --- a/scripts/aptly-repo-from-debs.sh +++ b/scripts/aptly-repo-from-debs.sh @@ -64,9 +64,7 @@ done # Download the delphix upgrade verification debian package, stored in the # combined-packages bundle. # -AWS_S3_URI_COMBINED_PACKAGES=$(resolve_s3_uri \ - "$AWS_S3_URI_COMBINED_PACKAGES" \ - "linux-pkg/${UPSTREAM_BRANCH}/combine-packages/post-push/latest") +AWS_S3_URI_COMBINED_PACKAGES=$(resolve_s3_uri "$AWS_S3_URI_COMBINED_PACKAGES") WORK_DIRECTORY=$(mktemp -d -p "$TOP/upgrade" tmp.pkgs.XXXXXXXXXX) diff --git a/scripts/build-ancillary-repository.sh b/scripts/build-ancillary-repository.sh index 95e4d614..0bbae145 100755 --- a/scripts/build-ancillary-repository.sh +++ b/scripts/build-ancillary-repository.sh @@ -61,29 +61,6 @@ function build_ancillary_repository() { EOF } -# -# Set UPSTREAM_BRANCH. This will determine which version of the linux package -# mirror is used. -# -if [[ -z "$UPSTREAM_PRODUCT_BRANCH" ]]; then - echo "UPSTREAM_PRODUCT_BRANCH is not set." - if ! source "$TOP/branch.config" 2>/dev/null; then - echo "No branch.config file found in repo root." - exit 1 - fi - - if [[ -z "$UPSTREAM_BRANCH" ]]; then - echo "UPSTREAM_BRANCH parameter was not sourced from branch.config." \ - "Ensure branch.config is properly formatted with e.g." \ - "UPSTREAM_BRANCH=\"\"" - exit 1 - fi - echo "Defaulting to branch $UPSTREAM_BRANCH set in branch.config." -else - UPSTREAM_BRANCH="$UPSTREAM_PRODUCT_BRANCH" -fi -echo "Running with UPSTREAM_BRANCH set to ${UPSTREAM_BRANCH}" - # # The packages produced by Delphix are stored in Amazon S3. # Thus, in order to populate the ancillary repository with these @@ -95,10 +72,7 @@ echo "Running with UPSTREAM_BRANCH set to ${UPSTREAM_BRANCH}" # packages from there, otherwise determine the latest combined-packages URI # automatically. # - -AWS_S3_URI_COMBINED_PACKAGES=$(resolve_s3_uri \ - "$AWS_S3_URI_COMBINED_PACKAGES" \ - "linux-pkg/${UPSTREAM_BRANCH}/combine-packages/post-push/latest") +AWS_S3_URI_COMBINED_PACKAGES=$(resolve_s3_uri "$AWS_S3_URI_COMBINED_PACKAGES") mkdir -p "$TOP/build" WORK_DIRECTORY=$(mktemp -d -p "$TOP/build" tmp.pkgs.XXXXXXXXXX) diff --git a/scripts/common.sh b/scripts/common.sh index 99f0942c..7efd2fef 100644 --- a/scripts/common.sh +++ b/scripts/common.sh @@ -25,22 +25,25 @@ function die() { function resolve_s3_uri() { local pkg_uri="$1" - local latest_subprefix="$2" - local bucket="snapshot-de-images" - local jenkinsid="jenkins-ops" local resolved_uri if [[ -n "$pkg_uri" ]]; then resolved_uri="$pkg_uri" - elif [[ -n "$latest_subprefix" ]]; then + else + # + # Set UPSTREAM_BRANCH. This will determine which version of the linux package + # mirror is used. + # + UPSTREAM_BRANCH=$(get_upstream_or_fail_if_unset) || exit 1 + echo "Running with UPSTREAM_BRANCH set to ${UPSTREAM_BRANCH}" + local latest_subprefix="linux-pkg/${UPSTREAM_BRANCH}/combine-packages/post-push/latest" + local bucket="snapshot-de-images" + local jenkinsid="jenkins-ops" aws s3 cp --quiet \ "s3://$bucket/builds/$jenkinsid/$latest_subprefix" . resolved_uri="s3://$bucket/$(cat latest)" rm -f latest - else - echo "Invalid arguments provided to resolve_s3_uri()" 2>&1 - exit 1 fi if aws s3 ls "$resolved_uri" &>/dev/null; then @@ -135,3 +138,26 @@ function extract_debs_into_dir() { find "$source_dir" -name '*.deb' -exec mv {} "$target_dir" \; find "$source_dir" -name '*.ddeb' -exec mv {} "$target_dir" \; } + +function get_upstream_or_fail_if_unset() { + if [[ -z "$UPSTREAM_PRODUCT_BRANCH" ]]; then + local upstream_branch + upstream_branch="$(git rev-parse --abbrev-ref --symbolic-full-name "@{u}" | cut -d'/' -f2-)" + if [[ -z $upstream_branch ]]; then + echo "ERROR: The currently checked out branch" >&2 + echo " does not have an upstream branch configured. Set the" >&2 + echo " upstream branch you plan to push to:" >&2 + echo "" >&2 + echo " git branch --set-upstream-to=" >&2 + echo "" >&2 + echo " Then run this script again. '' can be " >&2 + echo " something like '6.0/stage'" >&2 + return 1 + else + echo "$upstream_branch" + return 0 + fi + else + echo "$UPSTREAM_PRODUCT_BRANCH" + fi +} diff --git a/scripts/run-live-build.sh b/scripts/run-live-build.sh index dd7a9bf3..2e5943eb 100755 --- a/scripts/run-live-build.sh +++ b/scripts/run-live-build.sh @@ -15,6 +15,8 @@ # limitations under the License. # +. "${BASH_SOURCE%/*}/common.sh" + TOP=$(git rev-parse --show-toplevel 2>/dev/null) if [[ -z "$TOP" ]]; then @@ -138,33 +140,17 @@ while ! curl --output /dev/null --silent --head --fail \ sleep 1 done -# -# Set UPSTREAM_BRANCH. This will determine which version of the linux package -# mirror is used. -# -if [[ -z "$UPSTREAM_PRODUCT_BRANCH" ]]; then - echo "UPSTREAM_PRODUCT_BRANCH is not set." - if ! source "$TOP/branch.config" 2>/dev/null; then - echo "No branch.config file found in repo root." - exit 1 - fi - - if [[ -z "$UPSTREAM_BRANCH" ]]; then - echo "UPSTREAM_BRANCH parameter was not sourced from branch.config." \ - "Ensure branch.config is properly formatted with e.g." \ - "UPSTREAM_BRANCH=\"\"" - exit 1 - fi - echo "Defaulting to branch $UPSTREAM_BRANCH set in branch.config." -else - UPSTREAM_BRANCH="$UPSTREAM_PRODUCT_BRANCH" -fi -echo "Running with UPSTREAM_BRANCH set to ${UPSTREAM_BRANCH}" - pkg_mirror_secondary='' if [[ -n "$DELPHIX_PACKAGE_MIRROR_SECONDARY" ]]; then pkg_mirror_secondary="$DELPHIX_PACKAGE_MIRROR_SECONDARY" else + # + # Set UPSTREAM_BRANCH. This will determine which version of the linux package + # mirror is used. + # + UPSTREAM_BRANCH=$(get_upstream_or_fail_if_unset) || exit 1 + echo "Running with UPSTREAM_BRANCH set to ${UPSTREAM_BRANCH}" + # # If no secondary package mirror is provided, then pull in the latest # mirror dataset for the build. If no latest dataset is found, then fail. @@ -188,6 +174,13 @@ pkg_mirror_main='' if [[ -n "$DELPHIX_PACKAGE_MIRROR_MAIN" ]]; then pkg_mirror_main="$DELPHIX_PACKAGE_MIRROR_MAIN" else + # + # Set UPSTREAM_BRANCH. This will determine which version of the linux package + # mirror is used. + # + UPSTREAM_BRANCH=$(get_upstream_or_fail_if_unset) || exit 1 + echo "Running with UPSTREAM_BRANCH set to ${UPSTREAM_BRANCH}" + # # If no main package mirror is provided, then pull in the latest mirror # dataset for the build. If no latest dataset is found, then fail.