github.com/deemoprobe/k8s-first-commit@v0.0.0-20230430165612-a541f1982be3/src/release/config.sh (about)

     1  # Copyright 2014 Google Inc. All rights reserved.
     2  #
     3  # Licensed under the Apache License, Version 2.0 (the "License");
     4  # you may not use this file except in compliance with the License.
     5  # You may obtain a copy of the License at
     6  #
     7  #     http://www.apache.org/licenses/LICENSE-2.0
     8  #
     9  # Unless required by applicable law or agreed to in writing, software
    10  # distributed under the License is distributed on an "AS IS" BASIS,
    11  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  # See the License for the specific language governing permissions and
    13  # limitations under the License.
    14  
    15  # A set of defaults for Kubernetes releases
    16  
    17  PROJECT=$(gcloud config list project | tail -n 1 | cut -f 3 -d ' ')
    18  
    19  if which md5 > /dev/null; then
    20    HASH=$(md5 -q -s $PROJECT)
    21  else
    22    HASH=$(echo -n "$PROJECT" | md5sum)
    23  fi
    24  HASH=${HASH:0:5}
    25  RELEASE_BUCKET=${RELEASE_BUCKET-gs://kubernetes-releases-$HASH/}
    26  RELEASE_PREFIX=${RELEASE_PREFIX-devel/$USER/}
    27  RELEASE_NAME=${RELEASE_NAME-r$(date -u +%Y%m%d-%H%M%S)}
    28  
    29  # This is a 'soft link' to the release in question.  It is a single line file to
    30  # the full GS path for a release.
    31  RELEASE_TAG=${RELEASE_TAG-testing}
    32  
    33  RELEASE_TAR_FILE=master-release.tgz
    34  
    35  RELEASE_FULL_PATH=$RELEASE_BUCKET$RELEASE_PREFIX$RELEASE_NAME
    36  RELEASE_FULL_TAG_PATH=$RELEASE_BUCKET$RELEASE_PREFIX$RELEASE_TAG
    37  
    38  # Takes a release path ($1 if passed, otherwise $RELEASE_FULL_TAG_PATH) and
    39  # computes the normalized release path. Results are stored in
    40  # $RELEASE_NORMALIZED.  Returns 0 if a valid release can be found.
    41  function normalize_release() {
    42    RELEASE_NORMALIZED=${1-$RELEASE_FULL_TAG_PATH}
    43  
    44    # First test to see if there is a valid release at this path.
    45    if gsutil -q stat $RELEASE_NORMALIZED/$RELEASE_TAR_FILE; then
    46      return 0
    47    fi
    48  
    49    # Check if this is a simple file.  If so, read it and use the result as the
    50    # new RELEASE_NORMALIZED.
    51    if gsutil -q stat $RELEASE_NORMALIZED; then
    52      RELEASE_NORMALIZED=$(gsutil -q cat $RELEASE_NORMALIZED)
    53      normalize_release $RELEASE_NORMALIZED
    54      return
    55    fi
    56    return 1
    57  }
    58  
    59  # Sets a tag ($1) to a release ($2)
    60  function set_tag() {
    61    echo $2 | gsutil -q cp - $1
    62  
    63    gsutil -q setmeta -h "Cache-Control:private, max-age=0, no-transform" $1
    64    make_public_readable $1
    65  }
    66  
    67  # Makes a GCS object ($1) publicly readable
    68  function make_public_readable() {
    69    # Ideally we'd run the command below.  But this is currently broken in the
    70    # newest version of gsutil.  Instead, download the ACL and edit the json
    71    # quickly.
    72  
    73    # gsutil -q acl ch -g AllUsers:R $1
    74  
    75    TMPFILE=$(mktemp -t release 2>/dev/null || mktemp -t release.XXXX)
    76  
    77    gsutil -q acl get $1 \
    78      | python $(dirname $0)/make-public-gcs-acl.py \
    79      > $TMPFILE
    80      gsutil -q acl set $TMPFILE $RELEASE_FULL_PATH/$x
    81  
    82    rm $TMPFILE
    83  }