diff --git a/deploy/Dockerfile b/deploy/Dockerfile index d67c9f7de0..03d653c0db 100644 --- a/deploy/Dockerfile +++ b/deploy/Dockerfile @@ -58,14 +58,23 @@ RUN apk --no-cache add libc6-compat device-mapper findutils ndctl thin-provision # Grab cadvisor,libpfm4 and libipmctl from "build" container if they exist (libipmctl only works on amd64/x86_64). COPY --from=build /usr/local/lib/libpfm.so* /usr/local/lib/ -COPY --from=build /usr/local/lib/libipmctl.so* /usr/local/lib/ +# Disable libipmctl due to https://github.com/google/cadvisor/issues/3482 +#COPY --from=build /usr/local/lib/libipmctl.so* /usr/local/lib/ COPY --from=build /go/src/github.com/google/cadvisor/_output/cadvisor /usr/bin/cadvisor +COPY deploy/entrypoint.sh /usr/bin/entrypoint.sh +RUN chmod +x /usr/bin/entrypoint.sh + +COPY deploy/healthcheck.sh /usr/bin/healthcheck.sh +RUN chmod +x /usr/bin/healthcheck.sh + +# Default port is 8080, but can be changed with -port flag +# Users should expose their custom port with: docker run -p : EXPOSE 8080 -ENV CADVISOR_HEALTHCHECK_URL=http://localhost:8080/healthz +HEALTHCHECK --interval=30s --timeout=3s --start-period=5s \ + CMD /usr/bin/healthcheck.sh -HEALTHCHECK --interval=30s --timeout=3s \ - CMD wget --quiet --tries=1 --spider $CADVISOR_HEALTHCHECK_URL || exit 1 +# Use entrypoint wrapper +ENTRYPOINT ["/usr/bin/entrypoint.sh"] -ENTRYPOINT ["/usr/bin/cadvisor", "-logtostderr"] diff --git a/deploy/entrypoint.sh b/deploy/entrypoint.sh new file mode 100644 index 0000000000..4c489dfbfa --- /dev/null +++ b/deploy/entrypoint.sh @@ -0,0 +1,20 @@ +#!/bin/bash + +# Copyright 2025 Google Inc. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +set -e + +# Execute cadvisor with all provided arguments +exec /usr/bin/cadvisor -logtostderr "$@" diff --git a/deploy/healthcheck.sh b/deploy/healthcheck.sh new file mode 100644 index 0000000000..4742dd06f0 --- /dev/null +++ b/deploy/healthcheck.sh @@ -0,0 +1,37 @@ +#!/bin/bash + +# Copyright 2025 Google Inc. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# Default port +PORT=8080 + +# Extract port from the cadvisor process command line +if [ -f /proc/1/cmdline ]; then + CMDLINE=$(tr '\0' ' ' < /proc/1/cmdline) + + # Look for -port=XXXX or --port=XXXX + for arg in $CMDLINE; do + case "$arg" in + -port=*) + PORT="${arg#-port=}" + ;; + --port=*) + PORT="${arg#--port=}" + ;; + esac + done +fi + +wget --quiet --tries=1 --spider "http://localhost:${PORT}/healthz" || exit 1