add forgeinstance
This commit is contained in:
parent
9c7d2be7c6
commit
378966e45f
|
@ -20,11 +20,11 @@ import (
|
||||||
"golang.org/x/sync/errgroup"
|
"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 {
|
return func(cmd *cobra.Command, args []string) error {
|
||||||
log.Infoln("Starting runner daemon")
|
log.Infoln("Starting runner daemon")
|
||||||
|
|
||||||
_ = godotenv.Load(task.Input.EnvFile)
|
_ = godotenv.Load(envFile)
|
||||||
cfg, err := config.FromEnviron()
|
cfg, err := config.FromEnviron()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.WithError(err).
|
log.WithError(err).
|
||||||
|
@ -101,9 +101,10 @@ func runDaemon(ctx context.Context, task *runtime.Task) func(cmd *cobra.Command,
|
||||||
)
|
)
|
||||||
|
|
||||||
runner := &runtime.Runner{
|
runner := &runtime.Runner{
|
||||||
Client: cli,
|
Client: cli,
|
||||||
Machine: cfg.Runner.Name,
|
Machine: cfg.Runner.Name,
|
||||||
Environ: cfg.Runner.Environ,
|
ForgeInstance: cfg.ForgeInstance,
|
||||||
|
Environ: cfg.Runner.Environ,
|
||||||
}
|
}
|
||||||
|
|
||||||
poller := poller.New(
|
poller := poller.New(
|
||||||
|
|
|
@ -33,7 +33,7 @@ func initLogging(cfg config.Config) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func Execute(ctx context.Context) {
|
func Execute(ctx context.Context) {
|
||||||
task := runtime.NewTask(0, nil)
|
task := runtime.NewTask("gitea", 0, nil)
|
||||||
|
|
||||||
// ./act_runner
|
// ./act_runner
|
||||||
rootCmd := &cobra.Command{
|
rootCmd := &cobra.Command{
|
||||||
|
@ -54,7 +54,7 @@ func Execute(ctx context.Context) {
|
||||||
Aliases: []string{"daemon"},
|
Aliases: []string{"daemon"},
|
||||||
Use: "execute runner daemon",
|
Use: "execute runner daemon",
|
||||||
Args: cobra.MaximumNArgs(1),
|
Args: cobra.MaximumNArgs(1),
|
||||||
RunE: runDaemon(ctx, task),
|
RunE: runDaemon(ctx, task.Input.EnvFile),
|
||||||
}
|
}
|
||||||
// add all command
|
// add all command
|
||||||
rootCmd.AddCommand(daemonCmd)
|
rootCmd.AddCommand(daemonCmd)
|
||||||
|
|
|
@ -16,11 +16,12 @@ import (
|
||||||
type (
|
type (
|
||||||
// Config provides the system configuration.
|
// Config provides the system configuration.
|
||||||
Config struct {
|
Config struct {
|
||||||
Debug bool `envconfig:"GITEA_DEBUG"`
|
Debug bool `envconfig:"GITEA_DEBUG"`
|
||||||
Trace bool `envconfig:"GITEA_TRACE"`
|
Trace bool `envconfig:"GITEA_TRACE"`
|
||||||
Client Client
|
Client Client
|
||||||
Runner Runner
|
Runner Runner
|
||||||
Platform Platform
|
Platform Platform
|
||||||
|
ForgeInstance string
|
||||||
}
|
}
|
||||||
|
|
||||||
Client struct {
|
Client struct {
|
||||||
|
@ -68,6 +69,7 @@ func FromEnviron() (Config, error) {
|
||||||
if runner.UUID != "" {
|
if runner.UUID != "" {
|
||||||
cfg.Runner.UUID = runner.UUID
|
cfg.Runner.UUID = runner.UUID
|
||||||
}
|
}
|
||||||
|
cfg.ForgeInstance = runner.ForgeInstance
|
||||||
}
|
}
|
||||||
|
|
||||||
// runner config
|
// runner config
|
||||||
|
|
|
@ -4,8 +4,9 @@ const UUIDHeader = "x-runner-uuid"
|
||||||
|
|
||||||
// Runner struct
|
// Runner struct
|
||||||
type Runner struct {
|
type Runner struct {
|
||||||
ID int64 `json:"id"`
|
ID int64 `json:"id"`
|
||||||
UUID string `json:"uuid"`
|
UUID string `json:"uuid"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Token string `json:"token"`
|
Token string `json:"token"`
|
||||||
|
ForgeInstance string `json:"forge_instance"`
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,6 +46,7 @@ func (p *Register) Register(ctx context.Context, cfg config.Runner) (*core.Runne
|
||||||
UUID: resp.Msg.Runner.Uuid,
|
UUID: resp.Msg.Runner.Uuid,
|
||||||
Name: resp.Msg.Runner.Name,
|
Name: resp.Msg.Runner.Name,
|
||||||
Token: resp.Msg.Runner.Token,
|
Token: resp.Msg.Runner.Token,
|
||||||
|
// ForgeInstance: resp.Msg.Runner.ForgeInstance, TODO: add me
|
||||||
}
|
}
|
||||||
|
|
||||||
file, err := json.MarshalIndent(data, "", " ")
|
file, err := json.MarshalIndent(data, "", " ")
|
||||||
|
|
|
@ -12,9 +12,10 @@ import (
|
||||||
|
|
||||||
// Runner runs the pipeline.
|
// Runner runs the pipeline.
|
||||||
type Runner struct {
|
type Runner struct {
|
||||||
Machine string
|
Machine string
|
||||||
Environ map[string]string
|
ForgeInstance string
|
||||||
Client client.Client
|
Environ map[string]string
|
||||||
|
Client client.Client
|
||||||
}
|
}
|
||||||
|
|
||||||
// Run runs the pipeline stage.
|
// 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")
|
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)
|
||||||
}
|
}
|
||||||
|
|
|
@ -86,11 +86,11 @@ type Task struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewTask creates a new task
|
// 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{
|
task := &Task{
|
||||||
Input: &TaskInput{
|
Input: &TaskInput{
|
||||||
reuseContainers: true,
|
reuseContainers: true,
|
||||||
ForgeInstance: "gitea",
|
ForgeInstance: forgeInstance,
|
||||||
},
|
},
|
||||||
BuildID: buildID,
|
BuildID: buildID,
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue