Skip to content
This repository has been archived by the owner on Aug 30, 2022. It is now read-only.

Improve the docker infra #348

Merged
merged 1 commit into from
Mar 26, 2020
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
59 changes: 20 additions & 39 deletions docker/Dockerfile
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/
21 changes: 21 additions & 0 deletions docker/Dockerfile.release
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/
11 changes: 0 additions & 11 deletions docker/compile.sh

This file was deleted.

6 changes: 2 additions & 4 deletions docker/docker-compose-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ services:
command: coordinator -c /bin/config.toml
build:
context: ..
dockerfile: docker/Dockerfile
args:
RELEASE_BUILD: "true"
dockerfile: docker/Dockerfile.release
image: docker_coordinator:release
depends_on:
- influxdb
Expand All @@ -23,7 +21,7 @@ services:
command: aggregator -c /bin/config.toml
build:
context: ..
dockerfile: docker/Dockerfile
dockerfile: docker/Dockerfile.release
args:
RELEASE_BUILD: "true"
image: docker_aggregator:release
Expand Down
23 changes: 23 additions & 0 deletions docker/install_rust.sh
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