dev-environment/README.md

137 lines
4.3 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.
```
sudo sysctl -w net.ipv4.ip_unprivileged_port_start=80
```
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
See installation instructions here : https://docs.rancherdesktop.io/getting-started/installation
2024-11-18 11:06:38 +00:00
#### K3D
2024-11-18 11:00:49 +00:00
Install K3D :
```
curl -s https://raw.githubusercontent.com/k3d-io/k3d/main/install.sh | bash
```
Create config for the internal K3D registry to mirror your default docker images registry, for example in `/tmp/k3d-registry.yaml` :
```
mirrors:
docker.io:
endpoint:
- "git.coopgo.io"
```
Create cluster :
```
k3d cluster create devcluster -p "80:80@loadbalancer" --registry-create devregistry:5000 --registry-config /tmp/k3d-registry.yaml
```
2024-11-18 11:06:38 +00:00
### Install Tilt
[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) :
```
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-18 11:00:49 +00:00
```
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-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-18 11:06:38 +00:00
#### K3D specific setup
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
```
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
```
K8S_CONFIG="k8s_config/k3d"
```
2024-11-18 11:06:38 +00:00
### Set local hosts config
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-18 11:06:38 +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-18 11:06:38 +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 :
- username: admin@parcoursmob.fr
- password: parcoursmob
Now, you're ready to code !
## What it does
Set up PARCOURSMOB along with the following dependencies :
- COOPGO microservices :
- Mobility Accounts
- Groups Management
- Fleets
- Agenda
- Carpool service (coming soon)
- Other software Dependencies :
2024-11-04 00:39:20 +00:00
- MongoDB (Next step, deploy with PostgreSQL as both should be supported)
2024-11-04 00:22:29 +00:00
- Etcd for caching values
2024-11-04 00:39:20 +00:00
- [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-04 00:39:20 +00:00
1. Forward smtp4dev service locally : kubectl port-forward svc/smtp4dev 9090:80
2024-11-18 11:00:49 +00:00
2. Access UI : http://localhost:9090/