1
1
mirror of https://github.com/go-gitea/gitea synced 2025-11-01 03:48:24 +00:00

chore(runner): support register

Signed-off-by: Bo-Yi.Wu <appleboy.tw@gmail.com>
This commit is contained in:
Bo-Yi.Wu
2022-08-28 13:30:30 +08:00
committed by Jason Song
parent c10414a018
commit e05f224d19
4 changed files with 78 additions and 17 deletions

View File

@@ -6,27 +6,55 @@ package runner
import (
"context"
"errors"
bots_model "code.gitea.io/gitea/models/bots"
"code.gitea.io/gitea/modules/log"
runnerv1 "gitea.com/gitea/proto-go/runner/v1"
"gitea.com/gitea/proto-go/runner/v1/runnerv1connect"
"github.com/bufbuild/connect-go"
)
type Service struct{}
type Service struct {
runnerv1connect.UnimplementedRunnerServiceHandler
}
func (s *Service) Connect(
func (s *Service) Register(
ctx context.Context,
req *connect.Request[runnerv1.ConnectRequest],
) (*connect.Response[runnerv1.ConnectResponse], error) {
req *connect.Request[runnerv1.RegisterRequest],
) (*connect.Response[runnerv1.RegisterResponse], error) {
log.Info("Request headers: %v", req.Header())
res := connect.NewResponse(&runnerv1.ConnectResponse{
Stage: &runnerv1.Stage{
RunnerUuid: "foobar",
BuildUuid: "foobar",
token := req.Header().Get("X-Runner-Token")
log.Info("token: %v", token)
if token == "" {
return nil, errors.New("missing runner token")
}
runner, err := bots_model.GetRunnerByToken(token)
if err != nil {
return nil, errors.New("runner not found")
}
// update runner information
runner.Arch = req.Msg.Arch
runner.OS = req.Msg.Os
runner.Capacity = req.Msg.Capacity
if err := bots_model.UpdateRunner(ctx, runner, []string{"arch", "os", "capacity"}...); err != nil {
return nil, errors.New("can't update runner")
}
res := connect.NewResponse(&runnerv1.RegisterResponse{
Runner: &runnerv1.Runner{
Uuid: runner.UUID,
Os: req.Msg.Os,
Arch: req.Msg.Arch,
Capacity: req.Msg.Capacity,
},
})
res.Header().Set("Gitea-Version", "runnerv1")
return res, nil
}