This repository has been archived by the owner on Aug 30, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docker: use multi-stages dockerfiles
The image we currently produce is over 4GB large. In order to reduce this, we perform the compilation in a build container, and just copy the coordinator and aggregator binaries to the final image. This commit also removes the dependency vendoring. The main reason for having it was to cache the dependencies. But that doesn't cache the builds. Instead we use `cargo fetch` and `cargo build` on an empty project that contains all our dependencies to force cargo to cache them. Finally, we split the images: - an image to upload to docker hub, that contains a release build - an image for development that contains a debug build as well as some dev tools (Valgrind)
- Loading branch information
1 parent
30ebca6
commit 9d0735d
Showing
5 changed files
with
66 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,34 @@ | ||
FROM python:3.7.6-slim-buster | ||
|
||
ARG RELEASE_BUILD=false | ||
FROM python:3.7.6-slim-buster AS builder | ||
|
||
# Install rust nightly | ||
# Install Rust nightly | ||
ENV RUSTUP_HOME=/usr/local/rustup \ | ||
CARGO_HOME=/usr/local/cargo \ | ||
PATH=/usr/local/cargo/bin:$PATH | ||
|
||
RUN set -eux; \ | ||
apt-get update; \ | ||
apt-get install -y --no-install-recommends \ | ||
ca-certificates \ | ||
gcc \ | ||
libc6-dev \ | ||
wget \ | ||
libssl-dev \ | ||
pkg-config \ | ||
; \ | ||
\ | ||
url="https://static.rust-lang.org/rustup/dist/x86_64-unknown-linux-gnu/rustup-init"; \ | ||
wget "$url"; \ | ||
chmod +x rustup-init; \ | ||
./rustup-init -y --no-modify-path --default-toolchain nightly; \ | ||
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 docker/install_rust.sh . | ||
RUN bash ./install_rust.sh | ||
|
||
# Install dev tools | ||
RUN apt-get update; \ | ||
apt-get install -y valgrind \ | ||
; | ||
RUN apt-get update && apt-get install -y valgrind | ||
|
||
WORKDIR /usr/src/coordinator | ||
# https://benjamincongdon.me/blog/2019/12/04/Fast-Rust-Docker-Builds-with-cargo-vendor/ | ||
# First, fetch and build all the dependencies by compiling an empty | ||
# crate that depends on everything | ||
COPY rust/Cargo.lock . | ||
COPY rust/Cargo.toml . | ||
RUN mkdir .cargo | ||
RUN cargo vendor > .cargo/config | ||
RUN cargo fetch | ||
RUN mkdir -p ./src && \ | ||
touch src/lib.rs && \ | ||
cargo build --lib --all-features | ||
|
||
# Now copy the actual source code | ||
COPY rust/src src | ||
COPY ./docker/compile.sh . | ||
RUN bash compile.sh | ||
# Fix timestamp. cargo incremental build as issues caused by the above | ||
# trick to compile the deps separately | ||
RUN touch src/lib.rs | ||
RUN cargo build --all-features | ||
|
||
FROM python:3.7.6-slim-buster | ||
|
||
COPY --from=builder /target/debug/aggregator /bin/aggregator | ||
COPY --from=builder /target/debug/coordinator /bin/coordinator | ||
COPY python/aggregators aggregators/ | ||
RUN pip install aggregators/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
FROM python:3.7.6-slim-buster AS builder | ||
|
||
# Install Rust nightly | ||
ENV RUSTUP_HOME=/usr/local/rustup \ | ||
CARGO_HOME=/usr/local/cargo \ | ||
PATH=/usr/local/cargo/bin:$PATH | ||
COPY docker/install_rust.sh . | ||
RUN bash ./install_rust.sh | ||
|
||
COPY rust/Cargo.lock . | ||
COPY rust/Cargo.toml . | ||
COPY rust/src src | ||
RUN cargo build --release --features=telemetry,influx_metrics | ||
|
||
|
||
FROM python:3.7.6-slim-buster | ||
|
||
COPY --from=builder /target/release/aggregator /bin/aggregator | ||
COPY --from=builder /target/release/coordinator /bin/coordinator | ||
COPY python/aggregators aggregators/ | ||
RUN pip install aggregators/ |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#!/bin/bash | ||
|
||
set -eux | ||
|
||
apt-get update | ||
apt-get install -y --no-install-recommends \ | ||
ca-certificates \ | ||
gcc \ | ||
libc6-dev \ | ||
wget \ | ||
libssl-dev \ | ||
pkg-config \ | ||
|
||
wget "https://static.rust-lang.org/rustup/dist/x86_64-unknown-linux-gnu/rustup-init" | ||
|
||
chmod +x rustup-init | ||
|
||
./rustup-init -y --no-modify-path --default-toolchain nightly | ||
chmod -R a+w $RUSTUP_HOME $CARGO_HOME | ||
|
||
rustup --version | ||
cargo --version | ||
rustc --version |