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.
kallisti05
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)
eliott.wiener
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`.
sweaver
something like
COPY $path .```
and then
`earthly ./sub/directory/path+target-name --path="../../"` or something
sweaver
I think you could pass the path in as an ARG
to the target and then adjust your logic accordingly
kallisti05
eek. ok. Yeah... then this won't work. Docker lets you adjust the context path.. i guess that's not a thing in earthly?
sweaver
Any paths within an Earthfile are gonna be relative from the folder the Earthfile is in
kallisti05
./3/earthly+code | cached --> COPY ../.. .
kallisti05
./3/earthly+code | cached --> COPY ../../ .
kallisti05
<@U063CKQKWHF> hm. That's pretty close.. however it's having trouble finding the sources in the working directory.
sweaver
You can build a target from an earthfile in a subdirectory by running earthly ./sub/directory/path+target-name
kallisti05
(also, I kinda hate doing COPY ../../ . and assuming you're in the subpath)