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

HOST bug or expected behavior? #1743

Closed
wataruian opened this issue Mar 11, 2022 · 3 comments · Fixed by #3957
Closed

HOST bug or expected behavior? #1743

wataruian opened this issue Mar 11, 2022 · 3 comments · Fixed by #3957
Assignees

Comments

@wataruian
Copy link

wataruian commented Mar 11, 2022

I've been following the experimental feature to add host in /etc/hosts for the duration of the build (HOST) and found something (bug or expected behavior?):

  1. I can't seem to pass dynamic value to HOST, if I tried passing the ARG it really tries to add ${ARG_NAME} in /etc/hosts, I tried even setting as ENV, still the same. But hardcoding the value is working
  2. SAVE IMAGE does not seem to respect what is in /etc/hosts. So I am unable to push to the local registry, which when you try to do curl in +success-access-host is successful.
VERSION --use-host-command 0.6

FROM alpine:3.14

ARG IP="192.168.1.9"
ARG DOMAIN="mylocalhost.com"

success-set-host:
  HOST mylocalhost.com 192.168.1.9

failed-set-host:
  RUN echo ${DOMAIN}
  RUN echo ${IP}
  HOST ${DOMAIN} ${IP}

success-access-host:
  HOST mylocalhost.com 192.168.1.9
  RUN apk update && apk add curl && curl -GET mylocalhost.com:5000/v2/_catalog

failed-push:
  HOST mylocalhost.com 192.168.1.9
  SAVE IMAGE --insecure --push mylocalhost.com:5000/some-image:1.0

Any , idea how to achieve this?

Thanks!

@dchw
Copy link
Collaborator

dchw commented Mar 11, 2022

Right now, the HOST keyword only accepts static values. It seems reasonable to incorporate this.

Making HOST also be respected by SAVE IMAGE could be more tricky, and requires more thought, as it would require applying the HOST entry at the buildkit layer, not the currently-executing-build-command layer. This may be more difficult to achieve; or require a separate mechanism. One workaround that could work right now is to leverage our buildkit_additional_args config option. Something like this: earthly global.buildkit_additional_args ["--add-host", "yourdomain.com:127.0.0.1"] would allow buildkit to push to a custom hostname.

@vladaionescu
Copy link
Member

vladaionescu commented Mar 11, 2022

For the expansion, it seems that we forgot to call expandArgs on these two: https://github.com/earthly/earthly/blob/main/earthfile2llb/interpreter.go#L1387-L1388. We welcome a contribution if you'd like to add that yourself.

@dchw dchw self-assigned this Mar 11, 2022
@wataruian
Copy link
Author

Looks like this is the one I am needing for the long time (did not even know this existed):
earthly global.buildkit_additional_args ["--add-host", "yourdomain.com:127.0.0.1"]

I am not sure if HOST interfering with buildkit hosts is a wanted/good thing though, if needed it can be easily done with (--add-host - Thanks @dchw).

But HOST being able to accept variables for DOMAIN and IP makes sense.

alexcb added a commit that referenced this issue Apr 2, 2024
)

fixes #1743

---------

Co-authored-by: Alex Couture-Beil <alex@mofo.ca>
Co-authored-by: Alex Couture-Beil <alex@earthly.dev>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

3 participants