Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 19 additions & 62 deletions Tiltfile
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'):
Copy link
Contributor

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.

Copy link
Member Author

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.

Copy link
Member Author

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-support a Tilt extension:

v1alpha1.extension_repo(name='tilt-support', url='https://github.com/operator-framework/tilt-support')
v1alpha1.extension(name='tilt-support', repo_name='tilt-support', repo_path='.')
load('ext://tilt-support', 'deploy_repo')

Both would load the same code

Copy link
Contributor

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.

Copy link
Member Author

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.

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))