|
| 1 | +# -*- mode: Python -*- |
| 2 | + |
| 3 | +kubectl_cmd = "kubectl" |
| 4 | + |
| 5 | +# verify kubectl command exists |
| 6 | +if str(local("command -v " + kubectl_cmd + " || true", quiet = True)) == "": |
| 7 | + fail("Required command '" + kubectl_cmd + "' not found in PATH") |
| 8 | + |
| 9 | +# Use kustomize to build the install yaml files |
| 10 | +install = kustomize('config/default') |
| 11 | + |
| 12 | +# Update the root security group. Tilt requires root access to update the |
| 13 | +# running process. |
| 14 | +objects = decode_yaml_stream(install) |
| 15 | +for o in objects: |
| 16 | + if o.get('kind') == 'Deployment' and o.get('metadata').get('name') == 'git-sync-controller': |
| 17 | + o['spec']['template']['spec']['securityContext']['runAsNonRoot'] = False |
| 18 | + break |
| 19 | + |
| 20 | +updated_install = encode_yaml_stream(objects) |
| 21 | + |
| 22 | +# Apply the updated yaml to the cluster. |
| 23 | +# Allow duplicates so the e2e test can include this tilt file with other tilt files |
| 24 | +# setting up the same namespace. |
| 25 | +k8s_yaml(updated_install, allow_duplicates = True) |
| 26 | + |
| 27 | +load('ext://restart_process', 'docker_build_with_restart') |
| 28 | + |
| 29 | +# enable hot reloading by doing the following: |
| 30 | +# - locally build the whole project |
| 31 | +# - create a docker imagine using tilt's hot-swap wrapper |
| 32 | +# - push that container to the local tilt registry |
| 33 | +# Once done, rebuilding now should be a lot faster since only the relevant |
| 34 | +# binary is rebuilt and the hot swat wrapper takes care of the rest. |
| 35 | +local_resource( |
| 36 | + 'git-sync-controller-binary', |
| 37 | + 'CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o bin/manager ./', |
| 38 | + deps = [ |
| 39 | + "main.go", |
| 40 | + "go.mod", |
| 41 | + "go.sum", |
| 42 | + "api", |
| 43 | + "controllers", |
| 44 | + "pkg", |
| 45 | + ], |
| 46 | +) |
| 47 | + |
| 48 | +# Build the docker image for our controller. We use a specific Dockerfile |
| 49 | +# since tilt can't run on a scratch container. |
| 50 | +# `only` here is important, otherwise, the container will get updated |
| 51 | +# on _any_ file change. We only want to monitor the binary. |
| 52 | +# If debugging is enabled, we switch to a different docker file using |
| 53 | +# the delve port. |
| 54 | +entrypoint = ['/manager'] |
| 55 | +dockerfile = 'tilt.dockerfile' |
| 56 | +docker_build_with_restart( |
| 57 | + 'ghcr.io/open-component-model/git-sync-controller', |
| 58 | + '.', |
| 59 | + dockerfile = dockerfile, |
| 60 | + entrypoint = entrypoint, |
| 61 | + only=[ |
| 62 | + './bin', |
| 63 | + ], |
| 64 | + live_update = [ |
| 65 | + sync('./bin/manager', '/manager'), |
| 66 | + ], |
| 67 | +) |
0 commit comments