# Deployment

Services deployed (using kustomize):

- [catalog](./src/catalog)
- [runner](./src/runner)
- [proxy-admin](./src/proxy-admin)
- [proxy-client](./src/proxy-client)
- [web-client](./src/web-client)


Platform components deployed (using helm):

- [Traefik]()
- [Postgresql]()


## [Beta](https://beta.barretthousen.com)

The [Beta](https://beta.barretthousen.com) environment lives in my [homelab repo](https://git.vdhsn.com/adam/SunnyHomeLab),
 and is auto deployed using Flux w/ kustomize.

See [./env/beta](./env/beta/kustomization.yaml) for how it's set up.

- There are only 3 environments: `local`, `beta`, `prod`
	- `local`: optimize for iteration speed, observability, mutability. Ephemeral data. Should be quick to create and destroy.
	- `beta`: optimize for likeness with prod, observability, and durable data.
	- `prod`: optimize for up time, automated change control, observability, data durability.
- Each environment should pull from the image tag that matches it's name (ie catalog service running in `beta` env will use `git.vdhsn.com/barretthousen/service-catalog:beta` docker image)
- All environments should have resources suffixed with their name (ie `deployment/catalog-beta` in `beta` env)
- All environments must use kustomize, and have the same resources - configuration of those resources can vary as needed

### Initial environment setup

Deploy the following with Helm (assuming we're setting up a new `beta` env with the following commands):
1. Traefik:
```sh
helm repo add traefik https://traefik.github.io/charts;

helm upgrade --install  ingress traefik/traefik -n 'barretthousen-beta'\
			--set=logs.access.enabled=true
```

2. Postgresql:
```sh
helm repo add bitnami https://charts.bitnami.com/bitnami;

helm install --upgrade bh-db bitnami/postgresql -n 'barretthousen-beta' \
			--set='fullnameOverride=bh-db' \
			--set='auth.enablePostgresuser=true' \
			--set='auth.postgresPassword=bh-admin' \
			--set='auth.database=bh'
```

### Deployment steps

1. Build and publish prod images
```sh
make build-backend-image SERVICE=catalog env=beta
make build-backend-image SERVICE=runner env=beta
make build-backend-image SERVICE=proxy-admin env=beta
make build-backend-image SERVICE=proxy-client env=beta

make build-client-image SERVICE=web-client env=beta
```

2. Rolling restart deployments in the beta env
```sh
kubectl rollout restart -n barretthousen-beta deployment runner-beta
kubectl rollout status -n barretthousen-beta deployment runner-beta -w

kubectl rollout restart -n barretthousen-beta deployment catalog-beta
kubectl rollout status -n barretthousen-beta deployment catalog-beta  -w

kubectl rollout restart -n barretthousen-beta deployment proxy-admin-beta
kubectl rollout status -n barretthousen-beta deployment proxy-admin-beta -w

kubectl rollout restart -n barretthousen-beta deployment proxy-client-beta
kubectl rollout status -n barretthousen-beta deployment proxy-client-beta -w

kubectl rollout restart -n barretthousen-beta deployment web-client-beta
kubectl rollout status -n barretthousen-beta deployment web-client-beta -w
```


## Prod

TBD
