github.com/google/cadvisor@v0.49.1/build/integration-in-docker.sh (about) 1 #!/usr/bin/env bash 2 3 # Copyright 2020 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 -ex 18 19 ROOT="$(cd "$(dirname "${BASH_SOURCE}")/.." && pwd -P)" 20 TMPDIR=$(mktemp -d) 21 function delete() { 22 echo "Deleting ${TMPDIR}..." 23 if [[ $EUID -ne 0 ]]; then 24 sudo rm -rf "${TMPDIR}" 25 else 26 rm -rf "${TMPDIR}" 27 fi 28 } 29 trap delete EXIT INT TERM 30 31 function run_tests() { 32 33 # Add safe.directory as workaround for https://github.com/actions/runner/issues/2033 34 BUILD_CMD="git config --global safe.directory /go/src/github.com/google/cadvisor && env GOOS=linux GOARCH=amd64 GO_FLAGS='$GO_FLAGS' ./build/build.sh && \ 35 env GOOS=linux GOFLAGS='$GO_FLAGS' go test -c github.com/google/cadvisor/integration/tests/api && \ 36 env GOOS=linux GOFLAGS='$GO_FLAGS' go test -c github.com/google/cadvisor/integration/tests/healthz" 37 38 if [ "$BUILD_PACKAGES" != "" ]; then 39 BUILD_CMD="apt update && apt install -y $BUILD_PACKAGES && \ 40 $BUILD_CMD" 41 fi 42 docker run --rm \ 43 -w /go/src/github.com/google/cadvisor \ 44 -v ${PWD}:/go/src/github.com/google/cadvisor \ 45 golang:"$GOLANG_VERSION-bullseye" \ 46 bash -c "$BUILD_CMD" 47 48 EXTRA_DOCKER_OPTS="-e DOCKER_IN_DOCKER_ENABLED=true" 49 if [[ "${OSTYPE}" == "linux"* ]]; then 50 EXTRA_DOCKER_OPTS+=" -v ${TMPDIR}/docker-graph:/docker-graph" 51 fi 52 53 mkdir ${TMPDIR}/docker-graph 54 docker run --rm \ 55 -w /go/src/github.com/google/cadvisor \ 56 -v ${ROOT}:/go/src/github.com/google/cadvisor \ 57 ${EXTRA_DOCKER_OPTS} \ 58 --privileged \ 59 --cap-add="sys_admin" \ 60 --entrypoint="" \ 61 gcr.io/k8s-testimages/bootstrap \ 62 bash -c "export DEBIAN_FRONTEND=noninteractive && \ 63 echo 'deb http://deb.debian.org/debian buster-backports main'>/etc/apt/sources.list.d/buster.list && \ 64 cat /etc/apt/sources.list.d/buster.list && \ 65 apt update && \ 66 apt install -y -t buster-backports $PACKAGES && \ 67 CADVISOR_ARGS="$CADVISOR_ARGS" /usr/local/bin/runner.sh build/integration.sh" 68 } 69 70 GO_FLAGS=${GO_FLAGS:-"-tags=netgo -race"} 71 PACKAGES=${PACKAGES:-"sudo"} 72 BUILD_PACKAGES=${BUILD_PACKAGES:-} 73 CADVISOR_ARGS=${CADVISOR_ARGS:-} 74 GOLANG_VERSION=${GOLANG_VERSION:-"1.22"} 75 run_tests "$GO_FLAGS" "$PACKAGES" "$BUILD_PACKAGES" "$CADVISOR_ARGS"