Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Tiltfile #166

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.*
deploy/
e2e/
examples/
hack/
25 changes: 21 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
# "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

Expand All @@ -7,13 +14,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"]
7 changes: 3 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ test: fmt codegen

.PHONY: build-linux
build-linux: codegen
echo "cross compiling linode-cloud-controller-manager for linux/amd64" && \
echo "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 -ldflags '-extldflags "-static"' -o dist/linode-cloud-controller-manager-linux-amd64 .

.PHONY: build
build: codegen
Expand All @@ -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
Expand Down
75 changes: 75 additions & 0 deletions Tiltfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
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",
# No glob support :(
deps=[
"cloud/",
"go.mod",
"go.sum",
"main.go",
"Makefile",
"sentry/",
],
ignore=[
"**/*.bin",
"**/gomock*",
"cloud/linode/mock_client_test.go",
],
labels=labels,
)

entrypoint = "/linode-cloud-controller-manager-linux"
docker_build_with_restart(
"linode/linode-cloud-controller-manager",
".",
entrypoint=[entrypoint],
ignore=["**/*.go", "go.*", "Makefile"],
live_update=[
sync(
"dist/linode-cloud-controller-manager-linux-amd64",
entrypoint,
),
],
build_args={"BUILD_SOURCE": "local"},
platform="linux/amd64",
)

chart_yaml = helm(
"deploy/chart",
name="ccm-linode",
namespace="kube-system",
values="./tilt.values.yaml",
)
k8s_yaml(chart_yaml)
7 changes: 7 additions & 0 deletions devbox.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"packages": [
"go_1_20@latest",
"tilt@latest",
"kubernetes-helm@latest"
]
}
65 changes: 65 additions & 0 deletions devbox.lock
Original file line number Diff line number Diff line change
@@ -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"
}
}
}
}
}
9 changes: 9 additions & 0 deletions tilt.values.yaml
Original file line number Diff line number Diff line change
@@ -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
Loading