Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use slimmer docker image #10

Merged
merged 4 commits into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:

steps:
- name: Create release
uses: softprops/action-gh-release@v1
uses: softprops/action-gh-release@v2
with:
# create a draft release which needs manual approval
draft: true
63 changes: 38 additions & 25 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
FROM ghcr.io/rust-cross/rust-musl-cross:aarch64-musl AS aarch64-musl
FROM ghcr.io/rust-cross/rust-musl-cross:x86_64-musl AS musl_x86_64
FROM ghcr.io/rust-cross/rust-musl-cross:aarch64-musl AS musl_aarch64

FROM ghcr.io/rust-cross/rust-musl-cross:x86_64-musl AS x86_64-musl
FROM rust:1.80.1-slim-bookworm AS build-base

FROM rust:1.80.1-bookworm
# prepopulate cargo index
RUN cargo search --limit=1
RUN apt update && apt upgrade -y
RUN apt -y install \
# Prepopulate cargo index and install dependencies
RUN cargo search --limit=1 && \
apt update && apt upgrade -y && \
apt -y install --no-install-recommends \
g++-x86-64-linux-gnu \
g++-aarch64-linux-gnu \
protobuf-compiler \
Expand All @@ -15,64 +15,77 @@ RUN apt -y install \
cmake \
llvm \
liburing-dev \
ca-certificates
RUN curl --proto '=https' --tlsv1.2 -sSf https://just.systems/install.sh | bash -s -- --to /usr/local/bin
ca-certificates \
git \
curl && \
apt-get clean && rm -rf /var/lib/apt/lists/*

# Install rustup components and global tools in a single layer
RUN rustup target add \
x86_64-unknown-linux-musl \
aarch64-unknown-linux-musl \
x86_64-unknown-linux-gnu \
aarch64-unknown-linux-gnu
RUN rustup component add clippy rustfmt
RUN cargo install [email protected] [email protected]

COPY --from=x86_64-musl "/usr/local/musl" /usr/local/musl-x86_64/
COPY --from=aarch64-musl "/usr/local/musl" /usr/local/musl-aarch64/
ENV PATH="${PATH}:/usr/local/musl-x86_64/bin:/usr/local/musl-aarch64/bin"
aarch64-unknown-linux-gnu && \
rustup component add clippy rustfmt && \
cargo install [email protected] [email protected]

# linker script forcing static compilation of libstdc++
RUN echo 'GROUP ( libstdc++.a AS_NEEDED( -lgcc -lc -lm ) )' > $(readlink -f $(x86_64-unknown-linux-musl-g++ --print-file-name libstdc++.so))
RUN echo 'GROUP ( libstdc++.a AS_NEEDED( -lgcc -lc -lm ) )' > $(readlink -f $(aarch64-unknown-linux-musl-g++ --print-file-name libstdc++.so))
# Install `just`
RUN curl --proto '=https' --tlsv1.2 -sSf https://just.systems/install.sh | bash -s -- --to /usr/local/bin

# Install `sccache` and `buf` in a single layer
ARG TARGETARCH
RUN arch=$(echo "$TARGETARCH" | sed s/arm64/aarch64/ | sed s/amd64/x86_64/) && \
curl -LSfs https://github.com/mozilla/sccache/releases/download/v0.7.4/sccache-v0.7.4-${arch}-unknown-linux-musl.tar.gz -o sccache.tar.gz && \
tar -xvf sccache.tar.gz && \
rm sccache.tar.gz && \
cp sccache-v0.7.4-${arch}-unknown-linux-musl/sccache /usr/bin/sccache && \
rm -rf sccache-v0.7.4-${arch}-unknown-linux-musl
rm -rf sccache-v0.7.4-${arch}-unknown-linux-musl && \
curl -sSL "https://github.com/bufbuild/buf/releases/download/v1.29.0/buf-Linux-${arch}" -o "/usr/bin/buf" && \
chmod +x "/usr/bin/buf"

# Copy musl from the prebuilt x86_64 and aarch64 images
COPY --from=musl_x86_64 "/usr/local/musl" /usr/local/musl-x86_64/
COPY --from=musl_aarch64 "/usr/local/musl" /usr/local/musl-aarch64/

# Set environment variables for cross-compilation
ENV PATH="${PATH}:/usr/local/musl-x86_64/bin:/usr/local/musl-aarch64/bin"
ENV SCCACHE_DIR=/usr/local/sccache
ENV RUSTC_WRAPPER="sccache"

RUN arch=$(echo "$TARGETARCH" | sed s/arm64/aarch64/ | sed s/amd64/x86_64/) && \
curl -sSL "https://github.com/bufbuild/buf/releases/download/v1.29.0/buf-Linux-${arch}" -o "/usr/bin/buf" && \
chmod +x "/usr/bin/buf"
# linker script forcing static compilation of libstdc++
RUN echo 'GROUP ( libstdc++.a AS_NEEDED( -lgcc -lc -lm ) )' > $(readlink -f $(x86_64-unknown-linux-musl-g++ --print-file-name libstdc++.so))
RUN echo 'GROUP ( libstdc++.a AS_NEEDED( -lgcc -lc -lm ) )' > $(readlink -f $(aarch64-unknown-linux-musl-g++ --print-file-name libstdc++.so))

# x86_64 musl
ENV CC_x86_64_unknown_linux_musl="sccache x86_64-unknown-linux-musl-gcc"
ENV CXX_x86_64_unknown_linux_musl="sccache x86_64-unknown-linux-musl-g++"
ENV AR_x86_64_unknown_linux_musl="x86_64-unknown-linux-musl-ar"
ENV CARGO_TARGET_X86_64_UNKNOWN_LINUX_MUSL_LINKER="x86_64-unknown-linux-musl-gcc"
ENV BINDGEN_EXTRA_CLANG_ARGS_x86_64_unknown_linux_musl="--sysroot=/usr/x86_64-linux-musl"

# aarch64 musl
ENV CC_aarch64_unknown_linux_musl="sccache aarch64-unknown-linux-musl-gcc"
ENV CXX_aarch64_unknown_linux_musl="sccache aarch64-unknown-linux-musl-g++"
ENV AR_aarch64_unknown_linux_musl="aarch64-unknown-linux-musl-ar"
ENV CARGO_TARGET_AARCH64_UNKNOWN_LINUX_MUSL_LINKER="aarch64-unknown-linux-musl-gcc"
ENV BINDGEN_EXTRA_CLANG_ARGS_aarch64_unknown_linux_musl="--sysroot=/usr/aarch64-linux-musl"

# x86_64 gnu
ENV CC_x86_64_unknown_linux_gnu="sccache x86_64-linux-gnu-gcc"
ENV CXX_x86_64_unknown_linux_gnu="sccache x86_64-linux-gnu-g++"
ENV AR_x86_64_unknown_linux_gnu="x86_64-linux-gnu-ar"
ENV CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_LINKER="x86_64-linux-gnu-gcc"
ENV BINDGEN_EXTRA_CLANG_ARGS_x86_64_unknown_linux_gnu="--sysroot=/usr/x86_64-linux-gnu"

# aarch64 gnu
ENV CC_aarch64_unknown_linux_gnu="sccache aarch64-linux-gnu-gcc"
ENV CXX_aarch64_unknown_linux_gnu="sccache aarch64-linux-gnu-g++"
ENV AR_aarch64_unknown_linux_gnu="aarch64-linux-gnu-ar"
ENV CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER="aarch64-linux-gnu-gcc"
ENV BINDGEN_EXTRA_CLANG_ARGS_aarch64_unknown_linux_gnu="--sysroot=/usr/aarch64-linux-gnu"

ENV RUSTC_WRAPPER="sccache"

# Set up working directory
WORKDIR /restate

# Make git work if different owner runs commands
RUN git config --global --add safe.directory /restate