Skip to content

Commit

Permalink
Cache dependencies in docker builds
Browse files Browse the repository at this point in the history
  • Loading branch information
Dzejkop committed Dec 5, 2023
1 parent 3e55932 commit 1852855
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,25 @@ ENV CARGO_HOME="/root/.cargo"
# Install the toolchain
RUN rustup component add cargo

# TODO: Hacky but it works
RUN mkdir -p ./src
RUN mkdir -p ./crates/postgres-docker-utils/src
RUN mkdir -p ./crates/fake-rpc/src

# Copy only Cargo.toml for better caching
COPY ./Cargo.toml ./Cargo.toml
COPY ./Cargo.lock ./Cargo.lock
COPY ./crates/postgres-docker-utils/Cargo.toml ./crates/postgres-docker-utils/Cargo.toml
COPY ./crates/fake-rpc/Cargo.toml ./crates/fake-rpc/Cargo.toml

RUN echo "fn main() {}" > ./src/main.rs
RUN echo "fn main() {}" > ./crates/postgres-docker-utils/src/main.rs
RUN echo "fn main() {}" > ./crates/fake-rpc/src/main.rs

# Prebuild dependencies
RUN cargo fetch
RUN cargo build --release --no-default-features

# Copy all the source files
# .dockerignore ignores the target dir
COPY . .
Expand Down

0 comments on commit 1852855

Please sign in to comment.