earthly icon indicating copy to clipboard operation
earthly copied to clipboard

Add a `CONST` Command

Open brandonSc opened this issue 2 years ago • 3 comments

Sometimes we may use ARG with a default value that we treat as a constant. This can be useful for declaring a reusable value at build-time in an Earthfile.

It's not always clear, however, that the ARG is not intended to be overridden with a different value. We may even want to prevent the value from being overridden and causing unexpected behavior.

A CONST command would improve readability in these cases, as well as prevent users from overriding its value.

Here's how it might look in an Earthfile:

FROM alpine
CONST URL=https://example.com

get-1:
  RUN wget "$URL/thing-1"

get-2:
  RUN wget "$URL/thing-2"

brandonSc avatar May 02 '22 19:05 brandonSc

I imagine this would be straight forward to implement, as we would leverage a lot of the infrastructure we already have for ARG

brandonSc avatar May 02 '22 19:05 brandonSc

I imagine the need for that would be way less if https://github.com/earthly/earthly/issues/1575 was implemented.

gpoulin avatar May 20 '22 13:05 gpoulin

It would be nice to also consider how we can use an IMPORT so we can define these CONSTs in a single Earthfile.

alexcb avatar May 10 '24 18:05 alexcb