dev: quick notes on how to use tilt and minikube (#10407)

* dev: quick notes on how to use tilt and minikube

* prettier

* Update dev/tilt/README.md

Co-authored-by: Thorsten Ball <mrnugget@gmail.com>

* thorsten review

* code review unknwon

* Update dev/tilt/README.md

Co-authored-by: ᴜɴᴋɴᴡᴏɴ <joe@sourcegraph.com>

* code review stephen

* prettier

Co-authored-by: Thorsten Ball <mrnugget@gmail.com>
Co-authored-by: ᴜɴᴋɴᴡᴏɴ <joe@sourcegraph.com>
This commit is contained in:
uwedeportivo 2020-05-08 16:41:59 -07:00 committed by GitHub
parent 3a7c957ede
commit ade9d713a7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 46 additions and 0 deletions

4
.gitignore vendored
View File

@ -132,3 +132,7 @@ storybook-static/
# Custom dev-specific nginx config
/dev/*.nginx.conf
# tilt files
/dev/tilt/generated-cluster
/dev/tilt/tilt-watch-targets

3
dev/tilt/Caddyfile Normal file
View File

@ -0,0 +1,3 @@
sourcegraph.test:3443
tls internal
reverse_proxy 192.168.99.111:31963

32
dev/tilt/README.md Normal file
View File

@ -0,0 +1,32 @@
## Local development environment with [tilt.dev](https://tilt.dev) and [minikube](https://kubernetes.io/docs/tasks/tools/install-minikube/)
> This is still a work in progress. `tilt` is useful when you have to develop k8s code and need a local cluster for your edit/compile/test cycle.
> `tilt` can also be used with [bare processes](https://blog.tilt.dev/2020/02/12/local-dev.html) but we haven't converted and optimized our build
> pipeline to it. The `tilt` team have given us a [starting point](https://github.com/windmilleng/sourcegraph/blob/master/Tiltfile) (thanks!).
> For now, (until we convert, test and optimize this approach) please still use `enterprise/dev/start.sh`.
(Instructions assume you are in this directory)
- Install [tilt](https://docs.tilt.dev/install.html)
- Install [minikube](https://kubernetes.io/docs/tasks/tools/install-minikube/)
- Generate manifests from the [minikube overlay](https://github.com/sourcegraph/deploy-sourcegraph/blob/master/overlays/minikube) and copy the `generated-cluster` directory into this directory.
- `mkdir tilt-watch-targets`
- Prepare the cluster:
```shell
minikube start
kubectl create namespace ns-sourcegraph
kubectl -n ns-sourcegraph apply --prune -l deploy=sourcegraph -f generated-cluster --recursive
kubectl -n ns-sourcegraph expose deployment sourcegraph-frontend --type=NodePort --name sourcegraph --port=3080 --target-port=3080
minikube service list
```
- From the `minikube service list` output take the exposed port and modify the Caddyfile.
- `caddy run` (this makes Sourcegraph from the minikube cluster available at https://sourcegraph.test:3443)
- `tilt up` (starts tilt)
Tilt will start an initial build of the frontend and deploy it. Whenever you are done editing and want to trigger another build, `touch tilt-watch-targets/frontend`.
Similar to the `frontend` you can add other `custom_build` statements to your `Tiltfile` to build and watch the other servers.
There are many `Tiltfile` modifications that can help accelerate the edit/build/deploy cycle: https://docs.tilt.dev/example_go.html

7
dev/tilt/Tiltfile Normal file
View File

@ -0,0 +1,7 @@
k8s_yaml(listdir('generated-cluster'))
custom_build(
'sourcegraph/frontend',
'../../cmd/frontend/pre-build.sh && IMAGE="$EXPECTED_REF" ../../cmd/frontend/build.sh',
['tilt-watch-targets/frontend'],
)