github.com/google/cadvisor@v0.49.1/build/check_container.sh (about)

     1  #!/usr/bin/env bash
     2  # Copyright 2015 Google Inc. All rights reserved.
     3  #
     4  # Licensed under the Apache License, Version 2.0 (the "License");
     5  # you may not use this file except in compliance with the License.
     6  # You may obtain a copy of the License at
     7  #
     8  #     http://www.apache.org/licenses/LICENSE-2.0
     9  #
    10  # Unless required by applicable law or agreed to in writing, software
    11  # distributed under the License is distributed on an "AS IS" BASIS,
    12  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  # See the License for the specific language governing permissions and
    14  # limitations under the License.
    15  #
    16  # Description:
    17  # This script is meant to run a basic test against each of the CPU architectures
    18  # cadvisor should support.
    19  #
    20  # This script requires that you have run qemu-user-static so that your machine
    21  # can interpret ELF binaries for other architectures using QEMU:
    22  # https://github.com/multiarch/qemu-user-static#getting-started
    23  #
    24  # $ docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
    25  #
    26  # Usage:
    27  # ./check_container.sh gcr.io/tstapler-gke-dev/cadvisor:v0.44.1-test-4
    28  target_image=$1
    29  
    30  # Architectures officially supported by cadvisor
    31  arches=( "amd64" "arm" "arm64" )
    32  
    33  # Docker doesn't handle images with different architectures but the same tag.
    34  # Remove the container and the image use by it to avoid problems.
    35  cleanup() {
    36      echo Cleaning up the container $1
    37      docker stop $1
    38      docker rmi $target_image
    39      echo
    40  }
    41  
    42  for arch in "${arches[@]}"; do
    43    echo Testing that we can run $1 on $arch and curl the /healthz endpoint
    44    echo
    45    container_id=$(docker run --platform "linux/$arch" -p 8080:8080 --rm --detach "$target_image")
    46    docker_exit_code=$?
    47    if [ $docker_exit_code -ne 0 ]; then
    48      echo Failed to run container docker exited with $docker_exit_code
    49      cleanup $container_id
    50      exit $docker_exit_code
    51    fi
    52    sleep 10
    53    echo
    54    echo Testing the container with curl:
    55    curl --show-error --retry 5 --fail -L 127.0.0.1:8080/healthz
    56    echo
    57    echo
    58    curl_exit=$?
    59    if [ $curl_exit -ne 0 ]; then
    60      echo  Curling $target_image did not work
    61      cleanup $container_id
    62      exit $curl_exit
    63    fi
    64    echo Success!
    65    echo
    66    cleanup $container_id
    67  done