From ec6b927cebe7b5981a544848ceafacd9e1f1ea94 Mon Sep 17 00:00:00 2001 From: Matt Hamilton Date: Wed, 8 Nov 2023 01:49:48 -0400 Subject: [PATCH] Optimised dockerfile for slightly smaller build image. It is still quite large due to rust cache --- Dockerfile | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/Dockerfile b/Dockerfile index 1b37e50..28e9356 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,19 +1,31 @@ # syntax=docker/dockerfile:1 +# Use a multi-stage build to compile the application +FROM rust:alpine as builder + +WORKDIR /usr/src/fendermint +# Install dependencies required for the build +RUN apk add --no-cache clang musl-dev git curl jq bash \ + && git clone https://github.com/consensus-shipyard/fendermint.git . \ + && cargo install --force cargo-make + + +# Start with a new, clean base image to reduce size FROM docker:cli -RUN apk add --no-cache clang musl-dev git curl jq bash +RUN apk add --no-cache bash jq curl libgcc -WORKDIR /app +# Copy only the compiled binaries and any other necessary files from the builder image +COPY --from=builder /usr/local/cargo/bin /usr/local/cargo/bin +COPY --from=builder /usr/src/fendermint /app/fendermint -COPY . . +# Set any environment variables needed +ENV PATH="/usr/local/cargo/bin:${PATH}" -RUN curl https://sh.rustup.rs -sSf | bash -s -- -y -ENV PATH="/root/.cargo/bin:${PATH}" -RUN cargo install --force cargo-make +# Set the work directory +WORKDIR /app -RUN git clone https://github.com/consensus-shipyard/fendermint.git && \ - cd fendermint && \ - cargo make --makefile ./infra/Makefile.toml info +RUN cd fendermint && cargo make --makefile ./infra/Makefile.toml info -ENTRYPOINT ["/bin/bash", "-c"] \ No newline at end of file +# Set the entrypoint +ENTRYPOINT ["/bin/bash", "-c"]