libre.sh/.tilt/kubebuilder.Tiltfile

63 lines
2 KiB
Text

kustomization='''resources:
- ../config/default
patches:
- target:
kind: Deployment
patch: |-
- op: remove
path: /spec/template/spec/securityContext
- op: add
path: /metadata/labels/ignore-apply
value: "true"'''
def kubebuilder(PATH):
def path(relpath):
return os.path.join(PATH, relpath)
# DIRNAME = os.path.basename(PATH)
DIRNAME = "operator"
def name(value):
return "["+DIRNAME+"] "+value
def yaml_cmd():
return "kustomize build "+path(".tilt_bin")
def yaml():
data = local(yaml_cmd())
keep,err = filter_yaml(data, kind='deployment')
return keep
def build_cmd():
main = "main.go"
if os.path.exists(path('cmd/main.go')):
main = "cmd/main.go"
return "cd %s && make manifests generate fmt vet && CGO_ENABLED=0 go build -o .tilt_bin/manager %s" % (PATH, main)
local("mkdir -p %s && echo '%s' > %s" % (path(".tilt_bin"), kustomization, path(".tilt_bin/kustomization.yaml")))
local_resource(name('YAML'), yaml_cmd()+" | kubectl apply -l ignore-apply!=true -f -", deps=[path("config")], labels=[DIRNAME], allow_parallel=True)
deps = [path('controllers'), path('main.go'), path('api'), path('cmd'), path('internal')]
local_resource(name('Build'), build_cmd(), deps=deps, ignore=[path('**/zz_generated.deepcopy.go')], labels=[DIRNAME], allow_parallel=True)
k8s_yaml(yaml())
k8s_resource(workload='lsh-'+DIRNAME, resource_deps=["registry", name("YAML"), name("Build")], labels=[DIRNAME])
CONTAINERFILE = read_file(path('Dockerfile.tilt'),'''FROM gcr.io/distroless/static:nonroot
WORKDIR /
COPY .tilt_bin/manager /
CMD ["/manager"]
''')
custom_build(
ref="registry.libre.sh/"+DIRNAME+":latest",
command=(
"set -ex\n" +
"echo \"%s\" | podman build -t $EXPECTED_REF -f - %s\n" +
"podman push --format=docker --tls-verify=false $EXPECTED_REF\n"
) % (CONTAINERFILE, PATH),
deps=[path(".tilt_bin/manager")],
skips_local_docker=True,
)