k8s.io/kubernetes@v1.31.0-alpha.0.0.20240520171757-56147500dadc/cluster/gce/gci/mounter/stage-upload.sh (about)

     1  #!/usr/bin/env bash
     2  
     3  # Copyright 2016 The Kubernetes Authors.
     4  #
     5  # Licensed under the Apache License, Version 2.0 (the "License");
     6  # you may not use this file except in compliance with the License.
     7  # You may obtain a copy of the License at
     8  #
     9  #     http://www.apache.org/licenses/LICENSE-2.0
    10  #
    11  # Unless required by applicable law or agreed to in writing, software
    12  # distributed under the License is distributed on an "AS IS" BASIS,
    13  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    14  # See the License for the specific language governing permissions and
    15  # limitations under the License.
    16  
    17  # Due to the GCE custom metadata size limit, we split the entire script into two
    18  # files configure.sh and configure-helper.sh. The functionality of downloading
    19  # kubernetes configuration, manifests, docker images, and binary files are
    20  # put in configure.sh, which is uploaded via GCE custom metadata.
    21  
    22  set -o errexit
    23  set -o pipefail
    24  set -o nounset
    25  
    26  DOCKER2ACI_VERSION="v0.13.0"
    27  MOUNTER_VERSION=$1
    28  DOCKER_IMAGE=docker://$2
    29  MOUNTER_ACI_IMAGE=gci-mounter-${MOUNTER_VERSION}.aci
    30  MOUNTER_GCS_DIR=gs://kubernetes-release/gci-mounter/
    31  
    32  TMPDIR=/tmp
    33  # Setup a working directory
    34  DOWNLOAD_DIR=$(mktemp --tmpdir=${TMPDIR} -d gci-mounter-build.XXXXXXXXXX)
    35  
    36  # Setup a staging directory
    37  STAGING_DIR=$(mktemp --tmpdir=${TMPDIR} -d gci-mounter-staging.XXXXXXXXXX)
    38  ACI_DIR=${STAGING_DIR}/gci-mounter
    39  CWD=${PWD}
    40  
    41  # Cleanup the temporary directories
    42  cleanup() {
    43      rm -rf "${DOWNLOAD_DIR}"
    44      rm -rf "${STAGING_DIR}"
    45      cd "${CWD}"
    46  }
    47  
    48  # Delete temporary directories on exit
    49  trap cleanup EXIT
    50  
    51  mkdir "${ACI_DIR}"
    52  
    53  # Convert docker image to aci and stage it
    54  echo "Downloading docker2aci ${DOCKER2ACI_VERSION}"
    55  wget "https://github.com/appc/docker2aci/releases/download/${DOCKER2ACI_VERSION}/docker2aci-${DOCKER2ACI_VERSION}.tar.gz" >/dev/null 2>&1
    56  echo "Extracting docker2aci ${DOCKER2ACI_VERSION}"
    57  tar xzf docker2aci-${DOCKER2ACI_VERSION}.tar.gz
    58  ACI_IMAGE=$("${DOWNLOAD_DIR}/docker2aci-${DOCKER2ACI_VERSION}/docker2aci" "${DOCKER_IMAGE}" 2>/dev/null | tail -n 1)
    59  cp "${ACI_IMAGE}" "${ACI_DIR}/${MOUNTER_ACI_IMAGE}"
    60  
    61  # Upload the contents to gcs
    62  echo "Uploading gci mounter ACI in ${ACI_DIR} to ${MOUNTER_GCS_DIR}"
    63  gsutil cp "${ACI_DIR}/${MOUNTER_ACI_IMAGE}" "${MOUNTER_GCS_DIR}"
    64  
    65  echo "Upload completed"
    66  echo "Updated gci-mounter ACI version and SH512 in cluster/gce/gci/configure.sh"
    67  ACI_HASH=$(sha512sum "${ACI_DIR}/${MOUNTER_ACI_IMAGE}")
    68  echo "${MOUNTER_ACI_IMAGE} hash: ${ACI_HASH}"