Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is it possible to share variables (of LET, for instance)? #4105

Open
denizenging opened this issue May 10, 2024 · 4 comments
Open

Is it possible to share variables (of LET, for instance)? #4105

denizenging opened this issue May 10, 2024 · 4 comments
Labels
type:question Not an issue. Just a question.

Comments

@denizenging
Copy link

Question

I'd like to share alpine versions between two Earthfiles. Can't I use a central, third Earthfile to do that? If so, how do I do it?

@denizenging denizenging added the type:question Not an issue. Just a question. label May 10, 2024
@alexcb
Copy link
Collaborator

alexcb commented May 10, 2024

Have you looked into the IMPORT command?

You can have a base target like:

VERSION 0.8

common-alpine-target:
  FROM alpine:3.18
  RUN echo "this should be available everywhere" > /common-data

Then import a parent Earthfile in some child directory like:

VERSION 0.8

IMPORT .. AS root

child:
   FROM root+common-alpine-target
   RUN cat /common-data

then you can treat common-alpine-target as a golden base image which everything should depend on.

@alexcb
Copy link
Collaborator

alexcb commented May 10, 2024

unfortunately IMPORT doesn't allow you to import any ARG or LET definitions; but I could see this being a nice addition (especially if we add a CONST one day #1863)

@denizenging
Copy link
Author

unfortunately IMPORT doesn't allow you to import any ARG or LET definitions; but I could see this being a nice addition (especially if we add a CONST one day #1863)

I actually figured out that I could use FROM with targets, but having a way to share variables could be useful for someone else. I'm currently satisfied with my solution, but maybe I should keep this issue open for the ones who might benefit from this?

@alexcb
Copy link
Collaborator

alexcb commented May 10, 2024

it's also possible to inherit a ENV value from a different target (where as ARG values are not inherited)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:question Not an issue. Just a question.
Projects
Status: No status
Development

No branches or pull requests

2 participants