Konubinix' opinionated web of thoughts

Earthly

Fleeting

beware that save artifact is not robust at all

behave like –if-exists sometimes

this won’t fail

test:
    FROM alpine
    SAVE ARTIFACT nothing

But it will correctly save the artifact if it exists

does not undertand absolute path when using –if-exists, WORKDIR

https://github.com/earthly/earthly/issues/2014

When using –if-exists, save artifact interpret the path as relative, /a/b/c becomes ./a/b/c. This messes up with WORKDIR.

This does not save the file

VERSION 0.8

test:
    FROM alpine
    WORKDIR /app
    RUN echo foo > /app/something
    SAVE ARTIFACT --if-exists /app/something AS LOCAL something

While this does

VERSION 0.8

test:
    FROM alpine
    RUN mkdir /app
    RUN echo foo > /app/something
    SAVE ARTIFACT --if-exists /app/something AS LOCAL something

And this as well

VERSION 0.8

test:
    FROM alpine
    WORKDIR /app
    RUN echo foo > /app/something
    SAVE ARTIFACT --if-exists /app/../something AS LOCAL something

Use the pattern IF + SAVE ARTIFACT, to be sure.

#+BEGIN_SRC earthfile VERSION 0.8

test: FROM alpine WORKDIR /app RUN echo foo > /app/something IF test -e “/app/something” SAVE ARTIFACT /app/something AS LOCAL something END #+END_ARC

connecting to a docker registry from within

Not yet, but planned and discussed in https://github.com/earthly/earthly/issues/1722

try finally save artifact does not work well

If we want to save a directory, it won’t work -> https://github.com/earthly/earthly/issues/2817

We have to use a workaround like https://github.com/earthly/earthly/issues/2817#issuecomment-1536766279 to actually save a file

BUT…

  1. this is not to be copy pasted as-is for we also want to save the artifact in case of success,
  2. the file size is limited -> https://github.com/earthly/earthly/issues/2452

So far, the best I can think of is to

  1. allow the failing test to pass,
  2. save its exit code as an artifact,
  3. add a check in the command that runs earthly about the exit code,

This is an example of this workaround.

mytest:
  ...
  RUN --no-cache mycommand ; echo $? > res.txt
  IF test "$(cat res.txt)" != "0"
      # to undertand this better -> https://konubinix.eu/braindump/posts/56c711e5-6d29-4b9d-b630-f75c92800c61/?title=earthly_try_finally_save_artifact_does_not_work_well
      RUN echo "$(tput setaf 1)BEWARE THAT THE TEST FAILED! DON'T BE FOOLED BY FACT EARTHLY WILL RETURN IN GREEN!"
  END
  SAVE ARTIFACT --if-exists somewantedartifact AS LOCAL somewantedartifact
  SAVE ARTIFACT res.txt AS LOCAL res.txt
runtest() {
    earthly +mytest && return "$(cat res.txt)"
}
runtest

caching

disable layer caching is to use the RUN –push flag. This flag is useful when you want to perform an operation with external effects (e.g. deploying to production). By default Earthly does not run –push commands unless the –push flag is also specified when invoking Earthly itself (earthly –push +my-target). RUN –push commands are never cached.

https://docs.earthly.dev/docs/caching/caching-in-earthfiles

cache bust

wait

Notes pointant ici