buildearthly

Is it possible to build a dynamic list of targets with Earthly


I've been considering the Earthly build automation tool as a replacement for Make in my project. I have a mono repo with a root Makefile, that has a target that scans for subfolders with Makefiles, and builds those with make -C some_subfolder.

Looking at the documentation for Eartly, the only way I can see to support those builds is to make a static lists of subfolders, and then build them using the example from the mono repo documentation, like

FROM alpine:3.13

all:
    BUILD ./some_subfolder+all
    BUILD ./another_folder+all

I've been through the rest of the guides, and I can't see any way to make that list of build instructions dynamic, without writing a wrapper script to run Earthly. Has anyone else had this issue and come up with a solution?


Solution

  • In recent versions of Earthly you can use the new FOR command.

    VERSION 0.6
    
    build:
      ...
      FOR dir IN $(ls -d */)
        BUILD "./$dir+build"
      END