From 07d6be2888c7ad8cbcc62978f2dcd2526f51537f Mon Sep 17 00:00:00 2001 From: Gergely Brautigam <182850+Skarlso@users.noreply.github.com> Date: Thu, 16 Mar 2023 14:16:32 +0100 Subject: [PATCH] feat: prepare e2e test environment --- .dockerignore | 1 - Tiltfile | 67 +++++++++++++++++++++++++++++++ config/manager/kustomization.yaml | 4 +- tilt.dockerfile | 5 +++ 4 files changed, 74 insertions(+), 3 deletions(-) create mode 100644 Tiltfile create mode 100644 tilt.dockerfile diff --git a/.dockerignore b/.dockerignore index 0f04682..8e6fac7 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,4 +1,3 @@ # More info: https://docs.docker.com/engine/reference/builder/#dockerignore-file # Ignore build and test binaries. -bin/ testbin/ diff --git a/Tiltfile b/Tiltfile new file mode 100644 index 0000000..96c6ed4 --- /dev/null +++ b/Tiltfile @@ -0,0 +1,67 @@ +# -*- mode: Python -*- + +kubectl_cmd = "kubectl" + +# verify kubectl command exists +if str(local("command -v " + kubectl_cmd + " || true", quiet = True)) == "": + fail("Required command '" + kubectl_cmd + "' not found in PATH") + +# Use kustomize to build the install yaml files +install = kustomize('config/default') + +# Update the root security group. Tilt requires root access to update the +# running process. +objects = decode_yaml_stream(install) +for o in objects: + if o.get('kind') == 'Deployment' and o.get('metadata').get('name') == 'git-sync-controller': + o['spec']['template']['spec']['securityContext']['runAsNonRoot'] = False + break + +updated_install = encode_yaml_stream(objects) + +# Apply the updated yaml to the cluster. +# Allow duplicates so the e2e test can include this tilt file with other tilt files +# setting up the same namespace. +k8s_yaml(updated_install, allow_duplicates = True) + +load('ext://restart_process', 'docker_build_with_restart') + +# enable hot reloading by doing the following: +# - locally build the whole project +# - create a docker imagine using tilt's hot-swap wrapper +# - push that container to the local tilt registry +# Once done, rebuilding now should be a lot faster since only the relevant +# binary is rebuilt and the hot swat wrapper takes care of the rest. +local_resource( + 'git-sync-controller-binary', + 'CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o bin/manager ./', + deps = [ + "main.go", + "go.mod", + "go.sum", + "api", + "controllers", + "pkg", + ], +) + +# Build the docker image for our controller. We use a specific Dockerfile +# since tilt can't run on a scratch container. +# `only` here is important, otherwise, the container will get updated +# on _any_ file change. We only want to monitor the binary. +# If debugging is enabled, we switch to a different docker file using +# the delve port. +entrypoint = ['/manager'] +dockerfile = 'tilt.dockerfile' +docker_build_with_restart( + 'ghcr.io/open-component-model/git-sync-controller', + '.', + dockerfile = dockerfile, + entrypoint = entrypoint, + only=[ + './bin', + ], + live_update = [ + sync('./bin/manager', '/manager'), + ], +) diff --git a/config/manager/kustomization.yaml b/config/manager/kustomization.yaml index a55e156..dc2f5ec 100644 --- a/config/manager/kustomization.yaml +++ b/config/manager/kustomization.yaml @@ -7,5 +7,5 @@ images: newName: controller newTag: latest - name: open-component-model/git-sync-controller - newName: localhost:5001/open-component-model/git-sync-controller - newTag: v0.0.1 + newName: ghcr.io/open-component-model/git-sync-controller + newTag: latest diff --git a/tilt.dockerfile b/tilt.dockerfile new file mode 100644 index 0000000..2fbfdce --- /dev/null +++ b/tilt.dockerfile @@ -0,0 +1,5 @@ +FROM alpine +WORKDIR / +COPY ./bin/manager /manager + +ENTRYPOINT ["/manager"]