## 项目简介
本项目是公司 CMDB 资产管理系统，主要用于管理公司的服务器、DNS、域名、网络设备、数据库、中间件、应用等资产信息，以及资产的配置管理、变更管理、故障管理等。

### 前端
使用百度低代码框架 [Amis](https://github.com/baidu/amis) 实现，通过配置 JSON 文件生成各种后台页面。

主 HTML 文件：`/cmdb-backend/web/index.html`

其他 json 文件目录：`/cmdb-backend/web/pages/`


### 后端
使用 golang gin 框架实现，其中 / URL 是前端页面，/api/xx URL 是后端接口。



## 项目启动

### 本地启动方式
1. 在本地设置环境变量 ，建议写入本地 .zshrc 文件

``` bash
vim ~/.zshrc

export CMDB_ENV=dev
```
保存退出，执行命令

``` bash
source .zshrc
```

2. 修改 config 文件，改成本地实际路径
``` bash
vim /cmdb-backend/pkg/config

viper.AddConfigPath("/Users/xxx/xx/cmdb-backend/config")
```

3. 启动项目
``` bash
go run main.go
```

4. 访问地址  http://localhost:80


### 生产部署方式

生产环境仍采用本地交叉编译二进制并上传到服务器 `/apps` 的方式，进程由 supervisor 管理，不再使用 `nohup`。

1. 确认生产配置

生产配置放在服务器 `/apps/config/config_prod.yaml`，不要提交到 Git。SSO 迁移到 SaaS Authing 时，至少需要更新以下字段：

```yaml
authing:
  app_id: <Authing App ID>
  app_secret: <Authing App Secret>
  app_redirect_uri: https://cmdb.pingcap.net/api/account/callback
  app_provider_uri: https://pingcap-cmdb.authing.cn/oidc
  app_logout_uri: https://pingcap-cmdb.authing.cn/oidc/session/end
  user_pool_id: <Authing User Pool ID>
  user_pool_secret: <Authing User Pool Secret>
```

2. 首次安装 supervisor（仅首次需要）

```bash
ssh root@cmdb 'apt-get update && apt-get install -y supervisor && systemctl enable --now supervisor'
```

3. 构建、上传并通过 supervisor 重启

```bash
./scripts/deploy_supervisor.sh
```

如果远端尚未安装 supervisor，也可以让脚本安装：

```bash
./scripts/deploy_supervisor.sh --install-supervisor
```

4. 查看服务状态和日志

```bash
ssh root@cmdb 'supervisorctl status cmdb-backend'
ssh root@cmdb 'tail -f /apps/cmdb-backend.log'
ssh root@cmdb 'tail -f /apps/logs/cmdb.log'
```

5. 健康检查

```bash
curl https://cmdb.pingcap.net/check_health
```
