github.com/google/cadvisor@v0.49.1/build/release.sh (about) 1 #!/usr/bin/env bash 2 3 # Copyright 2015 Google Inc. All rights reserved. 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 set -e 18 19 if [ -z "$VERSION" ]; then 20 VERSION=$( git describe --tags --dirty --abbrev=14 | sed -E 's/-([0-9]+)-g/.\1+/' ) 21 # Only allow releases of tagged versions. 22 TAGGED='^v[0-9]+\.[0-9]+\.[0-9]+(-(alpha|beta|rc)\.?[0-9]*)?$' 23 if [[ ! "$VERSION" =~ $TAGGED ]]; then 24 echo "Error: Only tagged versions are allowed for releases" >&2 25 echo "Found: $VERSION" >&2 26 exit 1 27 fi 28 fi 29 30 read -p "Please confirm: $VERSION is the desired version (Type y/n to continue):" -n 1 -r 31 echo 32 if ! [[ $REPLY =~ ^[Yy]$ ]]; then 33 exit 1 34 fi 35 36 # Don't include hostname with release builds 37 if ! git_user="$(git config --get user.email)"; then 38 echo "Error: git user not set, use:" 39 echo "git config user.email <email>" 40 exit 1 41 fi 42 43 export BUILD_USER="$git_user" 44 export BUILD_DATE=$( date +%Y%m%d ) # Release date is only to day-granularity 45 export VERBOSE=true 46 47 # Build the docker image 48 echo ">> building cadvisor docker image" 49 image_name=${IMAGE_NAME:-"gcr.io/cadvisor/cadvisor"} 50 final_image="$image_name:${VERSION}" 51 52 docker buildx inspect cadvisor-builder > /dev/null \ 53 || docker buildx create --name cadvisor-builder --use 54 55 # Build binaries 56 57 # A mapping of the docker arch name to the qemu arch name 58 declare -A arches=( ["amd64"]="x86_64" ["arm"]="arm" ["arm64"]="aarch64" ) 59 60 for arch in "${arches[@]}"; do 61 if ! hash "qemu-${arch}-static"; then 62 echo Releasing multi arch containers requires qemu-user-static. 63 echo 64 echo Please install using apt-get install qemu-user-static or 65 echo a similar package for your OS. 66 67 exit 1 68 fi 69 done 70 71 for arch in "${!arches[@]}"; do 72 GOARCH="$arch" GO_CGO_ENABLED="0" OUTPUT_NAME_WITH_ARCH="true" build/build.sh 73 arch_specific_image="${image_name}-${arch}:${VERSION}" 74 docker buildx build --platform "linux/${arch}" --build-arg VERSION="$VERSION" -f deploy/Dockerfile -t "$arch_specific_image" --progress plain --push . 75 docker manifest create --amend "$final_image" "$arch_specific_image" 76 docker manifest annotate --os=linux --arch="$arch" "$final_image" "$arch_specific_image" 77 done 78 docker manifest push "$final_image" 79 echo 80 echo "Release info (copy to the release page)": 81 echo 82 echo Multi Arch Container Image: 83 echo $final_image 84 echo 85 echo Architecture Specific Container Images: 86 for arch in "${!arches[@]}"; do 87 echo "${image_name}-${arch}:${VERSION}" 88 done 89 echo 90 echo Binaries: 91 (cd _output && find . -name "cadvisor-${VERSION}*" -exec sha256sum --tag {} \;) 92 exit 0