Tiltfile 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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']['containers'][0]['securityContext'] = {'runAsNonRoot': False, 'readOnlyRootFilesystem': False}
  25. o['spec']['template']['spec']['containers'][0]['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. # Create the directory and write the file
  31. local('mkdir -p .tilt-tmp')
  32. local('cat > .tilt-tmp/external-secrets-modified.yaml', stdin=updated_install)
  33. # Now use k8s_custom_deploy to apply it
  34. k8s_custom_deploy(
  35. 'external-secrets',
  36. apply_cmd='kubectl apply --server-side -f .tilt-tmp/external-secrets-modified.yaml -o yaml',
  37. delete_cmd='kubectl delete --ignore-not-found -f .tilt-tmp/external-secrets-modified.yaml',
  38. deps=['bin/deploy/manifests/external-secrets.yaml'],
  39. image_deps=['oci.external-secrets.io/external-secrets/external-secrets']
  40. )
  41. load('ext://restart_process', 'docker_build_with_restart')
  42. # enable hot reloading by doing the following:
  43. # - locally build the whole project
  44. # - create a docker imagine using tilt's hot-swap wrapper
  45. # - push that container to the local tilt registry
  46. # Once done, rebuilding now should be a lot faster since only the relevant
  47. # binary is rebuilt and the hot swat wrapper takes care of the rest.
  48. gcflags = ''
  49. if settings.get('debug').get('enabled'):
  50. gcflags = '-N -l'
  51. local_resource(
  52. 'external-secret-binary',
  53. "CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -gcflags '{gcflags}' -v -o bin/external-secrets ./".format(gcflags=gcflags),
  54. deps = [
  55. "main.go",
  56. "go.mod",
  57. "go.sum",
  58. "apis",
  59. "cmd",
  60. "pkg",
  61. ],
  62. )
  63. # Build the docker image for our controller. We use a specific Dockerfile
  64. # since tilt can't run on a scratch container.
  65. # `only` here is important, otherwise, the container will get updated
  66. # on _any_ file change. We only want to monitor the binary.
  67. # If debugging is enabled, we switch to a different docker file using
  68. # the delve port.
  69. entrypoint = ['/external-secrets']
  70. dockerfile = 'tilt.dockerfile'
  71. if settings.get('debug').get('enabled'):
  72. k8s_resource('external-secrets', port_forwards=[
  73. port_forward(30000, 30000, 'debugger'),
  74. ])
  75. entrypoint = ['/dlv', '--listen=:30000', '--api-version=2', '--continue=true', '--accept-multiclient=true', '--headless=true', 'exec', '/external-secrets', '--']
  76. dockerfile = 'tilt.debug.dockerfile'
  77. docker_build_with_restart(
  78. 'oci.external-secrets.io/external-secrets/external-secrets',
  79. '.',
  80. dockerfile = dockerfile,
  81. entrypoint = entrypoint,
  82. only=[
  83. './bin',
  84. ],
  85. live_update = [
  86. sync('./bin/external-secrets', '/external-secrets'),
  87. ],
  88. )