FIX test devops

This commit is contained in:
Jasder 2020-07-21 17:08:07 +08:00
parent 20d8f21ebb
commit 0f92aa7981
6 changed files with 213 additions and 137 deletions

300
README.md
View File

@ -2508,7 +2508,9 @@ GET /api/dev_ops/builds
*示例*
```
curl -X GET http://localhost:3000/api/dev_ops/builds | jq
curl -X GET \
-d 'id=4844' \
http://localhost:3000/api/dev_ops/builds | jq
```
*请求参数说明:*
@ -2530,29 +2532,31 @@ curl -X GET http://localhost:3000/api/dev_ops/builds | jq
```
[
{
"id": 100207,
"repo_id": 296163,
"number": 42,
"id": 1,
"repo_id": 8,
"trigger": "@hook",
"number": 1,
"status": "success",
"event": "pull_request",
"action": "sync",
"link": "https://github.com/octoat/hello-world/compare/e3320539a4c0...9fc1ad6ebf12",
"message": "updated README",
"before": "e3320539a4c03ccfda992641646deb67d8bf98f3",
"after": "9fc1ad6ebf12462f3f9773003e26b4c6f54a772e",
"event": "push",
"action": "",
"link": "",
"timestamp": 0,
"message": "更新 '.trustie-pipeline.yml'\n",
"before": "5e7c6f7dfd5ce6cc6e287fcbc000dadd9992b324",
"after": "5e52ce51a239f5c8dd0b489a8a71e94f976179b4",
"ref": "refs/heads/master",
"source_repo": "spaceghost/hello-world",
"source": "develop",
"source_repo": "",
"source": "master",
"target": "master",
"author_login": "octocat",
"author_name": "The Octocat",
"author_email": "octocat@github.com",
"author_avatar": "http://www.gravatar.com/avatar/7194e8d48fa1d2b689f99443b767316c",
"sender": "bradrydzewski",
"started": 1564085874,
"finished": 1564086343,
"created": 1564085874,
"updated": 1564085874,
"author_login": "jasder",
"author_name": "jasder",
"author_email": "email.com",
"author_avatar": "",
"sender": "jasder",
"started": 1595317786,
"finished": 1595318426,
"created": 1595317786,
"updated": 1595317786,
"version": 3
}
]
@ -2566,13 +2570,16 @@ GET /api/dev_ops/builds/:number
*示例*
```
curl -X GET http://localhost:3000/api/dev_ops/builds/42 | jq
curl -X GET \
-d 'id=4844' \
http://ocalhost:3000/api/dev_ops/builds/1 | jq
```
*请求参数说明:*
|参数名|必选|类型|说明|
|-|-|-|-|
|id |int|repository's id|
|number |是|int |build's number |
*返回参数说明:*
@ -2586,52 +2593,78 @@ curl -X GET http://localhost:3000/api/dev_ops/builds/42 | jq
返回值
```
{
"id": 100207,
"repo_id": 296163,
"number": 42,
"status": "pending",
"event": "pull_request",
"action": "sync",
"link": "https://github.com/octoat/hello-world/compare/e3320539a4c0...9fc1ad6ebf12",
"message": "updated README",
"before": "e3320539a4c03ccfda992641646deb67d8bf98f3",
"after": "9fc1ad6ebf12462f3f9773003e26b4c6f54a772e",
"id": 1,
"repo_id": 8,
"trigger": "@hook",
"number": 1,
"status": "success",
"event": "push",
"action": "",
"link": "http://localhost:3000/jasder/forgeplus/compare/5e7c6f7dfd5ce6cc6e287fcbc000dadd9992b324...5e52ce51a239f5c8dd0b489a8a71e94f976179b4",
"timestamp": 0,
"message": "更新 '.trustie-pipeline.yml'\n",
"before": "5e7c6f7dfd5ce6cc6e287fcbc000dadd9992b324",
"after": "5e52ce51a239f5c8dd0b489a8a71e94f976179b4",
"ref": "refs/heads/master",
"source_repo": "spaceghost/hello-world",
"source": "develop",
"source_repo": "",
"source": "master",
"target": "master",
"author_login": "octocat",
"author_name": "The Octocat",
"author_email": "octocat@github.com",
"author_avatar": "http://www.gravatar.com/avatar/7194e8d48fa1d2b689f99443b767316c",
"sender": "bradrydzewski",
"started": 0,
"finished": 0,
"created": 1564085874,
"updated": 1564085874,
"version": 1,
"author_login": "jasder",
"author_name": "jasder",
"author_email": "2053003901@qq.com",
"author_avatar": "http://localhost:3000/user/avatar/jasder/-1",
"sender": "jasder",
"started": 1595317786,
"finished": 1595318426,
"created": 1595317786,
"updated": 1595317786,
"version": 3,
"stages": [
{
"id": 199937,
"repo_id": 296163,
"build_id": 100207,
"id": 1,
"repo_id": 8,
"build_id": 1,
"number": 1,
"name": "default",
"kind": "pipeline",
"type": "docker",
"status": "pending",
"status": "success",
"errignore": false,
"exit_code": 0,
"machine": "15e89c0f84f1",
"machine": "121.36.81.172",
"os": "linux",
"arch": "amd64",
"started": 0,
"stopped": 0,
"created": 1564085874,
"updated": 1564086343,
"version": 1,
"arch": "arm64",
"started": 1595317786,
"stopped": 1595318426,
"created": 1595317786,
"updated": 1595318426,
"version": 4,
"on_success": true,
"on_failure": false
"on_failure": false,
"steps": [
{
"id": 1,
"step_id": 1,
"number": 1,
"name": "clone",
"status": "success",
"exit_code": 0,
"started": 1595317786,
"stopped": 1595318373,
"version": 4
},
{
"id": 2,
"step_id": 1,
"number": 2,
"name": "test",
"status": "success",
"exit_code": 0,
"started": 1595318373,
"stopped": 1595318426,
"version": 4
}
]
}
]
}
@ -2645,13 +2678,16 @@ POST /api/dev_ops/builds/:number
*示例*
```
curl -X POST http://localhost:3000/api/dev_ops/builds/42 | jq
curl -X POST \
-d 'id=4844' \
http://localhost:3000/api/dev_ops/builds/1 | jq
```
*请求参数说明:*
|参数名|必选|类型|说明|
|-|-|-|-|
|id |int|repository's id|
|number |是|int |build's number |
*返回参数说明:*
@ -2665,54 +2701,32 @@ curl -X POST http://localhost:3000/api/dev_ops/builds/42 | jq
返回值
```
{
"id": 100207,
"repo_id": 296163,
"number": 42,
"id": 2,
"repo_id": 8,
"trigger": "jasder",
"number": 2,
"status": "pending",
"event": "pull_request",
"action": "sync",
"link": "https://github.com/octoat/hello-world/compare/e3320539a4c0...9fc1ad6ebf12",
"message": "updated README",
"before": "e3320539a4c03ccfda992641646deb67d8bf98f3",
"after": "9fc1ad6ebf12462f3f9773003e26b4c6f54a772e",
"event": "push",
"action": "",
"link": "http://localhost:3000/jasder/forgeplus/compare/5e7c6f7dfd5ce6cc6e287fcbc000dadd9992b324...5e52ce51a239f5c8dd0b489a8a71e94f976179b4",
"timestamp": 0,
"message": "更新 '.trustie-pipeline.yml'\n",
"before": "5e7c6f7dfd5ce6cc6e287fcbc000dadd9992b324",
"after": "5e52ce51a239f5c8dd0b489a8a71e94f976179b4",
"ref": "refs/heads/master",
"source_repo": "spaceghost/hello-world",
"source": "develop",
"source_repo": "",
"source": "master",
"target": "master",
"author_login": "octocat",
"author_name": "The Octocat",
"author_email": "octocat@github.com",
"author_avatar": "http://www.gravatar.com/avatar/7194e8d48fa1d2b689f99443b767316c",
"sender": "bradrydzewski",
"author_login": "jasder",
"author_name": "jasder",
"author_email": "2053003901@qq.com",
"author_avatar": "http://localhost:3000/user/avatar/jasder/-1",
"sender": "jasder",
"started": 0,
"finished": 0,
"created": 1564085874,
"updated": 1564085874,
"version": 1,
"stages": [
{
"id": 199937,
"repo_id": 296163,
"build_id": 100207,
"number": 1,
"name": "default",
"kind": "pipeline",
"type": "docker",
"status": "pending",
"errignore": false,
"exit_code": 0,
"machine": "15e89c0f84f1",
"os": "linux",
"arch": "amd64",
"started": 0,
"stopped": 0,
"created": 1564085874,
"updated": 1564086343,
"version": 1,
"on_success": true,
"on_failure": false
}
]
"created": 1595321350,
"updated": 1595321350,
"version": 1
}
```
---
@ -2724,13 +2738,16 @@ DELETE /api/dev_ops/builds/:number
*示例*
```
curl -X DELETE http://localhost:3000/api/dev_ops/builds/42 | jq
curl -X DELETE \
-d 'id=4844' \
http://localhost:3000/api/dev_ops/builds/42 | jq
```
*请求参数说明:*
|参数名|必选|类型|说明|
|-|-|-|-|
|id |int|repository's id|
|number |是|int |build's number |
*返回参数说明:*
@ -2743,6 +2760,82 @@ curl -X DELETE http://localhost:3000/api/dev_ops/builds/42 | jq
返回值
```
{
"id": 2,
"repo_id": 8,
"trigger": "jasder",
"number": 2,
"status": "killed",
"event": "push",
"action": "",
"link": "http://localhost:3000/jasder/forgeplus/compare/5e7c6f7dfd5ce6cc6e287fcbc000dadd9992b324...5e52ce51a239f5c8dd0b489a8a71e94f976179b4",
"timestamp": 0,
"message": "更新 '.trustie-pipeline.yml'\n",
"before": "5e7c6f7dfd5ce6cc6e287fcbc000dadd9992b324",
"after": "5e52ce51a239f5c8dd0b489a8a71e94f976179b4",
"ref": "refs/heads/master",
"source_repo": "",
"source": "master",
"target": "master",
"author_login": "jasder",
"author_name": "jasder",
"author_email": "2053003901@qq.com",
"author_avatar": "http://localhost:3000/user/avatar/jasder/-1",
"sender": "jasder",
"started": 1595321352,
"finished": 1595321590,
"created": 1595321350,
"updated": 1595321352,
"version": 3,
"stages": [
{
"id": 2,
"repo_id": 8,
"build_id": 2,
"number": 1,
"name": "default",
"kind": "pipeline",
"type": "docker",
"status": "killed",
"errignore": false,
"exit_code": 0,
"machine": "121.36.81.172",
"os": "linux",
"arch": "arm64",
"started": 1595321352,
"stopped": 1595321590,
"created": 1595321350,
"updated": 1595321352,
"version": 4,
"on_success": true,
"on_failure": false,
"steps": [
{
"id": 3,
"step_id": 2,
"number": 1,
"name": "clone",
"status": "killed",
"exit_code": 130,
"started": 1595321353,
"stopped": 1595321590,
"version": 3
},
{
"id": 4,
"step_id": 2,
"number": 2,
"name": "test",
"status": "skipped",
"exit_code": 130,
"started": 1595321590,
"stopped": 1595321590,
"version": 2
}
]
}
]
}
```
---
@ -2753,13 +2846,16 @@ GET /api/dev_ops/builds/:number/logs/:stage/:step
*示例*
```
curl -X GET http://localhost:3000/api/dev_ops/builds/42/logs/ | jq
curl -X GET \
-d 'id=4844' \
http://localhost:3000/api/dev_ops/builds/42/logs/ | jq
```
*请求参数说明:*
|参数名|必选|类型|说明|
|-|-|-|-|
|id |int|repository's id|
|number |是|int |build's number |
|stage |是|int |build's stage id |
|step |是|int |build's step id |

