From 959b6dd96da9ee76dd374b63dcfd0e202860a03b Mon Sep 17 00:00:00 2001 From: Marco Mariani Date: Thu, 16 Nov 2017 18:15:59 +0100 Subject: [PATCH] pkg/cadvisor Signed-off-by: Marco Mariani --- pkg/cadvisor/Dockerfile | 40 ++++++++++++++++++++++++++++ pkg/cadvisor/build.yml | 2 ++ pkg/cadvisor/static.patch | 10 +++++++ pkg/cadvisor/waitfordocker.sh | 49 +++++++++++++++++++++++++++++++++++ 4 files changed, 101 insertions(+) create mode 100644 pkg/cadvisor/Dockerfile create mode 100644 pkg/cadvisor/build.yml create mode 100644 pkg/cadvisor/static.patch create mode 100755 pkg/cadvisor/waitfordocker.sh diff --git a/pkg/cadvisor/Dockerfile b/pkg/cadvisor/Dockerfile new file mode 100644 index 000000000..87bfe41b8 --- /dev/null +++ b/pkg/cadvisor/Dockerfile @@ -0,0 +1,40 @@ +FROM linuxkit/alpine:07f7d136e427dc68154cd5edbb2b9576f9ac5213 as build + +RUN apk add --no-cache bash go git musl-dev linux-headers make + +ENV GOPATH=/go PATH=$PATH:/go/bin +ENV GITREPO=github.com/google/cadvisor +ENV COMMIT=v0.28.1 + +ADD /static.patch /tmp/ + +RUN go get -d ${GITREPO} \ + && cd /go/src/${GITREPO} \ + && git checkout ${COMMIT} \ + && patch -p1 build/build.sh > building cadvisor" + + if [ -n "$VERBOSE" ]; then diff --git a/pkg/cadvisor/waitfordocker.sh b/pkg/cadvisor/waitfordocker.sh new file mode 100755 index 000000000..09ffad4f3 --- /dev/null +++ b/pkg/cadvisor/waitfordocker.sh @@ -0,0 +1,49 @@ +#!/bin/sh +# copied from projects/compose, with fixes for shellcheck +# shellcheck disable=SC2039 +set -e + +######### +# +# wait for docker socket to be ready, then run the rest of the command +# +######## +RETRIES=${RETRIES:-"-1"} +WAIT=${WAIT:=10} +[ -n "$DEBUG" ] && set -x + +# keep retrying until docker is ready or we hit our limit +retry_or_fail() { + local retry_count=0 + local success=1 + local cmd=$1 + local retryMax=$2 + local retrySleep=$3 + local message=$4 + until [ "$retry_count" -ge "$retryMax" ] && [ "$retryMax" -ne -1 ]; do + echo "trying to $message" + set +e + $cmd + success=$? + set -e + [ $success -eq 0 ] && break + retry_count=$(( retry_count+1 )) || true + echo "attempt number $retry_count failed to $message, sleeping $retrySleep seconds..." + sleep "$retrySleep" + done + # did we succeed? + if [ $success -ne 0 ]; then + echo "failed to $message after $retryMax tries. Exiting..." >&2 + exit 1 + fi +} + +connect_to_docker() { + [ -S /var/run/docker.sock ] || return 1 + curl --unix-socket /var/run/docker.sock http://localhost/containers/json >/dev/null 2>&1 || return 1 +} +# try to connect to docker +retry_or_fail connect_to_docker "$RETRIES" "$WAIT" "connect to docker" + +# if we got here, we succeeded +exec "$@"