Tiltfile 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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. # Split the YAML into CRDs and other resources
  20. objects = decode_yaml_stream(read_file('bin/deploy/manifests/external-secrets.yaml'))
  21. crds = []
  22. other_resources = []
  23. for o in objects:
  24. if o.get('kind') == 'CustomResourceDefinition':
  25. crds.append(o)
  26. else:
  27. other_resources.append(o)
  28. # Process deployments for development
  29. for o in other_resources:
  30. if o.get('kind') == 'Deployment' and o.get('metadata').get('name') in ['external-secrets-cert-controller', 'external-secrets', 'external-secrets-webhook']:
  31. o['spec']['template']['spec']['containers'][0]['securityContext'] = {'runAsNonRoot': False, 'readOnlyRootFilesystem': False}
  32. o['spec']['template']['spec']['containers'][0]['imagePullPolicy'] = 'Always'
  33. if settings.get('debug').get('enabled') and o.get('metadata').get('name') == 'external-secrets':
  34. o['spec']['template']['spec']['containers'][0]['ports'] = [{'containerPort': 30000}]
  35. # Create the directory
  36. local('mkdir -p .tilt-tmp')
  37. # Apply CRDs with server-side apply (handles large CRDs)
  38. if crds:
  39. crd_yaml = encode_yaml_stream(crds)
  40. local('cat > .tilt-tmp/external-secrets-crds.yaml', stdin=crd_yaml)
  41. local_resource(
  42. 'apply-crds',
  43. 'kubectl apply --server-side -f .tilt-tmp/external-secrets-crds.yaml',
  44. deps=['bin/deploy/manifests/external-secrets.yaml']
  45. )
  46. # Use regular k8s_yaml for deployments (Tilt will handle image substitution)
  47. if other_resources:
  48. deployments_yaml = encode_yaml_stream(other_resources)
  49. local('cat > .tilt-tmp/external-secrets-deployments.yaml', stdin=deployments_yaml)
  50. k8s_yaml('.tilt-tmp/external-secrets-deployments.yaml')
  51. load('ext://restart_process', 'docker_build_with_restart')
  52. # enable hot reloading by doing the following:
  53. # - locally build the whole project
  54. # - create a docker imagine using tilt's hot-swap wrapper
  55. # - push that container to the local tilt registry
  56. # Once done, rebuilding now should be a lot faster since only the relevant
  57. # binary is rebuilt and the hot swat wrapper takes care of the rest.
  58. gcflags = ''
  59. if settings.get('debug').get('enabled'):
  60. gcflags = '-N -l'
  61. local_resource(
  62. 'external-secret-binary',
  63. "CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -gcflags '{gcflags}' -v -o bin/external-secrets ./".format(gcflags=gcflags),
  64. deps = [
  65. "main.go",
  66. "go.mod",
  67. "go.sum",
  68. "apis",
  69. "cmd",
  70. "pkg",
  71. ],
  72. )
  73. # Build the docker image for our controller. We use a specific Dockerfile
  74. # since tilt can't run on a scratch container.
  75. # `only` here is important, otherwise, the container will get updated
  76. # on _any_ file change. We only want to monitor the binary.
  77. # If debugging is enabled, we switch to a different docker file using
  78. # the delve port.
  79. entrypoint = ['/external-secrets']
  80. dockerfile = 'tilt.dockerfile'
  81. if settings.get('debug').get('enabled'):
  82. k8s_resource('external-secrets', port_forwards=[
  83. port_forward(30000, 30000, 'debugger'),
  84. ])
  85. entrypoint = ['/dlv', '--listen=:30000', '--api-version=2', '--continue=true', '--accept-multiclient=true', '--headless=true', 'exec', '/external-secrets', '--']
  86. dockerfile = 'tilt.debug.dockerfile'
  87. docker_build_with_restart(
  88. 'oci.external-secrets.io/external-secrets/external-secrets',
  89. '.',
  90. dockerfile = dockerfile,
  91. entrypoint = entrypoint,
  92. only=[
  93. './bin',
  94. ],
  95. live_update = [
  96. sync('./bin/external-secrets', '/external-secrets'),
  97. ],
  98. )