Skip to content

Commit 9ef8cec

Browse files
committed
Cache intermediate layers of container build
1 parent 9cfe855 commit 9ef8cec

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

.github/workflows/_container.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ jobs:
2929
# Need load and tags so we can test it below
3030
load: true
3131
tags: test_tag
32+
cache-from: type=gha
33+
cache-to: type=gha,mode=max
3234

3335
- name: Test cli works in cached runtime image
3436
run: docker run --rm test_tag --version

Dockerfile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,15 @@ RUN rustup target add x86_64-unknown-linux-musl && \
66
apt-get install -y musl-tools musl-dev && \
77
update-ca-certificates
88

9+
# Build an empty project with only the Cargo files to improve the cache
10+
# performance of the container build. The src directory is expected to
11+
# change most frequently invalidating later caches so building early
12+
# allows built dependencies to be cached.
13+
RUN mkdir src && echo 'fn main() {}' > src/main.rs
914
COPY ./Cargo.toml ./Cargo.toml
1015
COPY ./Cargo.lock ./Cargo.lock
16+
RUN cargo build --release --target x86_64-unknown-linux-musl
17+
1118
COPY ./src ./src
1219

1320
RUN cargo build --release --target x86_64-unknown-linux-musl

0 commit comments

Comments
 (0)