Skip to main content

Earthly Arguments And Tags

I wrote about my first experience with Earthly in the ghc-musl Part 2: Earthly blog entry. I have since learned a few more things about it. Argument values are cached even when the default is the output of a command, and there is indeed a way to assign multiple tags to an image.

Arguments

In an Earthfile, I created a DATE argument that is set to the current date (in YYYYMMDD format, in the UTC time zone), to be used in image tags. Layers rebuild whenever any arguments that are in scope change, so I thought that this argument would force the build to not use cache if done on a new day.

ARG DATE=$(date --utc +%Y%m%d)

Unfortunately, the argument value is cached, so this did not work as I had hoped. Rebuilding requires either passing --no-cache to explicitly turn off caching or calculating the date on the command line, as follows.

$ earthly \
  --allow-privileged \
  --build-arg ALPINE_VERSION=3.15 \
  --build-arg DATE=$(date --utc +%Y%m%d)
  +ghc9.2.2

Tags

You use the SAVE IMAGE command to instruct Earthly to save an image when a target is built. I would like to assign more than one tag to an image, and Utku Demir suggested simply putting more than one SAVE IMAGE command. It works!

SAVE IMAGE --push "${IMAGE_NAME}:ghc${GHC_VERSION}-alpine${ALPINE_VERSION}-${DATE}"
SAVE IMAGE --push "${IMAGE_NAME}:ghc${GHC_VERSION}-alpine${ALPINE_VERSION}"
Author

Travis Cardwell

Published

Tags
Related Blog Entries