From a244b1083df6cff561f2eb13108261a698416334 Mon Sep 17 00:00:00 2001 From: Glenn Pratt Date: Fri, 12 Jan 2024 11:15:06 -0800 Subject: [PATCH] Add Tiltfile --- .dockerignore | 6 ++++ Dockerfile | 28 ++++++++++++++++--- Makefile | 5 ++-- Tiltfile | 71 ++++++++++++++++++++++++++++++++++++++++++++++++ devbox.json | 7 +++++ devbox.lock | 65 ++++++++++++++++++++++++++++++++++++++++++++ tilt.values.yaml | 9 ++++++ 7 files changed, 184 insertions(+), 7 deletions(-) create mode 100644 .dockerignore create mode 100644 Tiltfile create mode 100644 devbox.json create mode 100644 devbox.lock create mode 100644 tilt.values.yaml diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000..a2f7e521 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,6 @@ +.* +dist/ +deploy/ +e2e/ +examples/ +hack/ diff --git a/Dockerfile b/Dockerfile index 20942766..adaace27 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,14 @@ +# +# syntax=docker/dockerfile:1 + +# "docker": build in a Docker build container (default) +# "local": copy from the build context. This is useful for tilt's live_update +# feature, allowing hot reload of the kpp-api binary for fast +# development iteration. See ./Tiltfile +ARG BUILD_SOURCE="docker" + FROM golang:1.21-alpine as builder +RUN apk add --update --no-cache make RUN mkdir -p /linode WORKDIR /linode @@ -7,13 +17,23 @@ COPY go.sum . COPY main.go . COPY cloud ./cloud COPY sentry ./sentry +COPY Makefile . -RUN go mod download -RUN go build -a -ldflags '-extldflags "-static"' -o /bin/linode-cloud-controller-manager-linux /linode +RUN make build-linux -FROM alpine:3.18.4 +FROM alpine:3.18.4 as base RUN apk add --update --no-cache ca-certificates LABEL maintainers="Linode" LABEL description="Linode Cloud Controller Manager" -COPY --from=builder /bin/linode-cloud-controller-manager-linux /linode-cloud-controller-manager-linux + +# Copy from docker +FROM base as docker +COPY --from=builder /linode/dist/linode-cloud-controller-manager-linux-amd64 /linode-cloud-controller-manager-linux + +# Copy from local +FROM base as local +COPY dist/linode-cloud-controller-manager-linux-amd64 /linode-cloud-controller-manager-linux + +# See documentation on the arg +FROM $BUILD_SOURCE ENTRYPOINT ["/linode-cloud-controller-manager-linux"] diff --git a/Makefile b/Makefile index 2bc6d3c5..9495cfe6 100644 --- a/Makefile +++ b/Makefile @@ -44,7 +44,7 @@ build-linux: codegen echo "cross compiling linode-cloud-controller-manager for linux/amd64" && \ GOOS=linux GOARCH=amd64 \ CGO_ENABLED=0 \ - go build -o dist/linode-cloud-controller-manager-linux-amd64 . + go build -a -ldflags '-extldflags "-static"' -o dist/linode-cloud-controller-manager-linux-amd64 . .PHONY: build build: codegen @@ -65,8 +65,7 @@ imgname: echo IMG=${IMG} .PHONY: docker-build -# we cross compile the binary for linux, then build a container -docker-build: build-linux +docker-build: DOCKER_BUILDKIT=1 docker build --platform=$(PLATFORM) --tag ${IMG} . .PHONY: docker-push diff --git a/Tiltfile b/Tiltfile new file mode 100644 index 00000000..b48aa73c --- /dev/null +++ b/Tiltfile @@ -0,0 +1,71 @@ +load("ext://deployment", "deployment_create") +load("ext://k8s_attach", "k8s_attach") +load("ext://restart_process", "docker_build_with_restart") +load("ext://helm_resource", "helm_resource") + +allow_k8s_contexts(k8s_context()) + +# in order to use this registry you must add `127.0.0.1 registry-proxy` in your /etc/hosts +# and add http://registry-proxy:5000 to the list of insecure registries in docker daemon. +load("ext://k8s_attach", "k8s_attach") + +local_resource( + "registry-probe", + serve_cmd="sleep infinity", + readiness_probe=probe( + period_secs=15, + http_get=http_get_action(host="registry-proxy", port=5000, path="/"), + ), + labels=["registry"], +) + +k8s_attach( + "registry-port-forward", + "deployment/docker-registry", + namespace="registry", + port_forwards=[5000], + labels=["registry"], +) +default_registry("registry-proxy:5000", host_from_cluster="docker.local") + +labels = ["ccm-linode"] + +local_resource( + "linode-cloud-controller-manager-linux-amd64", + "make build-linux", + deps=[ + "*.go", + "cloud/**/*.go", + "sentry/**/*.go", + "go.*", + "Makefile", + ], + ignore=["./build/",], + labels=labels, +) + +docker_build_with_restart( + "linode/linode-cloud-controller-manager", + ".", + entrypoint=["/linode-cloud-controller-manager-linux-amd64"], + ignore=["**/*.go", "go.*"], + live_update=[ + sync("./dist/linode-cloud-controller-manager-linux-amd64", "/linode-cloud-controller-manager-linux"), + ], + build_args={"BUILD_SOURCE": "local"}, + platform="linux/amd64", +) + +# Avoiding helm_resource because orchestrating `helm install` over an +# argocd app seems to require deleting the app which is slow and upsets pulumi. +chart_yaml = helm( + "deploy/chart", + name="ccm-linode", + namespace="kube-system", + values="./tilt.values.yaml", +) +k8s_yaml(chart_yaml) + +# k8s_resource( +# "ccm-linode", labels=labels +# ) diff --git a/devbox.json b/devbox.json new file mode 100644 index 00000000..586425de --- /dev/null +++ b/devbox.json @@ -0,0 +1,7 @@ +{ + "packages": [ + "go_1_20@latest", + "tilt@latest", + "kubernetes-helm@latest" + ] +} diff --git a/devbox.lock b/devbox.lock new file mode 100644 index 00000000..520686c3 --- /dev/null +++ b/devbox.lock @@ -0,0 +1,65 @@ +{ + "lockfile_version": "1", + "packages": { + "go_1_20@latest": { + "last_modified": "2024-01-02T02:19:20Z", + "resolved": "github:NixOS/nixpkgs/63143ac2c9186be6d9da6035fa22620018c85932#go_1_20", + "source": "devbox-search", + "version": "1.20.12", + "systems": { + "aarch64-darwin": { + "store_path": "/nix/store/vgygiqcs16im3ffw6p0bv9zihixxg0cl-go-1.20.12" + }, + "aarch64-linux": { + "store_path": "/nix/store/rlk4nvwrz6rl7r87sn5g6v2vr2mhq8nv-go-1.20.12" + }, + "x86_64-darwin": { + "store_path": "/nix/store/vw51wxs8110al4q12pbg3vpi78w8ijk9-go-1.20.12" + }, + "x86_64-linux": { + "store_path": "/nix/store/s05mmkyf6sm6vskb4fwbjq0x93sqalqr-go-1.20.12" + } + } + }, + "kubernetes-helm@latest": { + "last_modified": "2023-11-19T17:46:56Z", + "resolved": "github:NixOS/nixpkgs/0bf3f5cf6a98b5d077cdcdb00a6d4b3d92bc78b5#kubernetes-helm", + "source": "devbox-search", + "version": "3.13.2", + "systems": { + "aarch64-darwin": { + "store_path": "/nix/store/bm0hydn3x8qicnnpp1j59affzbh802g6-kubernetes-helm-3.13.2" + }, + "aarch64-linux": { + "store_path": "/nix/store/rlxzcdijanfnr1cycmasxlqqbkhmfllc-kubernetes-helm-3.13.2" + }, + "x86_64-darwin": { + "store_path": "/nix/store/wihx37d21rxyvp5d10ki9qr57mmqa96n-kubernetes-helm-3.13.2" + }, + "x86_64-linux": { + "store_path": "/nix/store/2nsswfqlz4nc2hrbxchz7n98ccg9jfjx-kubernetes-helm-3.13.2" + } + } + }, + "tilt@latest": { + "last_modified": "2023-11-19T17:46:56Z", + "resolved": "github:NixOS/nixpkgs/0bf3f5cf6a98b5d077cdcdb00a6d4b3d92bc78b5#tilt", + "source": "devbox-search", + "version": "0.33.6", + "systems": { + "aarch64-darwin": { + "store_path": "/nix/store/d0kpgvk6vvb8lvsvmh338zxfnb9b7vp9-tilt-0.33.6" + }, + "aarch64-linux": { + "store_path": "/nix/store/d61h2m341hza65rs8ay04fjmdgwmw1m6-tilt-0.33.6" + }, + "x86_64-darwin": { + "store_path": "/nix/store/30kfkrlyrbk3bzwr524kmqmsygf5a89p-tilt-0.33.6" + }, + "x86_64-linux": { + "store_path": "/nix/store/9yqsnwx8khnbf86z81cyaaqmh4qkfy2i-tilt-0.33.6" + } + } + } + } +} diff --git a/tilt.values.yaml b/tilt.values.yaml new file mode 100644 index 00000000..69df1d62 --- /dev/null +++ b/tilt.values.yaml @@ -0,0 +1,9 @@ +env: +- name: LINODE_HOSTNAME_ONLY_INGRESS + value: "false" +nodeSelector: + node-role.kubernetes.io/master: "true" +secretRef: + apiTokenRef: apiToken + name: linode-api-secret + regionRef: region