# Serverless Service
Serverless service uses [grpc-gateway](https://github.com/grpc-ecosystem/grpc-gateway) to generate a reverse-proxy server which provides HTTP+JSON interface to the backend gRPC services.
![grpc-gateway arch](https://grpc-ecosystem.github.io/grpc-gateway/assets/images/architecture_introduction_diagram.svg)

Services provided for [TiDB Cloud (Serverless Tier)](https://docs.pingcap.com/tidbcloud/select-cluster-tier#serverless-tier-beta), including:

- Import OpenAPI
- Serverless Billing 

## Project layout

- [apidocs](./apidocs): generated swagger files
- [cmd](./cmd): compiled to excutable binaries
- [deployments](./deployments): pulumi scripts used to deploy the service
- [idl](./idl): all IDL(Independent Define Language) files, use protobuf and managed by [buf](https://buf.build/)
  - [idl/idl](./idl/idl): protobuf files and buf files
  - [idl/pbgen](./idl/pbgen): generated go code
- [internal](./internal): private service code
- [pkg](./pkg): public code that can be imported by third services
- [scripts](./scripts): useful bash & python scripts 
- [tools](./tools): downloaded excutable binaries with go mod

## How to Run
### Run in local
Support fully functional local deployment. By default, auth is skipped for loopback address. You can enable it by setting `stage` to `"staging"` in [config.yaml](./scripts/config/config.yaml) (no side effects). Or you can modify IDs of `fakeUser` in [auth.go](./internal/grpc/middlewares/auth/auth.go) to test specific user.

Note: make sure you have permission to access dev eks, refer to [doc](https://pingcap.feishu.cn/wiki/wikcnZYlICFVHBmTVmZbSc1klkf#doxcnU2gAoKQsuKAMwxuh9pVWPd).
```bash
# run as a http server
$ make local-run 
# or
$ make local-run http

# run as a grpc server
$ make local-run grpc
```

### Run in dev

You can use [github action](https://github.com/tidbcloud/serverless-service/actions/workflows/cd-dev.yml) to deploy in dev environment. Optionally, you can use workflow from your branch to run this action to test your code in the dev environment : ) 
