mirror of
https://gitea.com/gitea/act_runner.git
synced 2025-12-18 03:54:48 +00:00
Allow configuration of default platform if no runs-on labels match
This commit is contained in:
@@ -206,7 +206,7 @@ func (r *Runner) run(ctx context.Context, task *runnerv1.Task, reporter *report.
|
|||||||
ContainerDaemonSocket: r.cfg.Container.DockerHost,
|
ContainerDaemonSocket: r.cfg.Container.DockerHost,
|
||||||
Privileged: r.cfg.Container.Privileged,
|
Privileged: r.cfg.Container.Privileged,
|
||||||
DefaultActionInstance: taskContext["gitea_default_actions_url"].GetStringValue(),
|
DefaultActionInstance: taskContext["gitea_default_actions_url"].GetStringValue(),
|
||||||
PlatformPicker: r.labels.PickPlatform,
|
PlatformPicker: r.pickPlatform,
|
||||||
Vars: task.Vars,
|
Vars: task.Vars,
|
||||||
ValidVolumes: r.cfg.Container.ValidVolumes,
|
ValidVolumes: r.cfg.Container.ValidVolumes,
|
||||||
InsecureSkipTLS: r.cfg.Runner.Insecure,
|
InsecureSkipTLS: r.cfg.Runner.Insecure,
|
||||||
@@ -238,3 +238,11 @@ func (r *Runner) Declare(ctx context.Context, labels []string) (*connect.Respons
|
|||||||
Labels: labels,
|
Labels: labels,
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (r *Runner) pickPlatform(labels []string) string {
|
||||||
|
platform := r.labels.PickPlatform(labels)
|
||||||
|
if platform == "" {
|
||||||
|
platform = r.cfg.Runner.DefaultPlatform
|
||||||
|
}
|
||||||
|
return platform
|
||||||
|
}
|
||||||
|
|||||||
@@ -41,6 +41,8 @@ runner:
|
|||||||
- "ubuntu-latest:docker://gitea/runner-images:ubuntu-latest"
|
- "ubuntu-latest:docker://gitea/runner-images:ubuntu-latest"
|
||||||
- "ubuntu-22.04:docker://gitea/runner-images:ubuntu-22.04"
|
- "ubuntu-22.04:docker://gitea/runner-images:ubuntu-22.04"
|
||||||
- "ubuntu-20.04:docker://gitea/runner-images:ubuntu-20.04"
|
- "ubuntu-20.04:docker://gitea/runner-images:ubuntu-20.04"
|
||||||
|
# If no labels match the job's runs-on, this will be used
|
||||||
|
default_platform: "gitea/runner-images:ubuntu-latest"
|
||||||
|
|
||||||
cache:
|
cache:
|
||||||
# Enable cache server to use actions/cache.
|
# Enable cache server to use actions/cache.
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ type Runner struct {
|
|||||||
FetchTimeout time.Duration `yaml:"fetch_timeout"` // FetchTimeout specifies the timeout duration for fetching resources.
|
FetchTimeout time.Duration `yaml:"fetch_timeout"` // FetchTimeout specifies the timeout duration for fetching resources.
|
||||||
FetchInterval time.Duration `yaml:"fetch_interval"` // FetchInterval specifies the interval duration for fetching resources.
|
FetchInterval time.Duration `yaml:"fetch_interval"` // FetchInterval specifies the interval duration for fetching resources.
|
||||||
Labels []string `yaml:"labels"` // Labels specify the labels of the runner. Labels are declared on each startup
|
Labels []string `yaml:"labels"` // Labels specify the labels of the runner. Labels are declared on each startup
|
||||||
|
DefaultPlatform string `yaml:"default_platform"` // DefaultPlatform specify the image to be used if no runs-on matches our labels
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cache represents the configuration for caching.
|
// Cache represents the configuration for caching.
|
||||||
|
|||||||
@@ -79,7 +79,7 @@ func (l Labels) PickPlatform(runsOn []string) string {
|
|||||||
// So the runner receives a task with a label that the runner doesn't have,
|
// So the runner receives a task with a label that the runner doesn't have,
|
||||||
// it happens when the user have edited the label of the runner in the web UI.
|
// it happens when the user have edited the label of the runner in the web UI.
|
||||||
// TODO: it may be not correct, what if the runner is used as host mode only?
|
// TODO: it may be not correct, what if the runner is used as host mode only?
|
||||||
return "gitea/runner-images:ubuntu-latest"
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l Labels) Names() []string {
|
func (l Labels) Names() []string {
|
||||||
|
|||||||
Reference in New Issue
Block a user