# TEP

![TEP Architecture](/static/tep-overview.png)

# Development

## TEP Server

### API definetion & Code generation

All API definetions, including format of requests and responses, are defined in `pkg/apis/tepserver/swagger.yaml`, it's recommended to use [Swagger Editor](https://swagger.io/tools/swagger-editor/) to edit API definitions. Simply import it to the editor, and export after any modification to replace the old file.

Currently, codes in `pkg/apis/tepserver/types` are generated with [go-swagger](https://github.com/go-swagger/go-swagger). Use `hack/generate-swagger-models.sh` to generate Go API models after `pkg/apis/tepserver/swagger.yaml` is modified.

Besides that, the frontend uses JSON to mock data, so `hack/convert-api-to-json.sh` needs to be run after `pkg/apis/tepserver/swagger.yaml` is modified.

### Dependency
- At first we should install statik for attach static file into binary file. We can easily install statik like below:

```
make bin/statik
```

Learn more about statik in this [guide](https://github.com/rakyll/statik).

- [node v8.11.3+](https://nodejs.org/en/) is needed to build `dashboard-ui`, and you should have permission to access private repo of the organization `pingcap` on github.com.

### Build

```
make setup
make db/entity/autogenerated_entity.go
make tep-server
```

## TEP APIServer

### API definetion & Code generation

If you change the API object type definitions in any of the `pkg/apis/apiserver/.../types.go` files then you will need to update the files generated from the type definitions. To do this, invoke `hack/update-codegen.sh` with tep as your current working directory; the script takes no arguments.

### Build

```
make tep-apiserver
```

## Deploy on Kubernetes

### Deploy a meta database

TEP uses a meta database to store basic confurations and logs, any MySQL compatiable database server can be used, including TiDB itself. Here we use a simple single point MySQL instance for less resource usage.

```
helm install --name=tep-mysql stable/mysql --namespace=tep --set persistence.storageClass=local-storage
```

> refer: https://github.com/helm/charts/tree/master/stable/mysql

### Deploy TEP server

```
kubectl apply -f deploy/tep-server
```

### Deploy TEP APIServer

```
kubectl apply -f deploy/tep-apiserver
```