View File

@ -1,6 +1,6 @@
class ::DevOps::BuildsController < ApplicationController
before_action :require_login, except: :test_webhook
before_action :find_repo, except: :test_webhook
before_action :require_login
before_action :find_repo
def index
cloud_account = @repo.dev_ops_cloud_account
@ -31,16 +31,11 @@ class ::DevOps::BuildsController < ApplicationController
def logs
cloud_account = @repo.dev_ops_cloud_account
result = DevOps::Drone::API.new(cloud_account.drone_token, cloud_account.drone_url, @repo.user.login, @repo.identifier, build: params[:build], stage: params[:stage], step: sync_params[:step]).logs
result = DevOps::Drone::API.new(cloud_account.drone_token, cloud_account.drone_url, @repo.user.login, @repo.identifier, build: params[:build], stage: params[:stage], step: params[:step]).logs
render json: result
end
def test_webhook
logger.info "==============已经回调成功了....."
render_ok
end
private
def find_repo
@repo = ::Repository.find params[:id]

View File

@ -50,7 +50,7 @@ class DevOps::CloudAccountsController < ApplicationController
logger.info "######### result: #{result}"
redirect_url = "#{Gitea.gitea_config[:domain]}/login/oauth/authorize?client_id=#{oauth.client_id}&redirect_uri=#{cloud_account.drone_url}/login&response_type=code"
redirect_url = "#{cloud_account.drone_url}/login&response_type=code"
logger.info "######### redirect_url: #{redirect_url}"
if result
render_ok(redirect_url: redirect_url)

