add forgeinstance

This commit is contained in:
Lunny Xiao 2022-10-16 23:51:53 +08:00 committed by Jason Song
parent 9c7d2be7c6
commit 378966e45f
7 changed files with 28 additions and 22 deletions

View File

@ -20,11 +20,11 @@ import (
"golang.org/x/sync/errgroup"
)
func runDaemon(ctx context.Context, task *runtime.Task) func(cmd *cobra.Command, args []string) error {
func runDaemon(ctx context.Context, envFile string) func(cmd *cobra.Command, args []string) error {
return func(cmd *cobra.Command, args []string) error {
log.Infoln("Starting runner daemon")
_ = godotenv.Load(task.Input.EnvFile)
_ = godotenv.Load(envFile)
cfg, err := config.FromEnviron()
if err != nil {
log.WithError(err).
@ -101,9 +101,10 @@ func runDaemon(ctx context.Context, task *runtime.Task) func(cmd *cobra.Command,
)
runner := &runtime.Runner{
Client: cli,
Machine: cfg.Runner.Name,
Environ: cfg.Runner.Environ,
Client: cli,
Machine: cfg.Runner.Name,
ForgeInstance: cfg.ForgeInstance,
Environ: cfg.Runner.Environ,
}
poller := poller.New(

View File

@ -33,7 +33,7 @@ func initLogging(cfg config.Config) {
}
func Execute(ctx context.Context) {
task := runtime.NewTask(0, nil)
task := runtime.NewTask("gitea", 0, nil)
// ./act_runner
rootCmd := &cobra.Command{
@ -54,7 +54,7 @@ func Execute(ctx context.Context) {
Aliases: []string{"daemon"},
Use: "execute runner daemon",
Args: cobra.MaximumNArgs(1),
RunE: runDaemon(ctx, task),
RunE: runDaemon(ctx, task.Input.EnvFile),
}
// add all command
rootCmd.AddCommand(daemonCmd)

View File

@ -16,11 +16,12 @@ import (
type (
// Config provides the system configuration.
Config struct {
Debug bool `envconfig:"GITEA_DEBUG"`
Trace bool `envconfig:"GITEA_TRACE"`
Client Client
Runner Runner
Platform Platform
Debug bool `envconfig:"GITEA_DEBUG"`
Trace bool `envconfig:"GITEA_TRACE"`
Client Client
Runner Runner
Platform Platform
ForgeInstance string
}
Client struct {
@ -68,6 +69,7 @@ func FromEnviron() (Config, error) {
if runner.UUID != "" {
cfg.Runner.UUID = runner.UUID
}
cfg.ForgeInstance = runner.ForgeInstance
}
// runner config

View File

@ -4,8 +4,9 @@ const UUIDHeader = "x-runner-uuid"
// Runner struct
type Runner struct {
ID int64 `json:"id"`
UUID string `json:"uuid"`
Name string `json:"name"`
Token string `json:"token"`
ID int64 `json:"id"`
UUID string `json:"uuid"`
Name string `json:"name"`
Token string `json:"token"`
ForgeInstance string `json:"forge_instance"`
}

View File

@ -46,6 +46,7 @@ func (p *Register) Register(ctx context.Context, cfg config.Runner) (*core.Runne
UUID: resp.Msg.Runner.Uuid,
Name: resp.Msg.Runner.Name,
Token: resp.Msg.Runner.Token,
// ForgeInstance: resp.Msg.Runner.ForgeInstance, TODO: add me
}
file, err := json.MarshalIndent(data, "", " ")

View File

@ -12,9 +12,10 @@ import (
// Runner runs the pipeline.
type Runner struct {
Machine string
Environ map[string]string
Client client.Client
Machine string
ForgeInstance string
Environ map[string]string
Client client.Client
}
// Run runs the pipeline stage.
@ -48,5 +49,5 @@ func (s *Runner) Run(ctx context.Context, task *runnerv1.Task) error {
l.Info("update runner status to idle")
}()
return NewTask(task.Id, s.Client).Run(ctx, task)
return NewTask(s.ForgeInstance, task.Id, s.Client).Run(ctx, task)
}

View File

@ -86,11 +86,11 @@ type Task struct {
}
// NewTask creates a new task
func NewTask(buildID int64, client client.Client) *Task {
func NewTask(forgeInstance string, buildID int64, client client.Client) *Task {
task := &Task{
Input: &TaskInput{
reuseContainers: true,
ForgeInstance: "gitea",
ForgeInstance: forgeInstance,
},
BuildID: buildID,