Skip to content

Commit

Permalink
ci: Try and speed up QNS docker build (#2092)
Browse files Browse the repository at this point in the history
* ci: Try and speed up QNS docker build

Via https://github.com/LukeMathWalker/cargo-chef

* Update qns/Dockerfile

Co-authored-by: Max Inden <mail@max-inden.de>
Signed-off-by: Lars Eggert <lars@eggert.org>

---------

Signed-off-by: Lars Eggert <lars@eggert.org>
Co-authored-by: Max Inden <mail@max-inden.de>
  • Loading branch information
larseggert and mxinden authored Sep 9, 2024
1 parent 28f60bd commit b1b0da3
Showing 1 changed file with 19 additions and 49 deletions.
68 changes: 19 additions & 49 deletions qns/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,51 +1,18 @@
FROM martenseemann/quic-network-simulator-endpoint@sha256:517712019dda2a4d6f39e4490a55f29eae7ba415624067efe749f896e577ea91 AS buildimage
FROM lukemathwalker/cargo-chef:latest-rust-latest AS chef

RUN apt-get update && apt-get install -y --no-install-recommends \
git coreutils build-essential libclang-dev lld gyp ninja-build zlib1g-dev python-is-python3 \
&& apt-get autoremove -y && apt-get clean -y \
&& rm -rf /var/lib/apt/lists/*
WORKDIR /app

# From https://github.com/rust-lang/docker-rust/blob/master/1.80.0/bookworm/slim/Dockerfile

ENV RUSTUP_HOME=/usr/local/rustup \
CARGO_HOME=/usr/local/cargo \
PATH=/usr/local/cargo/bin:$PATH \
RUST_VERSION=1.80.0
FROM chef AS planner

RUN set -eux; \
apt-get update; \
apt-get install -y --no-install-recommends \
ca-certificates \
gcc \
libc6-dev \
wget \
; \
dpkgArch="$(dpkg --print-architecture)"; \
case "${dpkgArch##*-}" in \
amd64) rustArch='x86_64-unknown-linux-gnu'; rustupSha256='6aeece6993e902708983b209d04c0d1dbb14ebb405ddb87def578d41f920f56d' ;; \
armhf) rustArch='armv7-unknown-linux-gnueabihf'; rustupSha256='3c4114923305f1cd3b96ce3454e9e549ad4aa7c07c03aec73d1a785e98388bed' ;; \
arm64) rustArch='aarch64-unknown-linux-gnu'; rustupSha256='1cffbf51e63e634c746f741de50649bbbcbd9dbe1de363c9ecef64e278dba2b2' ;; \
i386) rustArch='i686-unknown-linux-gnu'; rustupSha256='0a6bed6e9f21192a51f83977716466895706059afb880500ff1d0e751ada5237' ;; \
ppc64el) rustArch='powerpc64le-unknown-linux-gnu'; rustupSha256='079430f58ad4da1d1f4f5f2f0bd321422373213246a93b3ddb53dad627f5aa38' ;; \
s390x) rustArch='s390x-unknown-linux-gnu'; rustupSha256='e7f89da453c8ce5771c28279d1a01d5e83541d420695c74ec81a7ec5d287c51c' ;; \
*) echo >&2 "unsupported architecture: ${dpkgArch}"; exit 1 ;; \
esac; \
url="https://static.rust-lang.org/rustup/archive/1.27.1/${rustArch}/rustup-init"; \
wget "$url"; \
echo "${rustupSha256} *rustup-init" | sha256sum -c -; \
chmod +x rustup-init; \
./rustup-init -y --no-modify-path --profile minimal --default-toolchain $RUST_VERSION --default-host ${rustArch}; \
rm rustup-init; \
chmod -R a+w $RUSTUP_HOME $CARGO_HOME; \
rustup --version; \
cargo --version; \
rustc --version; \
apt-get remove -y --auto-remove \
wget \
; \
rm -rf /var/lib/apt/lists/*;
COPY . .
RUN cargo chef prepare --recipe-path recipe.json

# End of copy from https://github.com/rust-lang/docker-rust...
FROM chef AS builder
RUN apt-get update && apt-get install -y --no-install-recommends \
libclang-dev gyp ninja-build python-is-python3 \
&& apt-get autoremove -y && apt-get clean -y \
&& rm -rf /var/lib/apt/lists/*

# We unfortunately need to build NSS from source, because the Debian package is
# not compiled with support for SSLKEYLOGFILE.
Expand All @@ -60,21 +27,24 @@ RUN set -eux; \

RUN "$NSS_DIR"/build.sh --static -Ddisable_tests=1 -o

COPY --from=planner /app/recipe.json recipe.json
# Build dependencies
RUN cargo chef cook --release --recipe-path recipe.json
# Build application
ADD . /neqo

RUN set -eux; \
cd /neqo; \
RUSTFLAGS="-C link-arg=-fuse-ld=lld" cargo build --release \
--bin neqo-client --bin neqo-server
cargo build --release --bin neqo-client --bin neqo-server

# Copy only binaries to the final image to keep it small.


FROM martenseemann/quic-network-simulator-endpoint@sha256:517712019dda2a4d6f39e4490a55f29eae7ba415624067efe749f896e577ea91

ENV LD_LIBRARY_PATH=/neqo/lib
COPY --from=buildimage /neqo/target/release/neqo-client /neqo/target/release/neqo-server /neqo/bin/
COPY --from=buildimage /dist/Release/lib/*.so /neqo/lib/
COPY --from=buildimage /dist/Release/bin/certutil /dist/Release/bin/pk12util /neqo/bin/
COPY --from=builder /neqo/target/release/neqo-client /neqo/target/release/neqo-server /neqo/bin/
COPY --from=builder /dist/Release/lib/*.so /neqo/lib/
COPY --from=builder /dist/Release/bin/certutil /dist/Release/bin/pk12util /neqo/bin/

COPY qns/interop.sh /neqo/
RUN chmod +x /neqo/interop.sh
Expand Down

0 comments on commit b1b0da3

Please sign in to comment.