From 22a84c82c473c9067c68f0c4f3d6c899308bbc3e Mon Sep 17 00:00:00 2001 From: Eguzki Astiz Lezaun Date: Tue, 26 Sep 2023 18:08:27 +0200 Subject: [PATCH] image build: layer caching --- .github/workflows/build-image.yaml | 1 + Dockerfile | 22 +++++++++++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build-image.yaml b/.github/workflows/build-image.yaml index a725ff74..0ad7dda0 100644 --- a/.github/workflows/build-image.yaml +++ b/.github/workflows/build-image.yaml @@ -36,6 +36,7 @@ jobs: with: image: limitador tags: ${{ env.IMG_TAGS }} + layers: true platforms: linux/amd64,linux/arm64 dockerfiles: | ./Dockerfile diff --git a/Dockerfile b/Dockerfile index 8e44b28d..ef058e96 100644 --- a/Dockerfile +++ b/Dockerfile @@ -22,11 +22,31 @@ RUN PKGS="gcc-c++ gcc-toolset-12-binutils-gold openssl-devel protobuf-c protobuf RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- --no-modify-path --profile minimal --default-toolchain ${RUSTC_VERSION} -c rustfmt -y WORKDIR /usr/src/limitador - ARG GITHUB_SHA ENV GITHUB_SHA=${GITHUB_SHA:-unknown} ENV RUSTFLAGS="-C target-feature=-crt-static" +COPY ./Cargo.lock ./Cargo.lock +COPY ./Cargo.toml ./Cargo.toml + +COPY limitador/Cargo.toml ./limitador/Cargo.toml +COPY limitador-server/Cargo.toml ./limitador-server/Cargo.toml + +RUN mkdir -p limitador/src limitador-server/src + +RUN echo "fn main() {println!(\"if you see this, the build broke\")}" > limitador/src/main.rs \ + && echo "fn main() {println!(\"if you see this, the build broke\")}" > limitador-server/src/main.rs + +RUN source $HOME/.cargo/env \ + && cargo build --release + +# avoid downloading and compiling all the dependencies when there's a change in +# our code. +RUN ls target +RUN ls target/release +RUN ls target/release/deps +RUN rm -f target/release/limitador* + COPY . . RUN source $HOME/.cargo/env \