View File

@ -11,23 +11,10 @@ class DevOps::Drone::Client
@rpc_secret = rpc_secret
end
def run
`docker run -d \
-v /var/run/docker.sock:/var/run/docker.sock \
-e DRONE_PRC_HOST=drone-server-#{client_id}:9000 \
-e DRONE_RPC_SECRET=#{rpc_secret} \
-e DRONE_RUNNER_NAME=#{drone_ip} \
--restart always \
--name drone-agent--#{client_id} \
--net="bridge" \
drone/drone-runner-docker:1
`
end
def generate_cmd
"docker run -d \
-v /var/run/docker.sock:/var/run/docker.sock \
-e DRONE_RPC_HOST=#{drone_ip}:9000 \
-e DRONE_RPC_HOST=#{drone_ip}:80 \
-e DRONE_RPC_SECRET=#{rpc_secret} \
-e DRONE_RUNNER_NAME=#{drone_ip} \
--restart always \

View File

@ -46,7 +46,6 @@ class DevOps::Drone::Server
-e DRONE_SERVER_HOST=#{drone_host} \
-e DRONE_SERVER_PROTO=http \
-p '80:80' \
-p '9000:9000' \
--restart=always \
--detach=true \
--name=drone-server-#{client_id} \

View File

@ -27,8 +27,7 @@ Rails.application.routes.draw do
get ':number', to: 'builds#detail', as: 'detail'
post ':number', to: 'builds#restart', as: 'restart'
delete ':number', to: 'builds#delete', as: 'delete'
get ':number/logs/:stage/:step', to: 'builds#detail', as: 'logs'
post 'test_webhook', to: 'builds#test_webhook', as: 'test_webhook'
get ':number/logs/:stage/:step', to: 'builds#logs', as: 'logs'
end
end
end