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

Add image_deps support to kubectl_build #389

Open
milas opened this issue Apr 21, 2022 · 3 comments
Open

Add image_deps support to kubectl_build #389

milas opened this issue Apr 21, 2022 · 3 comments
Labels
enhancement New feature or request

Comments

@milas
Copy link
Contributor

milas commented Apr 21, 2022

Kristinn asked in Slack:

Has anyone gotten kubectl_build to work with dependencies on other images expressed in the tiltfile?

We do support image_deps in the underlying custom_build now, but it hasn't been wired up for this extension.

Unfortunately, it's not as simple as passing through the argument, as the actual build command needs to understand how to consume the references that Tilt passes as TILT_IMAGE_i environment variables (where i is the index in image_deps arg).

Proposal

In practice, I can't see any way you'd use an image dependency (with the kubectl_build extension specifically) other than in an ARG.

I think a new parameter to kubectl_build could handle this -> image_deps_to_build_args: Dict[str, str] = None

kubectl_build('my-base-image', ...)

kubectl_build(
  'my-app-image',
  ...,
  image_deps_to_build_args={
    'my-base-image': 'BASE_IMAGE'
  }
)
ARG BASE_IMAGE
FROM BASE_IMAGE

...

Then in kubectl_build:

i = 0
for build_arg in image-deps_to_build_args.values():
  command += ['--build-arg', '{build_arg}=TILT_IMAGE_{i}'.format(build_arg=build_arg, i=i)]
  i += 1

custom_build(..., image_deps=[k for k in image_deps_to_build_args])

I'm slightly conflicted about using a dict given the ordering importance, but it's much more ergonomic than a list of tuples, and from Starlark dict reference:

Dictionaries are iterable; iteration yields the sequence of keys in insertion order

@milas milas added the enhancement New feature or request label Apr 21, 2022
@milas
Copy link
Contributor Author

milas commented Apr 21, 2022

@nicks wdyt about this proposal? I both want to make sure I didn't miss any subtlety around image_deps wrt custom_build and sanity check that this is a reasonable approach for custom build extensions

@nicks
Copy link
Member

nicks commented Apr 25, 2022

fwiw, I did this as two lists in helm_resource for a few reasons

i definitely could make the case either way, but would feel weird if half the apis used the list approach and half used dicts

@milas
Copy link
Contributor Author

milas commented Apr 25, 2022

That makes sense! Having image_keys be build arg key names is straightforward enough

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants