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

[Enhancement] Improve docker image build times #153

Closed
CosmicHorrorDev opened this issue Feb 22, 2021 · 1 comment · Fixed by #165
Closed

[Enhancement] Improve docker image build times #153

CosmicHorrorDev opened this issue Feb 22, 2021 · 1 comment · Fixed by #165
Labels
docker Tag if its related to docker enhancement New feature or request github Tag if its related to github

Comments

@CosmicHorrorDev
Copy link
Collaborator

CosmicHorrorDev commented Feb 22, 2021

Cache odin compilation with cargo chef

I'm sure you'be noticed, but currently there is a full clean compile each time the odin image is built. cargo chef helps fix this issue by doing some magic behind the scenes to enable docker to cache the dependencies and all that. I've personally been using it already locally to help with build times when testing. This is the custom dockerfile I've been using for odin:

FROM lukemathwalker/cargo-chef as planner
WORKDIR /data/odin
COPY . .
RUN cargo chef prepare --recipe-path recipe.json

FROM lukemathwalker/cargo-chef as cacher
WORKDIR /data/odin
COPY --from=planner /data/odin/recipe.json recipe.json
RUN cargo chef cook --release --recipe-path recipe.json

FROM rust as builder
WORKDIR /data/odin
COPY . .
# Copy over the cached dependencies
COPY --from=cacher /data/odin/target target
COPY --from=cacher $CARGO_HOME $CARGO_HOME
RUN cargo build --release --bin odin

FROM rust as runtime
WORKDIR /data/odin
COPY --from=builder /data/odin/target/release/odin /usr/local/bin
ENTRYPOINT ["/usr/local/bin/odin"]
CMD ["--version"]

This is basically a barely modified version of the example in cargo chef's README.

Cache the build info with github actions

Now the next step would be to cache the files so that they can actually be used to speed up CI. It looks like this action can help with that, but I honestly haven't done any docker image building in CI before so there's possibly better.

@mbround18 mbround18 added docker Tag if its related to docker enhancement New feature or request github Tag if its related to github labels Feb 22, 2021
@mbround18 mbround18 changed the title Improve docker image build times [Enhancement] Improve docker image build times Feb 22, 2021
@mbround18
Copy link
Owner

Ohh my, that does speed up builds considerably :D

mbround18 added a commit that referenced this issue Feb 23, 2021
mbround18 added a commit that referenced this issue Feb 23, 2021
* Build and cache based on #153

* Try github.ref

* Try           VERSION=

* Cleaned up bash script for stripping version

* Merged envs to be in one call

* Changed workflow

* use workflow with ref
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docker Tag if its related to docker enhancement New feature or request github Tag if its related to github
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants