Skip to content

Commit

Permalink
Adds Tilt as dev environment (#103)
Browse files Browse the repository at this point in the history
  • Loading branch information
amorey authored Jul 12, 2024
1 parent 26e1a32 commit c12b0f2
Show file tree
Hide file tree
Showing 11 changed files with 405 additions and 224 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ lerna-debug.log*
/frontend/dist-ssr
/backend/website

# tilt (custom)
.tilt

# misc
/frontend/stats.html

Expand Down
17 changes: 11 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,17 +165,22 @@ Kubetail can be configured using a configuration file written in YAML, JSON, TOM

## Develop

This repository is organized as a monorepo containing a Go-based backend server and a React-based frontend static website in their respective directories (see [backend](backend) and [frontend](frontend)). The website queries the backend server which proxies requests to a Kubernetes API and also performs a few other custom tasks (e.g. authentication). In production, the frontend website is bundled into the backend server and served as a static website (see [Build](#build)). In development, the backend and frontend are run separately but configured to work together.
This repository is organized as a monorepo containing a Go-based backend server and a React-based frontend static website in their respective directories (see [backend](backend) and [frontend](frontend)). The website queries the backend server which proxies requests to a Kubernetes API and also performs a few other custom tasks (e.g. authentication). In production, the frontend website is bundled into the backend server and served as a static website (see [Build](#build)). In development, the backend and frontend are run separately but configured to work together using [Tilt](https://tilt.dev).

To develop kubetail, first create a kubernetes dev cluster using a dev cluster tool that [works with Tilt](https://docs.tilt.dev/choosing_clusters#microk8s). To automate the process you can also use [ctlptl](https://github.com/tilt-dev/ctlptl) and one of the configs available in the [`hack/ctlptl`](hack/ctlptl) directory. For example, to create a dev cluster using [minikube](https://minikube.sigs.k8s.io/docs/) you can use this command:

```console
ctlptl apply -f hack/ctlptl/minikube.yaml
```

Once the dev cluster is running and `kubectl` is pointing to it, you can bring up the dev environment using Tilt:

To run the backend development server, cd into the `backend` directory and run the `server` command:
```console
cd backend
go run ./cmd/server -c hack/server.conf
tilt up
```

Now access the health status at [http://localhost:4000/healthz](http://localhost:4000/healthz).
After Tilt brings up the backend server you can access it on your localhost on port 4000. To run the frontend development website, cd into to the `frontend` directory and run the `install` and `dev` commands:

To run the frontend development website, cd into to the `frontend` directory and run the `install` and `dev` commands:
```console
cd frontend
pnpm install
Expand Down
63 changes: 63 additions & 0 deletions Tiltfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
load('ext://restart_process', 'docker_build_with_restart')

# kubetail-server
local_resource(
'kubetail-server-compile',
'cd backend && CGO_ENABLED=0 GOOS=linux go build -o ../.tilt/server ./cmd/server',
deps=[
'./backend'
]
)

docker_build_with_restart(
'kubetail-server',
dockerfile='hack/tilt/Dockerfile.kubetail-server',
context='.',
entrypoint="/server/server -c /etc/kubetail/config.yaml",
only=[
'./.tilt/server',
'./backend/templates'
],
live_update=[
sync('./.tilt/server', '/server/server'),
sync('./backend/templates', '/templates')
]
)

# --- apply manifests ---

k8s_yaml('hack/tilt/kubetail-server.yaml')
k8s_yaml('hack/tilt/loggen.yaml')
k8s_yaml('hack/tilt/loggen-ansi.yaml')
k8s_yaml('hack/tilt/echoserver.yaml')
#k8s_yaml('hack/tilt/chaoskube.yaml')

# --- define resources ---

k8s_resource(
'kubetail-server',
port_forwards='4000:4000',
objects=[
'kubetail-server:serviceaccount',
'kubetail-server:clusterrole',
'kubetail-server:clusterrolebinding',
'kubetail-server:configmap'
],
resource_deps=[]
)

#k8s_resource(
# 'chaoskube',
# objects=[
# 'chaoskube:serviceaccount',
# 'chaoskube:clusterrole',
# 'chaoskube:clusterrolebinding',
# 'chaoskube:role',
# 'chaoskube:rolebinding'
# ]
#)

k8s_resource(
'echoserver',
port_forwards='8080:8080',
)
13 changes: 13 additions & 0 deletions hack/ctlptl/minikube.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
apiVersion: ctlptl.dev/v1alpha1
kind: Registry
name: ctlptl-registry
port: 5005
---
apiVersion: ctlptl.dev/v1alpha1
kind: Cluster
product: minikube
registry: ctlptl-registry
minikube:
startFlags:
- --nodes=3
- --addons=metrics-server
218 changes: 0 additions & 218 deletions hack/minikube.yaml

This file was deleted.

10 changes: 10 additions & 0 deletions hack/tilt/Dockerfile.kubetail-server
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
FROM alpine:3.20.0

WORKDIR /server

# copy
COPY .tilt/server ./server
COPY backend/templates ./templates

ENTRYPOINT ["./server"]
CMD []
Loading

0 comments on commit c12b0f2

Please sign in to comment.