Coder Social home page Coder Social logo

Comments (8)

eliottwiener-gridunity avatar eliottwiener-gridunity commented on June 9, 2024 1

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.

idsvandermolen avatar idsvandermolen commented on June 9, 2024

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.

idsvandermolen avatar idsvandermolen commented on June 9, 2024

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.

idsvandermolen avatar idsvandermolen commented on June 9, 2024

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.

idsvandermolen avatar idsvandermolen commented on June 9, 2024

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.

alexcb avatar alexcb commented on June 9, 2024

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.

alexcb avatar alexcb commented on June 9, 2024

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.

alexcb avatar alexcb commented on June 9, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.