github.com/verrazzano/verrazzano@v1.7.0/release/scripts/get_release_artifacts.sh (about)

     1  #!/usr/bin/env bash
     2  #
     3  # Copyright (c) 2021, 2022, Oracle and/or its affiliates.
     4  # Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
     5  #
     6  # Downloads the verrazzano-platform-operator.yaml, the Verrazzano distributions for AMD64 and ARM64 architectures.
     7  
     8  set -e
     9  
    10  SCRIPT_DIR=$(cd $(dirname "$0"); pwd -P)
    11  . $SCRIPT_DIR/common.sh
    12  
    13  usage() {
    14      cat <<EOM
    15    Downloads the verrazzano-platform-operator.yaml, the Verrazzano distributions for AMD64 and ARM64 architectures.
    16  
    17    Usage:
    18      $(basename $0) <release branch> <short hash of commit to release> <release bundle> <directory where the release artifacts need to be downloaded> [VERIFY-ONLY]
    19  
    20    Example:
    21      $(basename $0) release-1.4 ab12123 verrazzano-1.4.0-lite.zip
    22  
    23    The script expects the OCI CLI is installed. It also expects the following environment variables -
    24      OCI_REGION - OCI region
    25      OBJECT_STORAGE_NS - top-level namespace used for the request
    26      OCI_OS_COMMIT_BUCKET - object storage bucket where the artifacts are stored
    27  EOM
    28      exit 0
    29  }
    30  
    31  [ -z "$OCI_REGION" ] || [ -z "$OBJECT_STORAGE_NS" ] || [ -z "$OCI_OS_COMMIT_BUCKET" ] || [ -z "$1" ] || [ -z "$2" ] || [ -z "$3" ] || [ -z "$4" ] || [ "$1" == "-h" ] && { usage; }
    32  
    33  if [ -z "$1" ]; then
    34    echo "Verrazzano release branch is required"
    35    exit 1
    36  fi
    37  BRANCH=$1
    38  
    39  if [ -z "$2" ]; then
    40    echo "The short commit used to build the release distribution is required"
    41    exit 1
    42  fi
    43  RELEASE_COMMIT_SHORT=$2
    44  
    45  if [ -z "$3" ]; then
    46    echo "Verrazzano distribution to download is required"
    47    exit 1
    48  fi
    49  RELEASE_BUNDLE="$3"
    50  
    51  if [ -z "$4" ]; then
    52    echo "Directory to download into is required"
    53    exit 1
    54  fi
    55  RELEASE_BINARIES_DIR=${4}
    56  
    57  function verify_vz_release_artifacts_exist() {
    58      echo "Verifying release artifacts exist"
    59      if [ $# -ne 1 ] && [ $# -ne 2 ]; then
    60        echo "Usage: ${FUNCNAME[0]} commit release_bundle"
    61        return 1
    62      fi
    63  
    64      local _folder="$1"
    65      local _file="$2"
    66      oci --region ${OCI_REGION} os object head \
    67              --namespace ${OBJECT_STORAGE_NS} \
    68              --bucket-name ${OCI_OS_COMMIT_BUCKET} \
    69              --name "${_folder}/${_file}"
    70      if [ $? -ne 0 ]; then
    71          echo "${_folder}/${_file} was not found"
    72          exit 1
    73      fi
    74  
    75      oci --region ${OCI_REGION} os object head \
    76              --namespace ${OBJECT_STORAGE_NS} \
    77              --bucket-name ${OCI_OS_COMMIT_BUCKET} \
    78              --name "${_folder}/${_file}.sha256"
    79      if [ $? -ne 0 ]; then
    80          echo "${_folder}/${_file}.sha256 was not found"
    81          exit 1
    82      fi
    83  }
    84  
    85  function get_vz_release_artifacts() {
    86      if [ $# -ne 1 ] && [ $# -ne 2 ]; then
    87        echo "Usage: ${FUNCNAME[0]} commit release_bundle"
    88        return 1
    89      fi
    90  
    91      echo "Getting release artifacts"
    92      cd $RELEASE_BINARIES_DIR
    93      local _folder="$1"
    94      local _file="$2"
    95      oci --region ${OCI_REGION} os object get \
    96              --namespace ${OBJECT_STORAGE_NS} \
    97              --bucket-name ${OCI_OS_COMMIT_BUCKET} \
    98              --name "${_folder}/${_file}" \
    99              --file "${_file}"
   100  
   101      oci --region ${OCI_REGION} os object get \
   102              --namespace ${OBJECT_STORAGE_NS} \
   103              --bucket-name ${OCI_OS_COMMIT_BUCKET} \
   104              --name "${_folder}/${_file}.sha256" \
   105              --file "${_file}.sha256"
   106  
   107      SHA256_CMD="sha256sum -c"
   108      if [ "$(uname)" == "Darwin" ]; then
   109        SHA256_CMD="shasum -a 256 -c"
   110      fi
   111      ${SHA256_CMD} ${_file}.sha256
   112      unzip ${_file}
   113      rm -f ${_file}
   114      rm -f ${_file}.sha256
   115  }
   116  
   117  # Validate OCI CLI
   118  validate_oci_cli || exit 1
   119  
   120  mkdir -p $RELEASE_BINARIES_DIR
   121  
   122  if [ "$5" == "VERIFY-ONLY" ]; then
   123      # verify the release artifacts exist, do not actually download them
   124      verify_vz_release_artifacts_exist ephemeral/$BRANCH/$RELEASE_COMMIT_SHORT ${RELEASE_BUNDLE} || exit 1
   125  else
   126      # Download the release artifacts
   127      get_vz_release_artifacts ephemeral/$BRANCH/$RELEASE_COMMIT_SHORT ${RELEASE_BUNDLE} || exit 1
   128  fi