From afbf1450c2540ef93bdb0e79017b3d4b0e25a52f Mon Sep 17 00:00:00 2001 From: slydetector Date: Sun, 8 Mar 2026 15:24:23 -0500 Subject: [PATCH] Build and distribute latest smartmontools 7.5 as part of image (#924) Co-authored-by: slydetector Co-authored-by: Aram Akhavan <1147328+kaysond@users.noreply.github.com> --- Makefile | 9 +++++++-- docker/Dockerfile | 23 +++++++++++++++++++++-- docker/Dockerfile.collector | 25 ++++++++++++++++++++++--- docker/Dockerfile.smartmontools | 20 ++++++++++++++++++++ 4 files changed, 70 insertions(+), 7 deletions(-) create mode 100644 docker/Dockerfile.smartmontools diff --git a/Makefile b/Makefile index fd4bd5b..1d7f9ef 100644 --- a/Makefile +++ b/Makefile @@ -122,8 +122,13 @@ binary-frontend-test-coverage: # Docker # NOTE: these docker make targets are only used for local development (not used by Github Actions/CI) ######################################################################################################################## +.PHONY: docker-smartmontools +docker-smartmontools: + @echo "building smartmontools docker image" + docker build $(DOCKER_TARGETARCH_BUILD_ARG) -f docker/Dockerfile.smartmontools -t smartmontools-build . + .PHONY: docker-collector -docker-collector: +docker-collector: docker-smartmontools @echo "building collector docker image" docker build $(DOCKER_TARGETARCH_BUILD_ARG) -f docker/Dockerfile.collector -t ghcr.io/analogj/scrutiny-dev:collector . @@ -133,6 +138,6 @@ docker-web: docker build $(DOCKER_TARGETARCH_BUILD_ARG) -f docker/Dockerfile.web -t ghcr.io/analogj/scrutiny-dev:web . .PHONY: docker-omnibus -docker-omnibus: +docker-omnibus: docker-smartmontools @echo "building omnibus docker image" docker build $(DOCKER_TARGETARCH_BUILD_ARG) -f docker/Dockerfile -t ghcr.io/analogj/scrutiny-dev:omnibus . diff --git a/docker/Dockerfile b/docker/Dockerfile index f4a23cd..5e7e9d4 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -23,8 +23,25 @@ RUN apt-get update && DEBIAN_FRONTEND=noninteractive \ RUN make binary-clean binary-all WEB_BINARY_NAME=scrutiny +######## Build smartmontools from source +FROM debian:trixie-slim AS smartmontoolsbuild +ARG SMARTMONTOOLS_VER=7.5 +RUN apt-get update && DEBIAN_FRONTEND=noninteractive \ + apt-get install -y --no-install-recommends \ + ca-certificates curl gcc g++ gnupg make \ + && rm -rf /var/lib/apt/lists/* +RUN curl -L "https://github.com/smartmontools/smartmontools/releases/download/RELEASE_$(echo ${SMARTMONTOOLS_VER} | tr '.' '_')/smartmontools-${SMARTMONTOOLS_VER}.tar.gz" -o /tmp/smartmontools.tar.gz \ + && tar -xzf /tmp/smartmontools.tar.gz -C /tmp \ + && cd /tmp/smartmontools-${SMARTMONTOOLS_VER} \ + && ./configure --prefix=/usr LDFLAGS='-static' --without-libcap-ng --without-libsystemd \ + && make -j"$(nproc)" \ + && make install \ + && /usr/sbin/update-smart-drivedb \ + && rm -rf /tmp/smartmontools* + + ######## Combine build artifacts in runtime image -FROM debian:trixie-slim as runtime +FROM debian:trixie-slim AS runtime ARG TARGETARCH EXPOSE 8080 WORKDIR /opt/scrutiny @@ -40,7 +57,6 @@ RUN apt-get update && DEBIAN_FRONTEND=noninteractive \ ca-certificates \ cron \ curl \ - smartmontools \ tzdata \ procps \ xz-utils \ @@ -62,6 +78,9 @@ RUN curl -L https://dl.influxdata.com/influxdb/releases/influxdb2-${INFLUXVER}-$ COPY /rootfs / +COPY --from=smartmontoolsbuild /usr/sbin/smartctl /usr/sbin/smartctl +COPY --from=smartmontoolsbuild /usr/share/smartmontools/ /usr/share/smartmontools/ + COPY --link --from=backendbuild --chmod=755 /go/src/github.com/analogj/scrutiny/scrutiny /opt/scrutiny/bin/ COPY --link --from=backendbuild --chmod=755 /go/src/github.com/analogj/scrutiny/scrutiny-collector-metrics /opt/scrutiny/bin/ COPY --link --from=frontendbuild --chmod=644 /go/src/github.com/analogj/scrutiny/dist /opt/scrutiny/web diff --git a/docker/Dockerfile.collector b/docker/Dockerfile.collector index 8987a00..7549f0e 100644 --- a/docker/Dockerfile.collector +++ b/docker/Dockerfile.collector @@ -4,7 +4,7 @@ ######## -FROM golang:1.25-trixie as backendbuild +FROM golang:1.25-trixie AS backendbuild WORKDIR /go/src/github.com/analogj/scrutiny @@ -13,12 +13,31 @@ COPY . /go/src/github.com/analogj/scrutiny RUN apt-get update && apt-get install -y file && rm -rf /var/lib/apt/lists/* RUN make binary-clean binary-collector +######## Build smartmontools from source +FROM debian:trixie-slim AS smartmontoolsbuild +ARG SMARTMONTOOLS_VER=7.5 +RUN apt-get update && DEBIAN_FRONTEND=noninteractive \ + apt-get install -y --no-install-recommends \ + ca-certificates curl gcc g++ gnupg make \ + && rm -rf /var/lib/apt/lists/* +RUN curl -L "https://github.com/smartmontools/smartmontools/releases/download/RELEASE_$(echo ${SMARTMONTOOLS_VER} | tr '.' '_')/smartmontools-${SMARTMONTOOLS_VER}.tar.gz" -o /tmp/smartmontools.tar.gz \ + && tar -xzf /tmp/smartmontools.tar.gz -C /tmp \ + && cd /tmp/smartmontools-${SMARTMONTOOLS_VER} \ + && ./configure --prefix=/usr LDFLAGS='-static' --without-libcap-ng --without-libsystemd \ + && make -j"$(nproc)" \ + && make install \ + && /usr/sbin/update-smart-drivedb \ + && rm -rf /tmp/smartmontools* + ######## -FROM debian:trixie-slim as runtime +FROM debian:trixie-slim AS runtime WORKDIR /opt/scrutiny ENV PATH="/opt/scrutiny/bin:${PATH}" -RUN apt-get update && apt-get install -y cron smartmontools ca-certificates tzdata && rm -rf /var/lib/apt/lists/* && update-ca-certificates +RUN apt-get update && apt-get install -y cron ca-certificates tzdata && rm -rf /var/lib/apt/lists/* && update-ca-certificates + +COPY --from=smartmontoolsbuild /usr/sbin/smartctl /usr/sbin/smartctl +COPY --from=smartmontoolsbuild /usr/share/smartmontools/ /usr/share/smartmontools/ COPY /docker/entrypoint-collector.sh /entrypoint-collector.sh COPY /rootfs/etc/cron.d/scrutiny /etc/cron.d/scrutiny diff --git a/docker/Dockerfile.smartmontools b/docker/Dockerfile.smartmontools new file mode 100644 index 0000000..c351951 --- /dev/null +++ b/docker/Dockerfile.smartmontools @@ -0,0 +1,20 @@ +######################################################################################################################## +# Smartmontools Builder +# - Builds smartctl from source as a static binary. +# - Updates the drive database to include the latest drive models since it can change between releases. +# - Used as a shared build stage by Dockerfile and Dockerfile.collector. +######################################################################################################################## +FROM debian:trixie-slim +ARG SMARTMONTOOLS_VER=7.5 +RUN apt-get update && DEBIAN_FRONTEND=noninteractive \ + apt-get install -y --no-install-recommends \ + ca-certificates curl gcc g++ gnupg make \ + && rm -rf /var/lib/apt/lists/* +RUN curl -L "https://github.com/smartmontools/smartmontools/releases/download/RELEASE_$(echo ${SMARTMONTOOLS_VER} | tr '.' '_')/smartmontools-${SMARTMONTOOLS_VER}.tar.gz" -o /tmp/smartmontools.tar.gz \ + && tar -xzf /tmp/smartmontools.tar.gz -C /tmp \ + && cd /tmp/smartmontools-${SMARTMONTOOLS_VER} \ + && ./configure --prefix=/usr LDFLAGS='-static' --without-libcap-ng --without-libsystemd \ + && make -j"$(nproc)" \ + && make install \ + && /usr/sbin/update-smart-drivedb \ + && rm -rf /tmp/smartmontools*