mirror of
https://github.com/go-gitea/gitea.git
synced 2025-07-23 22:05:51 +02:00
chore(runner): update to latest proto format.
Signed-off-by: Bo-Yi.Wu <appleboy.tw@gmail.com>
This commit is contained in:
parent
f355188e12
commit
4dd135580f
@ -20,8 +20,8 @@ type Filter struct {
|
|||||||
// Scheduler schedules Build stages for execution.
|
// Scheduler schedules Build stages for execution.
|
||||||
type Scheduler interface {
|
type Scheduler interface {
|
||||||
// Schedule schedules the stage for execution.
|
// Schedule schedules the stage for execution.
|
||||||
Schedule(context.Context, *runnerv1.Stage) error
|
Schedule(context.Context, *runnerv1.Task) error
|
||||||
|
|
||||||
// Request requests the next stage scheduled for execution.
|
// Request requests the next stage scheduled for execution.
|
||||||
Request(context.Context, Filter) (*runnerv1.Stage, error)
|
Request(context.Context, Filter) (*runnerv1.Task, error)
|
||||||
}
|
}
|
||||||
|
2
go.mod
2
go.mod
@ -6,7 +6,7 @@ require (
|
|||||||
code.gitea.io/gitea-vet v0.2.2-0.20220122151748-48ebc902541b
|
code.gitea.io/gitea-vet v0.2.2-0.20220122151748-48ebc902541b
|
||||||
code.gitea.io/sdk/gitea v0.15.1
|
code.gitea.io/sdk/gitea v0.15.1
|
||||||
codeberg.org/gusted/mcaptcha v0.0.0-20220723083913-4f3072e1d570
|
codeberg.org/gusted/mcaptcha v0.0.0-20220723083913-4f3072e1d570
|
||||||
gitea.com/gitea/proto-go v0.0.0-20220921035813-6a5980d5b2a2
|
gitea.com/gitea/proto-go v0.0.0-20221010043111-8f5efb3ec51d
|
||||||
gitea.com/go-chi/binding v0.0.0-20220309004920-114340dabecb
|
gitea.com/go-chi/binding v0.0.0-20220309004920-114340dabecb
|
||||||
gitea.com/go-chi/cache v0.2.0
|
gitea.com/go-chi/cache v0.2.0
|
||||||
gitea.com/go-chi/captcha v0.0.0-20211013065431-70641c1a35d5
|
gitea.com/go-chi/captcha v0.0.0-20211013065431-70641c1a35d5
|
||||||
|
6
go.sum
6
go.sum
@ -83,8 +83,10 @@ git.sr.ht/~mariusor/go-xsd-duration v0.0.0-20220703122237-02e73435a078 h1:cliQ4H
|
|||||||
git.sr.ht/~mariusor/go-xsd-duration v0.0.0-20220703122237-02e73435a078/go.mod h1:g/V2Hjas6Z1UHUp4yIx6bATpNzJ7DYtD0FG3+xARWxs=
|
git.sr.ht/~mariusor/go-xsd-duration v0.0.0-20220703122237-02e73435a078/go.mod h1:g/V2Hjas6Z1UHUp4yIx6bATpNzJ7DYtD0FG3+xARWxs=
|
||||||
gitea.com/gitea/act v0.0.0-20221008102131-d89ab14fb580 h1:F/VSl4oP5Gqe0FQ2i6BX/ODIhBc/cxfp5p5yA8pOSb4=
|
gitea.com/gitea/act v0.0.0-20221008102131-d89ab14fb580 h1:F/VSl4oP5Gqe0FQ2i6BX/ODIhBc/cxfp5p5yA8pOSb4=
|
||||||
gitea.com/gitea/act v0.0.0-20221008102131-d89ab14fb580/go.mod h1:lpzib6X73FHLSaTqTakan1xcsCAVhlZvPSpLns7jkRo=
|
gitea.com/gitea/act v0.0.0-20221008102131-d89ab14fb580/go.mod h1:lpzib6X73FHLSaTqTakan1xcsCAVhlZvPSpLns7jkRo=
|
||||||
gitea.com/gitea/proto-go v0.0.0-20220921035813-6a5980d5b2a2 h1:SKAZ2Fnay8Yx1Yw1BSU/ATEk3/WAFL/lMXhvBBVzyu4=
|
gitea.com/gitea/proto-go v0.0.0-20221008030753-07d7bbcfb9f5 h1:tCf76mJIGJkIvFCOFy6O30diGdA5zt07EUSZangUAzk=
|
||||||
gitea.com/gitea/proto-go v0.0.0-20220921035813-6a5980d5b2a2/go.mod h1:hD8YwSHusjwjEEgubW6XFvnZuNhMZTHz6lwjfltEt/Y=
|
gitea.com/gitea/proto-go v0.0.0-20221008030753-07d7bbcfb9f5/go.mod h1:hD8YwSHusjwjEEgubW6XFvnZuNhMZTHz6lwjfltEt/Y=
|
||||||
|
gitea.com/gitea/proto-go v0.0.0-20221010043111-8f5efb3ec51d h1:/c5HiuU195m2HR7VhJV11CnwpEWWXkgYi02Z6SU37ks=
|
||||||
|
gitea.com/gitea/proto-go v0.0.0-20221010043111-8f5efb3ec51d/go.mod h1:hD8YwSHusjwjEEgubW6XFvnZuNhMZTHz6lwjfltEt/Y=
|
||||||
gitea.com/go-chi/binding v0.0.0-20220309004920-114340dabecb h1:Yy0Bxzc8R2wxiwXoG/rECGplJUSpXqCsog9PuJFgiHs=
|
gitea.com/go-chi/binding v0.0.0-20220309004920-114340dabecb h1:Yy0Bxzc8R2wxiwXoG/rECGplJUSpXqCsog9PuJFgiHs=
|
||||||
gitea.com/go-chi/binding v0.0.0-20220309004920-114340dabecb/go.mod h1:77TZu701zMXWJFvB8gvTbQ92zQ3DQq/H7l5wAEjQRKc=
|
gitea.com/go-chi/binding v0.0.0-20220309004920-114340dabecb/go.mod h1:77TZu701zMXWJFvB8gvTbQ92zQ3DQq/H7l5wAEjQRKc=
|
||||||
gitea.com/go-chi/cache v0.0.0-20210110083709-82c4c9ce2d5e/go.mod h1:k2V/gPDEtXGjjMGuBJiapffAXTv76H4snSmlJRLUhH0=
|
gitea.com/go-chi/cache v0.0.0-20210110083709-82c4c9ce2d5e/go.mod h1:k2V/gPDEtXGjjMGuBJiapffAXTv76H4snSmlJRLUhH0=
|
||||||
|
@ -35,9 +35,6 @@ type Runner struct {
|
|||||||
ID int64
|
ID int64
|
||||||
UUID string `xorm:"CHAR(36) UNIQUE"`
|
UUID string `xorm:"CHAR(36) UNIQUE"`
|
||||||
Name string `xorm:"VARCHAR(32) UNIQUE"`
|
Name string `xorm:"VARCHAR(32) UNIQUE"`
|
||||||
OS string `xorm:"VARCHAR(16) index"` // the runner running os
|
|
||||||
Arch string `xorm:"VARCHAR(16) index"` // the runner running architecture
|
|
||||||
Type string `xorm:"VARCHAR(16)"`
|
|
||||||
OwnerID int64 `xorm:"index"` // org level runner, 0 means system
|
OwnerID int64 `xorm:"index"` // org level runner, 0 means system
|
||||||
Owner *user_model.User `xorm:"-"`
|
Owner *user_model.User `xorm:"-"`
|
||||||
RepoID int64 `xorm:"index"` // repo level runner, if orgid also is zero, then it's a global
|
RepoID int64 `xorm:"index"` // repo level runner, if orgid also is zero, then it's a global
|
||||||
@ -46,9 +43,14 @@ type Runner struct {
|
|||||||
Base int // 0 native 1 docker 2 virtual machine
|
Base int // 0 native 1 docker 2 virtual machine
|
||||||
RepoRange string // glob match which repositories could use this runner
|
RepoRange string // glob match which repositories could use this runner
|
||||||
Token string
|
Token string
|
||||||
Capacity int64
|
|
||||||
LastOnline timeutil.TimeStamp `xorm:"index"`
|
// Store OS and Artch.
|
||||||
Created timeutil.TimeStamp `xorm:"created"`
|
AgentLabels []string
|
||||||
|
// Store custom labes use defined.
|
||||||
|
CustomLabels []string
|
||||||
|
|
||||||
|
LastOnline timeutil.TimeStamp `xorm:"index"`
|
||||||
|
Created timeutil.TimeStamp `xorm:"created"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (Runner) TableName() string {
|
func (Runner) TableName() string {
|
||||||
|
@ -10,7 +10,6 @@ import (
|
|||||||
|
|
||||||
"code.gitea.io/gitea/core"
|
"code.gitea.io/gitea/core"
|
||||||
bots_model "code.gitea.io/gitea/models/bots"
|
bots_model "code.gitea.io/gitea/models/bots"
|
||||||
repo_model "code.gitea.io/gitea/models/repo"
|
|
||||||
"code.gitea.io/gitea/modules/log"
|
"code.gitea.io/gitea/modules/log"
|
||||||
runnerv1 "gitea.com/gitea/proto-go/runner/v1"
|
runnerv1 "gitea.com/gitea/proto-go/runner/v1"
|
||||||
"gitea.com/gitea/proto-go/runner/v1/runnerv1connect"
|
"gitea.com/gitea/proto-go/runner/v1/runnerv1connect"
|
||||||
@ -18,6 +17,8 @@ import (
|
|||||||
"github.com/bufbuild/connect-go"
|
"github.com/bufbuild/connect-go"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var _ runnerv1connect.RunnerServiceClient = (*Service)(nil)
|
||||||
|
|
||||||
type Service struct {
|
type Service struct {
|
||||||
Scheduler core.Scheduler
|
Scheduler core.Scheduler
|
||||||
|
|
||||||
@ -38,25 +39,24 @@ func (s *Service) Register(
|
|||||||
return nil, errors.New("missing runner token")
|
return nil, errors.New("missing runner token")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: Get token data from runner_token table
|
||||||
runner, err := bots_model.GetRunnerByToken(token)
|
runner, err := bots_model.GetRunnerByToken(token)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.New("runner not found")
|
return nil, errors.New("runner not found")
|
||||||
}
|
}
|
||||||
|
|
||||||
// update runner information
|
// update runner information
|
||||||
runner.Arch = req.Msg.Arch
|
runner.AgentLabels = req.Msg.AgentLabels
|
||||||
runner.OS = req.Msg.Os
|
runner.CustomLabels = req.Msg.CustomLabels
|
||||||
runner.Capacity = req.Msg.Capacity
|
runner.Name = req.Msg.Name
|
||||||
if err := bots_model.UpdateRunner(ctx, runner, []string{"arch", "os", "capacity"}...); err != nil {
|
if err := bots_model.UpdateRunner(ctx, runner, []string{"name", "agent_labels", "custom_labels"}...); err != nil {
|
||||||
return nil, errors.New("can't update runner")
|
return nil, errors.New("can't update runner")
|
||||||
}
|
}
|
||||||
|
|
||||||
res := connect.NewResponse(&runnerv1.RegisterResponse{
|
res := connect.NewResponse(&runnerv1.RegisterResponse{
|
||||||
Runner: &runnerv1.Runner{
|
Runner: &runnerv1.Runner{
|
||||||
Uuid: runner.UUID,
|
Uuid: runner.UUID,
|
||||||
Os: req.Msg.Os,
|
Token: runner.Token,
|
||||||
Arch: req.Msg.Arch,
|
|
||||||
Capacity: req.Msg.Capacity,
|
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -64,15 +64,13 @@ func (s *Service) Register(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Request requests the next available build stage for execution.
|
// Request requests the next available build stage for execution.
|
||||||
func (s *Service) Request(
|
func (s *Service) FetchTask(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
req *connect.Request[runnerv1.RequestRequest],
|
req *connect.Request[runnerv1.FetchTaskRequest],
|
||||||
) (*connect.Response[runnerv1.RequestResponse], error) {
|
) (*connect.Response[runnerv1.FetchTaskResponse], error) {
|
||||||
log.Debug("manager: request queue item")
|
log.Debug("manager: request queue item")
|
||||||
|
|
||||||
stage, err := s.Scheduler.Request(ctx, core.Filter{
|
task, err := s.Scheduler.Request(ctx, core.Filter{
|
||||||
Kind: req.Msg.Kind,
|
|
||||||
Type: req.Msg.Type,
|
|
||||||
OS: req.Msg.Os,
|
OS: req.Msg.Os,
|
||||||
Arch: req.Msg.Arch,
|
Arch: req.Msg.Arch,
|
||||||
})
|
})
|
||||||
@ -85,86 +83,29 @@ func (s *Service) Request(
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
res := connect.NewResponse(&runnerv1.RequestResponse{
|
// TODO: update task and check data lock
|
||||||
Stage: stage,
|
task.Machine = req.Msg.Os
|
||||||
|
|
||||||
|
res := connect.NewResponse(&runnerv1.FetchTaskResponse{
|
||||||
|
Task: task,
|
||||||
})
|
})
|
||||||
return res, nil
|
return res, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Details fetches build details
|
// UpdateTask updates the task status.
|
||||||
func (s *Service) Detail(
|
func (s *Service) UpdateTask(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
req *connect.Request[runnerv1.DetailRequest],
|
req *connect.Request[runnerv1.UpdateTaskRequest],
|
||||||
) (*connect.Response[runnerv1.DetailResponse], error) {
|
) (*connect.Response[runnerv1.UpdateTaskResponse], error) {
|
||||||
log.Info("stag id %d", req.Msg.Stage.Id)
|
res := connect.NewResponse(&runnerv1.UpdateTaskResponse{})
|
||||||
|
|
||||||
// fetch stage data
|
|
||||||
stage, err := bots_model.GetStageByID(req.Msg.Stage.Id)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
stage.Machine = req.Msg.Stage.Machine
|
|
||||||
stage.Status = core.StatusPending
|
|
||||||
|
|
||||||
count, err := bots_model.UpdateBuildStage(stage, "machine", "status")
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
if count != 1 {
|
|
||||||
return nil, core.ErrDataLock
|
|
||||||
}
|
|
||||||
|
|
||||||
// fetch build data
|
|
||||||
build, err := bots_model.GetBuildByID(stage.BuildID)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
// fetch repo data
|
|
||||||
repo, err := repo_model.GetRepositoryByID(build.RepoID)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
res := connect.NewResponse(&runnerv1.DetailResponse{
|
|
||||||
Stage: &runnerv1.Stage{
|
|
||||||
Id: stage.ID,
|
|
||||||
BuildId: stage.BuildID,
|
|
||||||
Name: stage.Name,
|
|
||||||
Kind: stage.Kind,
|
|
||||||
Type: stage.Type,
|
|
||||||
Status: string(stage.Status),
|
|
||||||
Started: int64(stage.Started),
|
|
||||||
Stopped: int64(stage.Stopped),
|
|
||||||
Machine: stage.Machine,
|
|
||||||
},
|
|
||||||
Build: &runnerv1.Build{
|
|
||||||
Id: build.ID,
|
|
||||||
Name: build.Name,
|
|
||||||
},
|
|
||||||
Repo: &runnerv1.Repo{
|
|
||||||
Id: repo.ID,
|
|
||||||
Name: repo.Name,
|
|
||||||
},
|
|
||||||
})
|
|
||||||
return res, nil
|
return res, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update updates the build stage.
|
// UpdateLog uploads log of the task.
|
||||||
func (s *Service) Update(
|
func (s *Service) UpdateLog(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
req *connect.Request[runnerv1.UpdateRequest],
|
req *connect.Request[runnerv1.UpdateLogRequest],
|
||||||
) (*connect.Response[runnerv1.UpdateResponse], error) {
|
) (*connect.Response[runnerv1.UpdateLogResponse], error) {
|
||||||
res := connect.NewResponse(&runnerv1.UpdateResponse{})
|
res := connect.NewResponse(&runnerv1.UpdateLogResponse{})
|
||||||
return res, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// UpdateStep updates the build step.
|
|
||||||
func (s *Service) UpdateStep(
|
|
||||||
ctx context.Context,
|
|
||||||
req *connect.Request[runnerv1.UpdateStepRequest],
|
|
||||||
) (*connect.Response[runnerv1.UpdateStepResponse], error) {
|
|
||||||
res := connect.NewResponse(&runnerv1.UpdateStepResponse{})
|
|
||||||
return res, nil
|
return res, nil
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,7 @@ type worker struct {
|
|||||||
typ string
|
typ string
|
||||||
os string
|
os string
|
||||||
arch string
|
arch string
|
||||||
channel chan *runnerv1.Stage
|
channel chan *runnerv1.Task
|
||||||
}
|
}
|
||||||
|
|
||||||
type queue struct {
|
type queue struct {
|
||||||
@ -32,7 +32,7 @@ type queue struct {
|
|||||||
ctx context.Context
|
ctx context.Context
|
||||||
}
|
}
|
||||||
|
|
||||||
func (q *queue) Schedule(ctx context.Context, stage *runnerv1.Stage) error {
|
func (q *queue) Schedule(ctx context.Context, stage *runnerv1.Task) error {
|
||||||
select {
|
select {
|
||||||
case q.ready <- struct{}{}:
|
case q.ready <- struct{}{}:
|
||||||
default:
|
default:
|
||||||
@ -40,13 +40,13 @@ func (q *queue) Schedule(ctx context.Context, stage *runnerv1.Stage) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (q *queue) Request(ctx context.Context, params core.Filter) (*runnerv1.Stage, error) {
|
func (q *queue) Request(ctx context.Context, params core.Filter) (*runnerv1.Task, error) {
|
||||||
w := &worker{
|
w := &worker{
|
||||||
kind: params.Kind,
|
kind: params.Kind,
|
||||||
typ: params.Type,
|
typ: params.Type,
|
||||||
os: params.OS,
|
os: params.OS,
|
||||||
arch: params.Arch,
|
arch: params.Arch,
|
||||||
channel: make(chan *runnerv1.Stage),
|
channel: make(chan *runnerv1.Task),
|
||||||
}
|
}
|
||||||
q.Lock()
|
q.Lock()
|
||||||
q.workers[w] = struct{}{}
|
q.workers[w] = struct{}{}
|
||||||
@ -123,15 +123,15 @@ func (q *queue) signal(ctx context.Context) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
stage := &runnerv1.Stage{
|
stage := &runnerv1.Task{
|
||||||
Id: item.ID,
|
Id: item.ID,
|
||||||
BuildId: item.BuildID,
|
// BuildId: item.BuildID,
|
||||||
Name: item.Name,
|
// Name: item.Name,
|
||||||
Kind: item.Name,
|
// Kind: item.Name,
|
||||||
Type: item.Type,
|
// Type: item.Type,
|
||||||
Status: string(item.Status),
|
// Status: string(item.Status),
|
||||||
Started: int64(item.Started),
|
// Started: int64(item.Started),
|
||||||
Stopped: int64(item.Stopped),
|
// Stopped: int64(item.Stopped),
|
||||||
}
|
}
|
||||||
|
|
||||||
w.channel <- stage
|
w.channel <- stage
|
||||||
|
Loading…
x
Reference in New Issue
Block a user