dev-environment/README.md

4.4 KiB

COOPGO Dev environment

Local dev environment for the COOPGO Technical Platform, using Tilt and a local Kubernetes cluster (such as Rancher Desktop, K3D, ...)

Tested with Rancher Desktop and K3D.

Quickstart

Install local cluster

Install Rancher Dektop or K3D or any other local Kubernetes. Make your Kubernetes context point to this cluster

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).

Rancher Desktop

See installation instructions here : https://docs.rancherdesktop.io/getting-started/installation

K3D

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

Install Tilt

Follow instructions on Tilt documentation

Set the environment

Create a .env file and configure environment

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 :

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.

PARCOURSMOB_IMAGE=coopgo-apps/parcoursmob@v1.2
MOBILITY_ACCOUNTS_IMAGE=my.own.registry/coopgo-platform/mobility-accounts
...

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 :

PARCOURSMOB_IMAGE=coopgo-apps/parcoursmob 
MOBILITY_ACCOUNTS_IMAGE=coopgo-platform/mobility-accounts
...

Then, set the K8S config to the dedicated overlay in k8s_config :

K8S_CONFIG="k8s_config/k3d"

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)

Run the dev environment and start developing

Run tilt up

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

Once you can acess PARCOURSMOB UI, you can connect with the initially created user :

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 :
    • MongoDB (Next step, deploy with PostgreSQL as both should be supported)
    • Etcd for caching values
    • Minio to store files
    • smtp4dev to test outgoing emails

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 :

By default, smtp4dev HTTP port is redirected to localhost:12345. You can change this with the dedicated environment variable in .env

SMTP4DEV_LOCAL_PORT=12345