github.com/noironetworks/cilium-net@v1.6.12/contrib/release/uploadrev (about)

     1  #!/bin/bash
     2  # Upload a Cilium revision to releases.cilium.io. This will be used to host
     3  # releases on a seperate location.
     4  #
     5  # TODO: update sphinx Documentation with process when bucket is setup. See
     6  # GH-1303 (Provide stable URL for stable release tarballs)[0].
     7  # [0]: https://github.com/cilium/cilium/issues/1303
     8  
     9  set -e
    10  
    11  function usage() {
    12    echo "Usage: $BASH_SOURCE <revision>"
    13    echo "Example: $BASH_SOURCE v1.0.0-rc2"
    14    echo "Environment:"
    15    grep -F \$\{ $BASH_SOURCE
    16  }
    17  
    18  if [ "$#" -lt 1 ]; then
    19    usage
    20    exit 1
    21  fi
    22  
    23  REV=$1
    24  
    25  function perror() {
    26    echo `tput setaf 1`$@`tput sgr0`
    27  }
    28  
    29  function configure_env() {
    30    if ! which aws; then
    31      perror "Please install or make sure aws is in your PATH"
    32      perror "See the user guide for more info "
    33      perror "https://docs.aws.amazon.com/cli/latest/userguide/installing.html"
    34      exit 1
    35    fi
    36    ARCH=${ARCH:-"`uname -m`"}
    37    DOMAIN=${DOMAIN:-"releases.cilium.io"}
    38    REMOTE_DIR=${REMOTE_DIR:-"$REV"}
    39    PREPEND=${PREPEND:-"cilium-$REV/"}
    40    ZIP_FILE=${ZIP_FILE:-"$REV.zip"}
    41    TARBALL=${TARBALL:-"$REV.tar.gz"}
    42    DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
    43    TARGET_DIR=${TARGET_DIR:-"$DIR/../../_build/`basename $REMOTE_DIR`"}
    44    CILIUM_SOURCE=${CILIUM_SOURCE:-"$DIR/../../"}
    45    SKIP_UPLOAD=${SKIP_UPLOAD:-0}
    46  }
    47  
    48  
    49  function create_dir() {
    50    if test -d $TARGET_DIR; then
    51      rm -rf $TARGET_DIR
    52    fi
    53    mkdir -pv $TARGET_DIR
    54    mkdir -pv $TARGET_DIR/tools
    55  }
    56  
    57  function copy_source() {
    58    git archive --prefix=$PREPEND -o $TARGET_DIR/$ZIP_FILE $REV
    59    git archive --format=tar.gz -o $TARGET_DIR/$TARBALL --prefix=$PREPEND $REV
    60  }
    61  
    62  function copy_binaries_cilium_docker() {
    63    echo "target_dir: $TARGET_DIR"
    64    mkdir -p $TARGET_DIR
    65    SHA=$(docker create docker.io/cilium/docker-plugin:$REV)
    66    docker cp $SHA:/usr/bin/cilium-docker $TARGET_DIR/cilium-docker-$ARCH
    67    docker rm -f $SHA
    68  }
    69  
    70  function copy_binaries_cilium_operator() {
    71    mkdir -p $TARGET_DIR
    72    SHA=$(docker create docker.io/cilium/operator:$REV)
    73    docker cp $SHA:/usr/bin/cilium-operator $TARGET_DIR/cilium-operator-$ARCH
    74    docker rm -f $SHA
    75  }
    76  
    77  function generate_sha_digest_for_binaries() {
    78    mkdir -p $TARGET_DIR
    79    # Generate  SHA256 digest
    80    cd $TARGET_DIR
    81    for f in *; do
    82      [ ! -d "$f" ] && sha256sum $f > $f.sha256sum
    83    done
    84  }
    85  
    86  function copy_binaries() {
    87    mkdir -p $TARGET_DIR
    88    SHA=$(docker create docker.io/cilium/cilium:$REV)
    89    docker cp $SHA:/usr/bin/cilium-agent $TARGET_DIR/cilium-$ARCH
    90    docker cp $SHA:/usr/bin/cilium-agent $TARGET_DIR/cilium-agent-$ARCH
    91    docker cp $SHA:/usr/bin/cilium-agent $TARGET_DIR/cilium-node-monitor-$ARCH
    92    docker cp $SHA:/usr/bin/cilium-bugtool $TARGET_DIR/cilium-bugtool-$ARCH
    93    docker cp $SHA:/usr/bin/cilium-health $TARGET_DIR/cilium-health-$ARCH
    94    docker cp $SHA:/usr/bin/cilium-health-responder $TARGET_DIR/cilium-health-responder-$ARCH
    95    docker cp $SHA:/usr/bin/cilium-envoy $TARGET_DIR/cilium-envoy-$ARCH
    96    docker cp $SHA:/opt/cni/bin/cilium-cni $TARGET_DIR/cilium-cni-$ARCH
    97    cp contrib/k8s/k8s-cilium-exec.sh $TARGET_DIR/tools/ || true
    98    cp contrib/k8s/k8s-get-cilium-pod.sh $TARGET_DIR/tools/ || true
    99    cp contrib/k8s/k8s-unmanaged.sh $TARGET_DIR/tools/ || true
   100    docker rm -f $SHA
   101    copy_binaries_cilium_operator
   102    copy_binaries_cilium_docker
   103    generate_sha_digest_for_binaries
   104  }
   105  
   106  
   107  function upload_all() {
   108    if [ $SKIP_UPLOAD == 1 ]; then
   109      echo "Skipping upload"
   110      return
   111    fi
   112    # Upload all files
   113    aws s3 cp --recursive $TARGET_DIR s3://$DOMAIN/$REMOTE_DIR
   114  }
   115  
   116  function print_done() {
   117    echo "--- markdown snippet for NEWS.rst  ---"
   118    echo "Release binaries"
   119    echo "----------------"
   120    echo ""
   121  
   122    cd $TARGET_DIR
   123    for s in *.sha256sum; do
   124      f=$(echo "$s" | sed s/\.sha256sum//)	
   125      echo "* [$f](http://$DOMAIN/$REMOTE_DIR/$f) ([$(cat $s | cut -c1-20)](http://$DOMAIN/$REMOTE_DIR/$s))"
   126    done
   127    echo "--- end ---"
   128    echo "`tput setaf 2`DONE`tput sgr0` local files are in $TARGET_DIR."
   129  }
   130  
   131  function main() {
   132    configure_env
   133    create_dir
   134    copy_source
   135    copy_binaries
   136    upload_all
   137    print_done
   138  }
   139  
   140  main