起因
公司使用syncd搭建的发布系统,在有时候需要发布的时候需要进行一系列繁琐的操作才能发布代码。思考如何命令行一键快速发布。
研究
通过抓公司页面得到发布的关键接口。
- 登录
api/login
参数
参数名 | 备注 |
---|---|
username | |
password | md5 |
返回
1 2 3 4 5 6 7 8 | type ResData struct { Code int `json:"code"` Data Data `json:"data"` Message string `json:"message"` } type Data struct { Token string `json:"token"` } |
- 查看空间列表
api/project/space/list
参数名 | 备注 |
---|---|
token | login返回 |
offset: | 分页 |
limit: | 个数 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | type ResData struct { Code int `json:"code"` Data Data `json:"data"` Message string `json:"message"` } type List struct { ID int `json:"id"` Name string `json:"name"` Description string `json:"description"` Ctime int `json:"ctime"` } type Data struct { List []List `json:"list"` Total int `json:"total"` } |
- 查看项目列表
api/project/list
参数
参数名 | 备注 |
---|---|
spaceId | 空间ID |
offset: | 分页 |
limit: | 每页条数 |
token | login返回 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | type ResData struct { Code int `json:"code"` Data Data `json:"data"` Message string `json:"message"` } type List struct { ID int `json:"id"` Name string `json:"name"` NeedAudit int `json:"need_audit"` Status int `json:"status"` } type Data struct { List []List `json:"list"` Total int `json:"total"` } |
- 查看所有项目列表
api/deploy/apply/project/all
参数名 | 备注 |
---|---|
token | login返回 |
1 2 3 4 5 6 | type ResData []struct { ProjectID int `json:"project_id"` ProjectName string `json:"project_name"` SpaceID int `json:"space_id"` SpaceName string `json:"space_name"` } |
- 构建任务
api/deploy/build/start
参数
参数名 | 备注 |
---|---|
id | 项目ID |
- 查看构建状态
api/deploy/build/status
参数
参数名 | 备注 |
---|---|
id | 项目ID |
返回
1 | map[string]interface{} |
status 解释
1 2 3 4 | BUILD_STATUS_INIT = 0 BUILD_STATUS_RUNNING = 1 BUILD_STATUS_DONE = 2 BUILD_STATUS_ERROR = 3 |
- 部署任务
api/deploy/deploy/start
参数
参数名 | 备注 |
---|---|
id | 项目ID |
- 部署状态
api/deploy/deploy/status
参数
参数名 | 备注 |
---|---|
id | 项目ID |
status 解释
1 2 3 4 | DEPLOY_STATUS_NONE = 0 DEPLOY_STATUS_START = 1 DEPLOY_STATUS_SUCCESS = 2 DEPLOY_STATUS_FAILED = 3 |
所以根据以上写出代码
代码放在github了
github地址:syncd-console
1.做了项目名模糊查询
2.未做回滚功能
效果