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

add SET_CACHE_MOUNTS_ENV #39

Merged
merged 7 commits into from
Dec 21, 2023
Merged

add SET_CACHE_MOUNTS_ENV #39

merged 7 commits into from
Dec 21, 2023

Conversation

idelvall
Copy link
Member

@idelvall idelvall commented Dec 18, 2023

Adds

  • +SET_CACHE_MOUNTS_ENV: that sets two entries in the environment with the code for the cache mounts.
  • +COPY_OUTPUT: to copy files from the the target mount cache to the image layers

This new approach gives more flexibility, for example to run within a WITH DOCKER clause:

Example:

build:
  ...
  DO rust+SET_CACHE_MOUNTS_ENV
  WITH DOCKER
    RUN --mount=$EARTHLY_RUST_CARGO_HOME_CACHE --mount=$EARTHLY_RUST_TARGET_CACHE  cross build --target $TARGET --release
  END
 

@idelvall idelvall mentioned this pull request Dec 18, 2023
@joepio
Copy link

joepio commented Dec 18, 2023

Works for me!

rust/Earthfile Show resolved Hide resolved
rust/Earthfile Show resolved Hide resolved
rust/Earthfile Outdated Show resolved Hide resolved
@idelvall idelvall marked this pull request as ready for review December 19, 2023 16:13
@idelvall idelvall requested a review from a team as a code owner December 19, 2023 16:13
rust/Earthfile Outdated Show resolved Hide resolved
@idelvall idelvall changed the title add GET_RUST_CACHE_MOUNTS add SET_CACHE_MOUNTS_ENV Dec 21, 2023
rust/Earthfile Outdated Show resolved Hide resolved
rust/README.md Outdated Show resolved Hide resolved
rust/Earthfile Outdated Show resolved Hide resolved
idelvall and others added 3 commits December 21, 2023 17:57
@idelvall idelvall merged commit 52e8c8a into main Dec 21, 2023
3 checks passed
@idelvall idelvall deleted the nacho/GET_RUST_CACHE_MOUNTS branch December 21, 2023 17:20
@idelvall idelvall mentioned this pull request Dec 21, 2023
@joepio
Copy link

joepio commented Jan 15, 2024

I noticed I'm no longer able to use GET_RUST_CACHE_MOUNTS. I though maybe it was renamed to SET_CACHE_MOUNTS_ENV, so I updated my earthly file (see below), but that also does not work. It does not seem to create an artifact.

Maybe I'm missing something?

atomicdata-dev/atomic-server#805

cross-build:
  FROM +source
  ARG --required TARGET
  DO rust+SET_CACHE_MOUNTS_ENV
  WITH DOCKER
    RUN --mount=$EARTHLY_RUST_CARGO_HOME_CACHE --mount=$EARTHLY_RUST_TARGET_CACHE  cross build --target $TARGET --release
  END
  SAVE ARTIFACT ./target/$TARGET/release/atomic-server AS LOCAL artifact/bin/atomic-server-$TARGET

@idelvall
Copy link
Member Author

idelvall commented Jan 15, 2024

Hi @joepio, given that target folder is within the mount cache, so you need to copy the output files first to the target layers, so it can be retrieved with SAVE ARTIFACT later on.
You can use +COPY_OUPUT target for that purpose: https://github.com/earthly/lib/blob/main/rust/README.md#copy_output

@joepio
Copy link

joepio commented Jan 18, 2024

@idelvall I can't get rust+COPY_OUTPUT to actually copy anything.

Even with DO rust+COPY_OUTPUT --output="*" my ./target directory seems completely empty.

Am I missing something?

cross-build:
  FROM +source
  ARG --required TARGET
  DO rust+SET_CACHE_MOUNTS_ENV
  WITH DOCKER
    RUN --mount=$EARTHLY_RUST_CARGO_HOME_CACHE --mount=$EARTHLY_RUST_TARGET_CACHE  cross build --target $TARGET --release
  END
  DO rust+COPY_OUTPUT --output="*"
  RUN ./target/$TARGET/release/atomic-server --version
  SAVE ARTIFACT ./target/$TARGET/release/atomic-server AS LOCAL artifact/bin/atomic-server-$TARGET

logs: https://cloud.earthly.dev/builds/2227c1db-854b-4b3a-a3d0-ca012c0a9873

@idelvall
Copy link
Member Author

idelvall commented Jan 18, 2024

That argument is actually a regexp @joepio.
Try starting with --output=".*" and then making it more specific, so only the files of your interest are copied

@joepio
Copy link

joepio commented Jan 18, 2024

Ah yes, thanks!

One step further :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

4 participants