mirror of
https://github.com/linuxkit/linuxkit.git
synced 2025-07-19 09:16:29 +00:00
pkg/cadvisor
Signed-off-by: Marco Mariani <marco.mariani@alterway.fr>
This commit is contained in:
parent
3184572403
commit
959b6dd96d
40
pkg/cadvisor/Dockerfile
Normal file
40
pkg/cadvisor/Dockerfile
Normal file
@ -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 </tmp/static.patch \
|
||||||
|
&& make build \
|
||||||
|
&& mv cadvisor /usr/bin/
|
||||||
|
|
||||||
|
|
||||||
|
FROM linuxkit/alpine:07f7d136e427dc68154cd5edbb2b9576f9ac5213 AS mirror
|
||||||
|
|
||||||
|
RUN mkdir -p /out/etc/apk && cp -r /etc/apk/* /out/etc/apk/
|
||||||
|
RUN apk add --no-cache --initdb -p /out \
|
||||||
|
alpine-baselayout \
|
||||||
|
busybox \
|
||||||
|
curl
|
||||||
|
|
||||||
|
# Remove apk residuals
|
||||||
|
RUN rm -rf /out/etc/apk /out/lib/apk /out/var/cache
|
||||||
|
|
||||||
|
|
||||||
|
FROM scratch
|
||||||
|
ENTRYPOINT []
|
||||||
|
CMD []
|
||||||
|
WORKDIR /
|
||||||
|
COPY --from=mirror /out/ /
|
||||||
|
COPY --from=build /usr/bin/cadvisor /usr/bin/cadvisor
|
||||||
|
COPY /waitfordocker.sh /usr/bin/waitfordocker.sh
|
||||||
|
|
||||||
|
ENTRYPOINT ["/usr/bin/waitfordocker.sh", "/usr/bin/cadvisor", "-logtostderr", "--disable_metrics=disk,tcp,udp"]
|
||||||
|
LABEL org.mobyproject.config='{"pid": "host", "binds": ["/var/lib/docker:/var/lib/docker:ro", "/var/run:/var/run", "/sys:/sys:ro", "/etc/resolv.conf:/etc/resolv.conf:ro"], "capabilities": ["all"]}'
|
2
pkg/cadvisor/build.yml
Normal file
2
pkg/cadvisor/build.yml
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
image: cadvisor
|
||||||
|
network: true
|
10
pkg/cadvisor/static.patch
Normal file
10
pkg/cadvisor/static.patch
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
--- build/build.sh.orig 2017-11-16 16:29:18.281342577 +0000
|
||||||
|
+++ build/build.sh 2017-11-16 16:29:55.534787421 +0000
|
||||||
|
@@ -44,6 +44,7 @@
|
||||||
|
-X ${repo_path}/version.BuildDate${ldseparator}${BUILD_DATE}
|
||||||
|
-X ${repo_path}/version.GoVersion${ldseparator}${go_version}"
|
||||||
|
|
||||||
|
+ldflags="$ldflags -extldflags \"-static\""
|
||||||
|
echo ">> building cadvisor"
|
||||||
|
|
||||||
|
if [ -n "$VERBOSE" ]; then
|
49
pkg/cadvisor/waitfordocker.sh
Executable file
49
pkg/cadvisor/waitfordocker.sh
Executable file
@ -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 "$@"
|
Loading…
Reference in New Issue
Block a user