From f2d6fe1250544b2368649b9b106900a5b9caabb0 Mon Sep 17 00:00:00 2001 From: Quentin Gliech Date: Fri, 16 Dec 2022 18:24:00 +0100 Subject: [PATCH] docker: Build with musl instead of glibc --- Dockerfile | 10 +++++----- misc/docker-arch-to-rust-target.sh | 12 +++--------- 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/Dockerfile b/Dockerfile index d62e1443c..19eca941b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,7 +7,7 @@ # # Docker platform definitions look like this: linux/arm64 and linux/amd64, so # there is a small script that translates those platforms to LLVM triples, -# respectively x86-64-unknown-linux-gnu and aarch64-unknown-linux-gnu +# respectively x86-64-unknown-linux-musl and aarch64-unknown-linux-musl # The Debian version and version name must be in sync ARG DEBIAN_VERSION=11 @@ -89,8 +89,8 @@ RUN cargo install --locked cargo-chef cargo-zigbuild cargo-auditable # Install all cross-compilation targets RUN rustup target add --toolchain "${RUSTC_VERSION}" \ - x86_64-unknown-linux-gnu \ - aarch64-unknown-linux-gnu + x86_64-unknown-linux-musl \ + aarch64-unknown-linux-musl # Helper script that transforms docker platforms to LLVM triples COPY ./misc/docker-arch-to-rust-target.sh / @@ -151,7 +151,7 @@ COPY ./templates/ /share/templates ################################## ## Runtime stage, debug variant ## ################################## -FROM --platform=${TARGETPLATFORM} gcr.io/distroless/base-debian${DEBIAN_VERSION}:debug-nonroot AS debug +FROM --platform=${TARGETPLATFORM} gcr.io/distroless/static-debian${DEBIAN_VERSION}:debug-nonroot AS debug COPY --from=builder /usr/local/bin/mas-cli /usr/local/bin/mas-cli COPY --from=share /share /usr/local/share/mas-cli @@ -162,7 +162,7 @@ ENTRYPOINT ["/usr/local/bin/mas-cli"] ################### ## Runtime stage ## ################### -FROM --platform=${TARGETPLATFORM} gcr.io/distroless/base-debian${DEBIAN_VERSION}:nonroot +FROM --platform=${TARGETPLATFORM} gcr.io/distroless/static-debian${DEBIAN_VERSION}:nonroot COPY --from=builder /usr/local/bin/mas-cli /usr/local/bin/mas-cli COPY --from=share /share /usr/local/share/mas-cli diff --git a/misc/docker-arch-to-rust-target.sh b/misc/docker-arch-to-rust-target.sh index 673c4db3a..c2fbf9818 100755 --- a/misc/docker-arch-to-rust-target.sh +++ b/misc/docker-arch-to-rust-target.sh @@ -5,16 +5,10 @@ if [ "$#" -ne 1 ]; then exit 1 fi -if [ "$1" = "linux/arm64" -o "$1" = "linux/arm64/v8" ]; then - echo "aarch64-unknown-linux-gnu" -elif [ "$1" = "linux/arm" -o "$1" = "linux/arm/v7" ]; then - echo "armv7-unknown-linux-gnueabihf" -elif [ "$1" = "linux/arm/v6" ]; then - echo "arm-unknown-linux-gnueabihf" +if [ "$1" = "linux/arm64" ] || [ "$1" = "linux/arm64/v8" ]; then + echo "aarch64-unknown-linux-musl" elif [ "$1" = "linux/amd64" ]; then - echo "x86_64-unknown-linux-gnu" -elif [ "$1" = "linux/i386" ]; then - echo "i686-unknown-linux-gnu" + echo "x86_64-unknown-linux-musl" else echo "unsupported platform $1" >&2 exit 2