earthly / lib

Mozilla Public License 2.0
7 stars 11 forks source link

add SET_CACHE_MOUNTS_ENV #39

Closed idelvall closed 8 months ago

idelvall commented 8 months ago

Adds

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
joepio commented 8 months ago

Works for me!

joepio commented 7 months ago

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?

https://github.com/atomicdata-dev/atomic-server/issues/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 commented 7 months ago

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 commented 7 months ago

@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 commented 7 months ago

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 commented 7 months ago

Ah yes, thanks!

One step further :)