dev-environment/README.md

152 lines
4.8 KiB
Markdown
Raw Normal View History

2024-11-04 00:39:54 +00:00
# COOPGO Dev environment
2024-11-04 00:22:29 +00:00
Local dev environment for the COOPGO Technical Platform, using [Tilt](https://tilt.dev) and a local Kubernetes cluster (such as [Rancher Desktop](https://rancherdesktop.io/), K3D, ...)
2024-11-18 11:06:38 +00:00
Tested with Rancher Desktop and K3D.
2024-11-04 00:22:29 +00:00
## Quickstart
2024-11-18 11:06:38 +00:00
### Install local cluster
Install Rancher Dektop or K3D or any other local Kubernetes. Make your Kubernetes context point to this cluster
2024-11-04 00:22:29 +00:00
2024-11-18 11:00:49 +00:00
Later, we will be using port 80 to access the cluster Ingress controller. On Linux, you must probably allow this.
```
2024-11-27 18:21:16 +00:00
sudo sysctl -w net.ipv4.ip_unprivileged_port_start=80
2024-11-18 11:00:49 +00:00
```
To preserve this change across reboots as a custom kernel parameter setting, add the same command inside your /etc/sysctl.conf file (or a dedicated /etc/sysctl.d/xxxxx.conf).
2024-11-18 11:06:38 +00:00
#### Rancher Desktop
2024-11-18 11:00:49 +00:00
2024-11-27 18:21:16 +00:00
See installation instructions here : <https://docs.rancherdesktop.io/getting-started/installation>
2024-11-18 11:00:49 +00:00
2024-11-27 18:21:16 +00:00
#### K3D
2024-11-18 11:00:49 +00:00
2024-11-27 18:21:16 +00:00
Install K3D :
2024-11-18 11:00:49 +00:00
```
2024-11-27 18:21:16 +00:00
curl -s https://raw.githubusercontent.com/k3d-io/k3d/main/install.sh | bash
2024-11-18 11:00:49 +00:00
```
Create config for the internal K3D registry to mirror your default docker images registry, for example in `/tmp/k3d-registry.yaml` :
2024-11-19 16:21:02 +00:00
```/tmp/k3d.registry
2024-11-18 11:00:49 +00:00
mirrors:
docker.io:
endpoint:
- "git.coopgo.io"
```
Create cluster :
2024-11-27 18:21:16 +00:00
```
k3d cluster create devcluster -p "80:80@loadbalancer" --registry-create devregistry:5000 --registry-config /tmp/k3d-registry.yaml
2024-11-18 11:00:49 +00:00
```
2024-11-27 18:21:16 +00:00
### Install Tilt
2024-11-18 11:06:38 +00:00
[Follow instructions on Tilt documentation](https://docs.tilt.dev/install.html)
### Set the environment
2024-11-04 00:22:29 +00:00
2024-11-18 11:06:38 +00:00
Create a .env file and configure environment
2024-11-04 00:22:29 +00:00
For example, to set the source code directories (see default values in Tiltfile) :
2024-11-19 16:21:02 +00:00
```.env
2024-11-04 00:22:29 +00:00
PARCOURSMOB_DIR="../../coopgo-apps/parcoursmob"
MOBILITY_ACCOUNTS_DIR="../../coopgo-platform/mobility-accounts"
AGENDA_DIR="../../coopgo-platform/agenda"
FLEETS_DIR="../../coopgo-platform/fleets"
GROUPS_MANAGEMENT_DIR="../../coopgo-platform/groups-management"
```
To avoid developing on another cluster than the one dedicated for dev, we whitelist the correct context. By default, the allowed context is 'rancher-desktop'. To change this, set ALLOWED_K8S_CONTEXT to the correct context name in .env :
2024-11-19 16:21:02 +00:00
```.env
2024-11-04 00:22:29 +00:00
ALLOWED_K8S_CONTEXT="k3d-devcluster"
```
You might also want to set the default container images used if/while your local source code folder doesn't exist.
2024-11-19 16:21:02 +00:00
```.env
2024-11-18 11:00:49 +00:00
PARCOURSMOB_IMAGE=coopgo-apps/parcoursmob@v1.2
2024-11-04 00:22:29 +00:00
MOBILITY_ACCOUNTS_IMAGE=my.own.registry/coopgo-platform/mobility-accounts
...
```
2024-11-27 18:21:16 +00:00
#### K3D specific setup
2024-11-18 11:06:38 +00:00
If you're using K3D, remove the registry part in the images (we'll use K3D local registry instead). It should look something like this :
2024-11-18 11:00:49 +00:00
2024-11-19 16:21:02 +00:00
```.env
2024-11-18 11:00:49 +00:00
PARCOURSMOB_IMAGE=coopgo-apps/parcoursmob
MOBILITY_ACCOUNTS_IMAGE=coopgo-platform/mobility-accounts
...
```
2024-11-18 11:06:38 +00:00
Then, set the K8S config to the dedicated overlay in k8s_config :
2024-11-18 11:00:49 +00:00
2024-11-27 18:21:16 +00:00
```.env
2024-11-18 11:00:49 +00:00
K8S_CONFIG="k8s_config/k3d"
```
2024-11-27 18:21:16 +00:00
### Set local hosts config
2024-11-18 11:06:38 +00:00
Add `tilt-dev.svc.cluster.local parcoursmob.tilt-dev.svc.cluster.local mobility-accounts.tilt-dev.svc.cluster.local` to resolve `127.0.0.1` in your hosts config (`/etc/hosts` on Linux)
2024-11-04 00:22:29 +00:00
2024-11-27 18:21:16 +00:00
### Run the dev environment and start developing
2024-11-04 00:22:29 +00:00
2024-11-18 11:06:38 +00:00
Run `tilt up`
2024-11-04 00:22:29 +00:00
2024-11-27 18:21:16 +00:00
After some time (you can see the services loading -or failing, if there is an error- through Tilt UI), PARCOURSMOB should be available on <http://parcoursmob.tilt-dev.svc.cluster.local>
2024-11-04 00:22:29 +00:00
Once you can acess PARCOURSMOB UI, you can connect with the initially created user :
2024-11-27 18:21:16 +00:00
- username: <admin@parcoursmob.fr>
2024-11-04 00:22:29 +00:00
- password: parcoursmob
Now, you're ready to code !
2024-11-27 18:21:16 +00:00
## What it does
2024-11-04 00:22:29 +00:00
Set up PARCOURSMOB along with the following dependencies :
- COOPGO microservices :
2024-11-27 18:21:16 +00:00
- Mobility Accounts
- Groups Management
- Fleets
- Agenda
- Carpool service (coming soon)
2024-11-04 00:22:29 +00:00
- Other software Dependencies :
2024-11-27 18:21:16 +00:00
- MongoDB (Next step, deploy with PostgreSQL as both should be supported)
- Etcd for caching values
- [Minio](https://min.io) to store files
- [smtp4dev](https://github.com/rnwood/smtp4dev) to test outgoing emails
2024-11-04 00:22:29 +00:00
Tilt handles livereloading Kubernetes pods when something changes in the code. You just have to checkout your code in the directory you've specified in .env (see quickstart), start developing on exsting microservices, and see the changes.
## Acess useful internal components for debugging/tests
Access smtp4dev to check outgoing emails :
2024-11-19 16:21:02 +00:00
By default, smtp4dev HTTP port is redirected to localhost:12345. You can change this with the dedicated environment variable in `.env`
```.env
SMTP4DEV_LOCAL_PORT=12345
```
2024-11-27 18:21:16 +00:00
## Use Nix shell to start easily
You can use the "nix shell" (<https://nixos.org/>) utility to set your environment without having to install every dependency individually.
Install Nix, run `nix-shell`, and benefit from a shell providing :
- Tilt command
- K3D
- Protocol buffer dependencies (protoc, protoc-gen-go, protobuf) needed to build gRPC protocol buffer definitions in the Golang microservices with the COOPGO Platform
More to come to provide a full dev environment dedicated to the COOPGO Technical Platform