E

Earthly Earthfile Location Inquiry

Summary

The user is asking if Earthly allows for alternative locations for Earthfiles, similar to how Makefiles can be referenced from subdirectories. They want to keep the Earthfile in the root directory but are facing issues with the COPY command, which relies on the current path and has relative paths based on the Earthfile's location. The user notes that while Docker allows for adjusting the context path, this doesn't seem possible in Earthly. They suggest passing the path as an argument to the target to modify the logic. The user concludes that it is not possible to COPY files from outside the build context directory.

Status
open
Tags
  • Earthfile
  • Earthly
  • Earthfile
  • COPY Command
  • Earthly
  • Docker
Source
#earthly
    k

    kallisti05

    9/11/2024

    One more silly question. Does earthly support alternative locations for Earthfiles? (I'm thinking kinda like make -C subdir/ when a Makefile is in subdir. I'd love to put the Earthfile in our root but getting push back to a subdir until it's more central. (also, I kinda hate doing COPY ../../ . and assuming you're in the subpath)

    e

    eliott.wiener

    9/12/2024

    If you are saying you'd like to have a directory tree like :

    ├── build-stuff
    │   └── Earthfile
    └── some-source-file```
    ...and be able to have the Earthfile `COPY` the file `some-source-file` into its build context, then I do not think that is possible. You will not be able to `COPY` anything outside of `build-stuff`.
    
    s

    sweaver

    9/11/2024

    something like

    COPY $path .```
    and then
    `earthly ./sub/directory/path+target-name --path="../../"` or something
    
    s

    sweaver

    9/11/2024

    I think you could pass the path in as an ARG to the target and then adjust your logic accordingly

    k

    kallisti05

    9/11/2024

    eek. ok. Yeah... then this won't work. Docker lets you adjust the context path.. i guess that's not a thing in earthly?

    s

    sweaver

    9/11/2024

    Any paths within an Earthfile are gonna be relative from the folder the Earthfile is in

    k

    kallisti05

    9/11/2024

    ./3/earthly+code | cached --> COPY ../.. .

    k

    kallisti05

    9/11/2024

    ./3/earthly+code | cached --> COPY ../../ .

    k

    kallisti05

    9/11/2024

    <@U063CKQKWHF> hm. That's pretty close.. however it's having trouble finding the sources in the working directory.

    s

    sweaver

    9/11/2024

    You can build a target from an earthfile in a subdirectory by running earthly ./sub/directory/path+target-name

    k

    kallisti05

    9/11/2024

    (also, I kinda hate doing COPY ../../ . and assuming you're in the subpath)