Merge pull request #2736 from Wolphin-project/cadvisor

cAdvisor
This commit is contained in:
Rolf Neugebauer 2017-11-22 19:35:30 +00:00 committed by GitHub
commit ddcc98c3fe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 160 additions and 0 deletions

59
examples/cadvisor.yml Normal file
View File

@ -0,0 +1,59 @@
kernel:
image: linuxkit/kernel:4.9.62
cmdline: "console=tty0 console=ttyS0 console=ttyAMA0"
init:
- linuxkit/init:42a92119e1ca10380e0d33e26c0cbcf85b9b3558
- linuxkit/runc:1b0741d07949c0acc444cd6a04ee7f833443579d
- linuxkit/containerd:bfb61cc1d26c39cd4b2bc08f7a9963fefa0ef3bf
- linuxkit/ca-certificates:af4880e78edc28743f7c5e262678c67c6add4c26
onboot:
- name: sysctl
image: linuxkit/sysctl:a9ad57ed738a31ea9380cd73236866c312b35489
- name: dhcpcd
image: linuxkit/dhcpcd:48831507404049660b960e4055f544917d90378e
command: ["/sbin/dhcpcd", "--nobackground", "-f", "/dhcpcd.conf", "-1"]
- name: sysfs
image: linuxkit/sysfs:5367b46211882278b84a9e8048855ca5df65beda
- name: format
image: linuxkit/format:6b46d0450082f397177da36be6b4d74d93eacd1e
- name: mount
image: linuxkit/mount:41685ecc8039643948e5dff46e17584753469a7a
command: ["/usr/bin/mountie", "/var/lib/docker"]
services:
- name: getty
image: linuxkit/getty:6af22c32c98536a79230eef000e9abd06b037faa
env:
- INSECURE=true
- name: rngd
image: linuxkit/rngd:842e5e8ece7934f0cab9fd0027b595ff3471e5b9
- name: ntpd
image: linuxkit/openntpd:07a80c3e3e816658318ac027e1253ff9a228b8de
- name: docker
image: docker:17.10.0-ce-dind
capabilities:
- all
net: host
mounts:
- type: cgroup
options: ["rw", "nosuid", "noexec", "nodev", "relatime"]
binds:
- /etc/resolv.conf:/etc/resolv.conf
- /var/lib/docker:/var/lib/docker
- /var/run:/var/run
- /lib/modules:/lib/modules
- /etc/docker/daemon.json:/etc/docker/daemon.json
command: ["/usr/local/bin/docker-init", "/usr/local/bin/dockerd"]
- name: cadvisor
image: linuxkit/cadvisor:42264edeebe7f76272ff691854ec592b7e5ae536
files:
- path: var/lib/docker
directory: true
- path: etc/docker/daemon.json
contents: '{"debug": true, "hosts": ["unix:///var/run/docker.sock"]}'
mode: "0644"
trust:
org:
- linuxkit
- library

40
pkg/cadvisor/Dockerfile Normal file
View 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
View File

@ -0,0 +1,2 @@
image: cadvisor
network: true

10
pkg/cadvisor/static.patch Normal file
View 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
View 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 "$@"