Skip to content

Commit

Permalink
Incremental docker build for validator image
Browse files Browse the repository at this point in the history
This diff changes build time from 40 to few minutes for incremental change, which is incredibly valuable during triage
  • Loading branch information
Andrey Chursin committed Oct 11, 2019
1 parent 8ac093d commit 243f535
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 21 deletions.
17 changes: 17 additions & 0 deletions docker/validator/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,21 @@ if [ "$https_proxy" ]; then
PROXY=" --build-arg https_proxy=$https_proxy --build-arg http_proxy=$http_proxy"
fi

rm -f libra-node-from-docker

docker build -f $DIR/validator_builder.Dockerfile $DIR/../.. --tag libra-node-builder $PROXY
TARGET=$DIR/../../target/libra-node-builder/
mkdir -p $TARGET
if docker ps -f name=libra-node-builder-container -f ancestor=libra-node-builder | grep libra-node-builder-container ; then
echo "Builder container is running with latest builder image"
else
echo "Builder image has changed, re-creating builder container"
docker rm -f libra-node-builder-container || echo "Build container did not exist"
docker run --name libra-node-builder-container -d -i -t -v $DIR/../..:/libra libra-node-builder bash
fi

docker exec -i -t libra-node-builder-container bash -c 'source /root/.cargo/env; cargo build -p libra-node --target-dir /target && /bin/cp /target/debug/libra-node target/libra-node-builder/'

ln target/libra-node-builder/libra-node libra-node-from-docker
docker build -f $DIR/validator.Dockerfile $DIR/../.. --tag libra_e2e --build-arg GIT_REV="$(git rev-parse HEAD)" --build-arg GIT_UPSTREAM="$(git merge-base HEAD origin/master)" --build-arg BUILD_DATE="$(date -u +'%Y-%m-%dT%H:%M:%SZ')" $PROXY
rm -f libra-node-from-docker
22 changes: 1 addition & 21 deletions docker/validator/validator.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,28 +1,8 @@
FROM debian:stretch as builder

# To use http/https proxy while building, use:
# docker build --build-arg https_proxy=http://fwdproxy:8080 --build-arg http_proxy=http://fwdproxy:8080

RUN echo "deb http://deb.debian.org/debian stretch-backports main" > /etc/apt/sources.list.d/backports.list \
&& apt-get update && apt-get install -y protobuf-compiler/stretch-backports cmake curl clang \
&& apt-get clean && rm -r /var/lib/apt/lists/*

RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain none
ENV PATH "$PATH:/root/.cargo/bin"

WORKDIR /libra
COPY rust-toolchain /libra/rust-toolchain
RUN rustup install $(cat rust-toolchain)

COPY . /libra
RUN cargo build --release -p libra-node -p client -p benchmark

### Production Image ###
FROM debian:stretch

RUN mkdir -p /opt/libra/bin /opt/libra/etc
COPY docker/install-tools.sh /root
COPY --from=builder /libra/target/release/libra-node /opt/libra/bin
COPY libra-node-from-docker /opt/libra/bin/libra-node

# Admission control
EXPOSE 8000
Expand Down
15 changes: 15 additions & 0 deletions docker/validator/validator_builder.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
FROM debian:stretch

# To use http/https proxy while building, use:
# docker build --build-arg https_proxy=http://fwdproxy:8080 --build-arg http_proxy=http://fwdproxy:8080

RUN echo "deb http://deb.debian.org/debian stretch-backports main" > /etc/apt/sources.list.d/backports.list \
&& apt-get update && apt-get install -y protobuf-compiler/stretch-backports cmake curl clang
# && apt-get clean && rm -r /var/lib/apt/lists/*

RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain none
ENV PATH "$PATH:/root/.cargo/bin"

WORKDIR /libra
COPY rust-toolchain /libra/rust-toolchain
RUN rustup install $(cat rust-toolchain)

0 comments on commit 243f535

Please sign in to comment.