-
Notifications
You must be signed in to change notification settings - Fork 68
Switch to using tilt-support repo #307
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,66 +1,23 @@ | ||
| # This loads a helper function that isn't part of core Tilt that simplifies restarting the process in the container | ||
| # when files changes. | ||
| load('ext://restart_process', 'docker_build_with_restart') | ||
| if not os.path.exists('../tilt-support'): | ||
| fail('Please clone https://github.com/operator-framework/tilt-support to ../tilt-support') | ||
|
|
||
| # Treat the main binary as a local resource, so we can automatically rebuild it when any of the deps change. This | ||
| # builds it locally, targeting linux, so it can run in a linux container. | ||
| local_resource( | ||
| 'manager_binary', | ||
| cmd=''' | ||
| mkdir -p .tiltbuild/bin | ||
| CGO_ENABLED=0 GOOS=linux go build -o .tiltbuild/bin/manager ./cmd/manager | ||
| ''', | ||
| deps=['api', 'cmd/manager', 'internal', 'pkg', 'go.mod', 'go.sum'] | ||
| ) | ||
| load('../tilt-support/Tiltfile', 'deploy_repo') | ||
|
|
||
| # Configure our image build. If the file in live_update.sync (.tiltbuild/bin/manager) changes, Tilt | ||
| # copies it to the running container and restarts it. | ||
| docker_build_with_restart( | ||
| # This has to match an image in the k8s_yaml we call below, so Tilt knows to use this image for our Deployment, | ||
| # instead of the actual image specified in the yaml. | ||
| ref='quay.io/operator-framework/operator-controller:devel', | ||
| # This is the `docker build` context, and because we're only copying in the binary we've already had Tilt build | ||
| # locally, we set the context to the directory containing the binary. | ||
| context='.tiltbuild/bin', | ||
| # We use a slimmed-down Dockerfile that only has $binary in it. | ||
| dockerfile_contents=''' | ||
| FROM gcr.io/distroless/static:debug | ||
| EXPOSE 8080 | ||
| WORKDIR / | ||
| COPY manager manager | ||
| ''', | ||
| # The set of files Tilt should include in the build. In this case, it's just the binary we built above. | ||
| only='manager', | ||
| # If .tiltbuild/bin/manager changes, Tilt will copy it into the running container and restart the process. | ||
| live_update=[ | ||
| sync('.tiltbuild/bin/manager', '/manager'), | ||
| ], | ||
| # The command to run in the container. | ||
| entrypoint="/manager", | ||
| ) | ||
| config.define_string_list('repos', args=True) | ||
| cfg = config.parse() | ||
| repos = cfg.get('repos', ['operator-controller', 'rukpak', 'catalogd']) | ||
|
|
||
| # Tell Tilt what to deploy by running kustomize and then doing some manipulation to make things work for Tilt. | ||
| objects = decode_yaml_stream(kustomize('config/default')) | ||
| for o in objects: | ||
| # For Tilt's live_update functionality to work, we have to run the container as root. Remove any PSA labels to allow | ||
| # this. | ||
| if o['kind'] == 'Namespace' and 'labels' in o['metadata']: | ||
| labels_to_delete = [label for label in o['metadata']['labels'] if label.startswith('pod-security.kubernetes.io')] | ||
| for label in labels_to_delete: | ||
| o['metadata']['labels'].pop(label) | ||
| repo = { | ||
| 'image': 'quay.io/operator-framework/operator-controller', | ||
| 'yaml': 'config/default', | ||
| 'binaries': { | ||
| 'manager': 'operator-controller-controller-manager', | ||
| }, | ||
| 'starting_debug_port': 30000, | ||
| } | ||
|
|
||
| if o['kind'] != 'Deployment': | ||
| # We only need to modify Deployments, so we can skip this | ||
| continue | ||
|
|
||
| # For Tilt's live_update functionality to work, we have to run the container as root. Otherwise, Tilt won't | ||
| # be able to untar the updated binary in the container's file system (this is how live update | ||
| # works). If there are any securityContexts, remove them. | ||
| if "securityContext" in o['spec']['template']['spec']: | ||
| o['spec']['template']['spec'].pop('securityContext') | ||
| for c in o['spec']['template']['spec']['containers']: | ||
| if "securityContext" in c: | ||
| c.pop('securityContext') | ||
|
|
||
| # Now apply all the yaml | ||
| k8s_yaml(encode_yaml_stream(objects)) | ||
| for r in repos: | ||
| if r == 'operator-controller': | ||
| deploy_repo('operator-controller', repo) | ||
| else: | ||
| include('../{}/Tiltfile'.format(r)) | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm very leery about going outside the repo.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is for local development and iteration. It's pretty standard.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't clone the tilt-support repo. That's something you have to do manually. It's definitely not forcing arbitrary code from the internet on you 😄
An alternative is to consider
tilt-supporta Tilt extension:Both would load the same code
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just said I'm "leery". I haven't seen many (if any?) projects that look outside their repository unless explicitly configured to do so by the user (e.g.
--with-software=/path/to/software). Then again, I'm also leery about pulling random software versions from the 'net (given my corporate security background).That said, if it's just looking for something, then it's not so bad.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, cool. Yeah this is by far the easiest way.