Comments (8)
I believe this is the expected behavior.
Here is where the docs explain this:
https://docs.earthly.dev/docs/earthfile#save-image
As of VERSION 0.6, images are only saved if they are connected to the initial target through a chain of BUILD commands.
https://docs.earthly.dev/docs/earthfile#save-artifact
As of VERSION 0.6, local artifacts are only saved if they are connected to the initial target through a chain of BUILD commands.
So the explanation is that BUILD
will cause images and artifacts to be saved in the sub-target, whereas FROM
will not. In other words, only BUILD
forms links of the "chain".
I ran into this same point of confusion not too long ago. I also had assumed that a FROM
would lead to images and artifacts being saved. I find the way this works to be a bit counter-intuitive, although I'm guessing there is a good reason for it.
from earthly.
Perhaps. Note that the url linked in the docs "if they are connected to the initial target through a chain of BUILD commands" is broken and apparently needs to point at the section in the BUILD command.
I'll read that section and try to figure out if it makes sense. However, at first glance as "Test 2" shows, just adding another intermediate target (tests
) changes the behaviour in (IMO) unexpected ways
from earthly.
I think this section in FROM probably makes it clearer:
The FROM command does not mark any saved images or artifacts of the referenced target for output, nor does it mark any push commands of the referenced target for pushing. For that, please use BUILD.
Though the examples there still use FROM
and SAVE ARTIFACT
in on target, suggesting it still would work correctly.
from earthly.
Actually the docs still don't make it clear to me how to adjust the tests described above to make it work and have both outputs. What I expect is to setup a chain of dependencies and (just like using a Makefile
) when one of the targets inputs (either a dependent target or input from COPY
) change, the corresponding outputs would be re-generated.
from earthly.
Changing the Earthfile to this seems to work:
VERSION 0.8
docker:
FROM ubuntu:22.04
SAVE IMAGE earthly-test:latest
build:
BUILD +docker
FROM +docker
COPY --dir input ./
SAVE ARTIFACT input AS LOCAL output
tests:
BUILD +build
all:
BUILD +tests
Which generates all outputs when invoking targets build
,tests
and all
. Though it is not really clear to me if this is the way one should implement it. First I tried to have only a BUILD +docker
in build
target, but then you get this error:
copy classical: the first command has to be FROM, FROM DOCKERFILE, LOCALLY, ARG, BUILD or IMPORT
from earthly.
Note that the url linked in the docs "if they are connected to the initial target through a chain of BUILD commands" is broken and apparently needs to point at the section in the BUILD command.
I had a look to see if this could be fixed, but unfortunately the anchor has disappeared. The docs are hosted via gitbook, which makes it difficult to fix these sorts of issues which come from bugs (or feature changes) in gitbook.
from earthly.
Though the examples there still use FROM and SAVE ARTIFACT in on target, suggesting it still would work correctly.
The SAVE ARTIFACT
is required here to allow for a COPY
to reference it; Note that SAVE ARTIFACT <path>
is different from SAVE ARTIFACT <PATH> AS LOCAL <output>
. It's only the AS LOCAL <output>
portion that requires chaining of BUILD commands.
from earthly.
Though it is not really clear to me if this is the way one should implement it
build:
BUILD +docker
FROM +docker
is how it's intended to be used. The BUILD +docker
occurs asyncronously and doesn't affect the target where it is defined.
If you really want to get into the weeds, you can also create a function to do both, e.g.
VERSION 0.8
BUILD_AND_FROM:
FUNCTION
ARG target
BUILD --pass-args $target
FROM --pass-args $target
docker:
FROM ubuntu:22.04
SAVE IMAGE earthly-test:latest
build:
DO +BUILD_AND_FROM --target=+docker
COPY --dir input ./
SAVE ARTIFACT input AS LOCAL output
tests:
BUILD +build
all:
BUILD +tests
from earthly.
Related Issues (20)
- how can i inspect every stage cost time
- `WITH DOCKER --cache-id` does not expand the `--cache-id` value HOT 7
- Cache with higher precision timestamps HOT 1
- `RUN --raw-output` doesn't work `WITH DOCKER` HOT 1
- less verbose `failed to parse key scan "this-is-a-bad-entry": invalid keyscan` errors
- Create matrix builds from CLI arguments HOT 1
- `RUN --interactive` triggers HTTP 500 when used `WITH DOCKER --load` HOT 1
- Can I `COPY` artifacts from a matrix build? HOT 2
- `--pass-args` busts cache unexpected HOT 8
- DIND networking dont work when using non standard CNI_MTU
- `TRY` / `FINALLY` when used with `WITH DOCKER` produces verbose output HOT 2
- Earthly doesn't respect a host defined in a local `/etc/hosts` file when doing SAVE IMAGE HOT 2
- ticktock cache issue HOT 3
- `TRY` / `FINALLY` doesn't work under `WITH DOCKER`
- error message for WITH DOCKER (unlazy force execution) could be improved
- self-hosted registry reachable from host machine but dns look up failed inside earthly HOT 2
- `+base` target should only be run when necessary
- Running TestContainers in Earthly fails to find Docker Daemon HOT 4
- `docker network create --internal` can fail with a ` network with name ... already exists` error when `WITH DOCKER --cache-id=` is used HOT 2
- BuildKit: Snapshot directory does not exist HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from earthly.