Tiltfile 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. # -*- mode: Python -*-
  2. kubectl_cmd = "kubectl"
  3. # verify kubectl command exists
  4. if str(local("command -v " + kubectl_cmd + " || true", quiet = True)) == "":
  5. fail("Required command '" + kubectl_cmd + "' not found in PATH")
  6. # set defaults
  7. settings = {
  8. "debug": {
  9. "enabled": False,
  10. },
  11. }
  12. # merge default settings with user defined settings
  13. tilt_file = "./tilt-settings.yaml" if os.path.exists("./tilt-settings.yaml") else "./tilt-settings.json"
  14. settings.update(read_yaml(
  15. tilt_file,
  16. default = {},
  17. ))
  18. # set up the development environment
  19. # Update the root security group. Tilt requires root access to update the
  20. # running process.
  21. objects = decode_yaml_stream(read_file('bin/deploy/manifests/external-secrets.yaml'))
  22. for o in objects:
  23. if o.get('kind') == 'Deployment' and o.get('metadata').get('name') in ['external-secrets-cert-controller', 'external-secrets', 'external-secrets-webhook']:
  24. o['spec']['template']['spec']['securityContext'] = {'runAsNonRoot': False}
  25. o['spec']['template']['spec']['imagePullPolicy'] = 'Always'
  26. if settings.get('debug').get('enabled') and o.get('metadata').get('name') == 'external-secrets':
  27. o['spec']['template']['spec']['containers'][0]['ports'] = [{'containerPort': 30000}]
  28. updated_install = encode_yaml_stream(objects)
  29. # Apply the updated yaml to the cluster.
  30. k8s_yaml(updated_install, allow_duplicates = True)
  31. load('ext://restart_process', 'docker_build_with_restart')
  32. # enable hot reloading by doing the following:
  33. # - locally build the whole project
  34. # - create a docker imagine using tilt's hot-swap wrapper
  35. # - push that container to the local tilt registry
  36. # Once done, rebuilding now should be a lot faster since only the relevant
  37. # binary is rebuilt and the hot swat wrapper takes care of the rest.
  38. gcflags = ''
  39. if settings.get('debug').get('enabled'):
  40. gcflags = '-N -l'
  41. local_resource(
  42. 'external-secret-binary',
  43. "CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -gcflags '{gcflags}' -v -o bin/external-secrets ./".format(gcflags=gcflags),
  44. deps = [
  45. "main.go",
  46. "go.mod",
  47. "go.sum",
  48. "apis",
  49. "cmd",
  50. "pkg",
  51. ],
  52. )
  53. # Build the docker image for our controller. We use a specific Dockerfile
  54. # since tilt can't run on a scratch container.
  55. # `only` here is important, otherwise, the container will get updated
  56. # on _any_ file change. We only want to monitor the binary.
  57. # If debugging is enabled, we switch to a different docker file using
  58. # the delve port.
  59. entrypoint = ['/external-secrets']
  60. dockerfile = 'tilt.dockerfile'
  61. if settings.get('debug').get('enabled'):
  62. k8s_resource('external-secrets', port_forwards=[
  63. port_forward(30000, 30000, 'debugger'),
  64. ])
  65. entrypoint = ['/dlv', '--listen=:30000', '--api-version=2', '--continue=true', '--accept-multiclient=true', '--headless=true', 'exec', '/external-secrets', '--']
  66. dockerfile = 'tilt.debug.dockerfile'
  67. docker_build_with_restart(
  68. 'ghcr.io/external-secrets/external-secrets',
  69. '.',
  70. dockerfile = dockerfile,
  71. entrypoint = entrypoint,
  72. only=[
  73. './bin',
  74. ],
  75. live_update = [
  76. sync('./bin/external-secrets', '/external-secrets'),
  77. ],
  78. )