From 8bddd1889246a2bda6bc0ac6f0eb595aaa60e3dd Mon Sep 17 00:00:00 2001 From: 7d4d9e33 <167094550+7d4d9e33@users.noreply.github.com> Date: Thu, 1 Oct 2026 22:15:11 +0700 Subject: [PATCH 1/5] edit Dockerfile.alpine - moved to latest version - build dynamically linked binary instead of static binary to make it more native - enabled Rust error backtracing on build error --- Dockerfile.alpine | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/Dockerfile.alpine b/Dockerfile.alpine index 94b708741..88f2eed68 100644 --- a/Dockerfile.alpine +++ b/Dockerfile.alpine @@ -1,29 +1,33 @@ -# supported versions here: https://hub.docker.com/_/rust -ARG RUST_BUILDER_VERSION=slim-bookworm -ARG ALPINE_VERSION=3.23 +# supported versions here: +# - https://hub.docker.com/_/rust +# - https://hub.docker.com/_/alpine +ARG ALPINE_VERSION=3.24 ######################## ## builder image ######################## -FROM ghcr.io/rust-cross/rust-musl-cross:x86_64-musl AS builder +FROM rust:alpine${ALPINE_VERSION} AS builder -RUN apt-get update \ - && apt-get -y install git cmake perl pkg-config libclang-dev \ - && rm -rf /var/lib/apt/lists/* - -RUN rustup target add x86_64-unknown-linux-musl +RUN apk add --update-cache --no-cache gcc g++ clang-dev git cmake make perl pkgconf nasm \ + && rm -rf /var/cache/apk/* WORKDIR /redlib +# display backtrace on build error +ENV RUST_BACKTRACE=full + +# enable dynamic linking, older rust disabled this for musl target by default +ENV RUSTFLAGS="-C target-feature=-crt-static -C link-self-contained=no" + # download (most) dependencies in their own layer COPY Cargo.lock Cargo.toml ./ RUN mkdir src && echo "fn main() { panic!(\"why am i running?\") }" > src/main.rs -RUN cargo build --release --locked --bin redlib --target x86_64-unknown-linux-musl +RUN cargo build --release --locked --bin redlib RUN rm ./src/main.rs && rmdir ./src # copy the source and build the redlib binary COPY . ./ -RUN cargo build --release --locked --bin redlib --target x86_64-unknown-linux-musl +RUN cargo build --release --locked --bin redlib RUN echo "finished building redlib!" ######################## @@ -31,8 +35,12 @@ RUN echo "finished building redlib!" ######################## FROM alpine:${ALPINE_VERSION} AS release +# without gcc compat layer, redlib will crash with undefined symbols +RUN apk add --update-cache --no-cache libgcc \ + && rm -rf /var/cache/apk/* + # Import redlib binary from builder -COPY --from=builder /redlib/target/x86_64-unknown-linux-musl/release/redlib /usr/local/bin/redlib +COPY --from=builder /redlib/target/release/redlib /usr/local/bin/redlib # Add non-root user for running redlib RUN adduser --home /nonexistent --no-create-home --disabled-password redlib From f4a47c5f237cef691016cf3fcac321e9f1588f3d Mon Sep 17 00:00:00 2001 From: 7d4d9e33 <167094550+7d4d9e33@users.noreply.github.com> Date: Thu, 1 Oct 2026 22:24:04 +0700 Subject: [PATCH 2/5] added debian slim image --- Dockerfile.debian-slim | 56 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 Dockerfile.debian-slim diff --git a/Dockerfile.debian-slim b/Dockerfile.debian-slim new file mode 100644 index 000000000..29a87d747 --- /dev/null +++ b/Dockerfile.debian-slim @@ -0,0 +1,56 @@ +# supported versions here: +# - https://hub.docker.com/_/rust +# - https://hub.docker.com/_/debian +ARG DEBIAN_VERSION_CODENAME=trixie + +######################## +## builder image +######################## +FROM rust:slim-${DEBIAN_VERSION_CODENAME} AS builder + +RUN apt-get update \ + && apt-get install -y --no-install-recommends --no-install-suggests gcc g++ libclang-dev git cmake make perl pkg-config nasm \ + && rm -rf /var/lib/apt/lists/* + +WORKDIR /redlib + +# display backtrace on build error +ENV RUST_BACKTRACE=full + +# download (most) dependencies in their own layer +COPY Cargo.lock Cargo.toml ./ +RUN mkdir src && echo "fn main() { panic!(\"why am i running?\") }" > src/main.rs +RUN cargo build --release --locked --bin redlib +RUN rm ./src/main.rs && rmdir ./src + +# copy the source and build the redlib binary +COPY . ./ +RUN cargo build --release --locked --bin redlib +RUN echo "finished building redlib!" + +######################## +## release image +######################## +FROM debian:${DEBIAN_VERSION_CODENAME}-slim AS release + +# Import redlib binary from builder +COPY --from=builder /redlib/target/release/redlib /usr/local/bin/redlib + +# Add non-root user for running redlib +RUN useradd \ + --no-create-home \ + --password "!" \ + --comment "user for running redlib" \ + redlib +USER redlib + +# Document that we intend to expose port 8080 to whoever runs the container +EXPOSE 8080 + +# Run a healthcheck every minute to make sure redlib is functional +HEALTHCHECK --interval=1m --timeout=3s CMD wget --spider -q http://localhost:8080/settings || exit 1 + +# Add container metadata +LABEL org.opencontainers.image.authors="sigaloid" + +CMD ["redlib"] From 05e782a7c8e9797548302b19ea036796228342ed Mon Sep 17 00:00:00 2001 From: 7d4d9e33 <167094550+7d4d9e33@users.noreply.github.com> Date: Thu, 1 Oct 2026 23:05:44 +0700 Subject: [PATCH 3/5] add distroless image --- Dockerfile.distroless | 51 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 Dockerfile.distroless diff --git a/Dockerfile.distroless b/Dockerfile.distroless new file mode 100644 index 000000000..e6a52e088 --- /dev/null +++ b/Dockerfile.distroless @@ -0,0 +1,51 @@ +# supported versions here: https://github.com/googlecontainertools/distroless +ARG DEBIAN_VERSION_NUMBER=13 +# supported builder cpu architectures here: https://github.com/rust-cross/rust-musl-cross +ARG RUST_MUSL_CROSS_TAG=x86_64-musl + +######################## +## builder image +######################## +FROM ghcr.io/rust-cross/rust-musl-cross:${RUST_MUSL_CROSS_TAG} AS builder + +ARG COMPILE_TARGET=x86_64-unknown-linux-musl + +RUN apt-get update \ + && apt-get -y install git cmake perl pkg-config libclang-dev \ + && rm -rf /var/lib/apt/lists/* + +RUN rustup target add ${COMPILE_TARGET} + +WORKDIR /redlib + +# download (most) dependencies in their own layer +COPY Cargo.lock Cargo.toml ./ +RUN mkdir src && echo "fn main() { panic!(\"why am i running?\") }" > src/main.rs +RUN cargo build --release --locked --bin redlib --target ${COMPILE_TARGET} +RUN rm ./src/main.rs && rmdir ./src + +# copy the source and build the redlib binary +COPY . ./ +RUN cargo build --release --locked --bin redlib --target ${COMPILE_TARGET} +RUN echo "finished building redlib!" + +######################## +## release image +######################## +FROM gcr.io/distroless/static-debian${DEBIAN_VERSION_NUMBER}:nonroot AS release + +ARG COMPILE_TARGET=x86_64-unknown-linux-musl + +# Import redlib binary from builder +COPY --from=builder --chown=65532:65532 /redlib/target/${COMPILE_TARGET}/release/redlib /usr/local/bin/redlib + +# Document that we intend to expose port 8080 to whoever runs the container +EXPOSE 8080 + +# Run a healthcheck every minute to make sure redlib is functional +HEALTHCHECK --interval=1m --timeout=3s CMD wget --spider -q http://localhost:8080/settings || exit 1 + +# Add container metadata +LABEL org.opencontainers.image.authors="sigaloid" + +CMD ["redlib"] From 47d0e29b7610972d7ada5e99c2ba0a18a7a7cdc2 Mon Sep 17 00:00:00 2001 From: 7d4d9e33 <167094550+7d4d9e33@users.noreply.github.com> Date: Thu, 1 Oct 2026 23:14:06 +0700 Subject: [PATCH 4/5] enable rust backtracing in distroless image --- Dockerfile.distroless | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Dockerfile.distroless b/Dockerfile.distroless index e6a52e088..11aa84522 100644 --- a/Dockerfile.distroless +++ b/Dockerfile.distroless @@ -18,6 +18,9 @@ RUN rustup target add ${COMPILE_TARGET} WORKDIR /redlib +# display backtrace on build error +ENV RUST_BACKTRACE=full + # download (most) dependencies in their own layer COPY Cargo.lock Cargo.toml ./ RUN mkdir src && echo "fn main() { panic!(\"why am i running?\") }" > src/main.rs From aa66573b1ac54a511c996c42f8228527677725b8 Mon Sep 17 00:00:00 2001 From: 7d4d9e33 <167094550+7d4d9e33@users.noreply.github.com> Date: Thu, 1 Oct 2026 23:28:20 +0700 Subject: [PATCH 5/5] update Dockerfile.ubuntu - move to newer rust builder - move to newer ubuntu - enable rust backtrace --- Dockerfile.ubuntu | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Dockerfile.ubuntu b/Dockerfile.ubuntu index c929de718..1843f3c3e 100644 --- a/Dockerfile.ubuntu +++ b/Dockerfile.ubuntu @@ -1,6 +1,6 @@ # supported versions here: https://hub.docker.com/_/rust -ARG RUST_BUILDER_VERSION=slim-bookworm -ARG UBUNTU_RELEASE_VERSION=noble +ARG RUST_BUILDER_VERSION=slim-trixie +ARG UBUNTU_RELEASE_VERSION=resolute ######################## ## builder image @@ -13,6 +13,9 @@ RUN apt-get update \ WORKDIR /redlib +# display backtrace on build error +ENV RUST_BACKTRACE=full + # download (most) dependencies in their own layer COPY Cargo.lock Cargo.toml ./ RUN mkdir src && echo "fn main() { panic!(\"why am i running?\") }" > src/main.rs