Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: use buildkit cache for dockerfile #860

Merged
merged 5 commits into from
Apr 3, 2024
Merged

Conversation

joroshiba
Copy link
Member

@joroshiba joroshiba commented Mar 25, 2024

Summary

Using new buildx cache instead of cargo chef for image updates, makes subsequent updates much faster locally.

Background

Cargo chef has not created huge speed up in build times due to nature of our dependencies. In local tests it improves second build by ~1 minute while slowing first build by about 3 minutes. This makes the first local build take ~4 min and then subsequent minor updates can be built in less than 30s.

Changes

  • Remove cargo chef
  • Utilize buildkit caches

Testing

Running locally, testing image built + CI tests on here to see how it impacts CI build time.

@joroshiba joroshiba requested a review from a team as a code owner March 25, 2024 22:17
@joroshiba joroshiba added the docker-build used to trigger docker builds on PRs label Mar 25, 2024
@github-actions github-actions bot added the ci issues that are related to ci and github workflows label Mar 25, 2024
@joroshiba joroshiba changed the title ci: use buildx cache for dockerfile ci: use buildkit cache for dockerfile Mar 25, 2024
RUN \
--mount=type=cache,target=/usr/local/cargo/registry \
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mounting a buildkit cache to cover the cargo registry + target dir

elif [ "$TARGETPLATFORM" = "linux/amd64" ]; then ARCH=x86_64; fi; \
cp target/$ARCH-unknown-linux-gnu/release/$TARGETBINARY target/release/
cp target/$ARCH-unknown-linux-gnu/release/$TARGETBINARY release/;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this used to be a seperate step, but now that it is in the cache, made a single step. Copies the executable out of the cache directory into a seperate one. We might be able to replace with out_dir if/when that is stabilized.

@joroshiba joroshiba force-pushed the joroshiba/faster-docker branch from c2aec42 to a5bc1b3 Compare March 25, 2024 23:22
elif [ "$TARGETPLATFORM" = "linux/amd64" ]; then ARCH=x86_64; fi; \
cp target/$ARCH-unknown-linux-gnu/release/$TARGETBINARY target/release/
cp target/$ARCH-unknown-linux-gnu/release/$TARGETBINARY release/;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the reason for doing this? Is moving from target/$ARCH-unknown-linux-gnu/release to target/release invalidating the cache?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the cache is all of target/, if you run in a different command the file doesn't exist because you need to mount the cache. By moving the artifact out of the cache it persists.

Copy link
Member

@SuperFluffy SuperFluffy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is nice. Shame that cargo-chef didn't work out for our purposes. We can consider bringing it back if our dependency structure changes.

@joroshiba joroshiba enabled auto-merge April 3, 2024 00:34
@joroshiba joroshiba added this pull request to the merge queue Apr 3, 2024
Merged via the queue into main with commit f472a22 Apr 3, 2024
35 checks passed
@joroshiba joroshiba deleted the joroshiba/faster-docker branch April 3, 2024 00:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ci issues that are related to ci and github workflows docker docker-build used to trigger docker builds on PRs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants