Add --labels support in docker example (#51)
This commit is contained in:
@@ -40,6 +40,7 @@ You'll then need:
|
||||
|------|----------|-------------|
|
||||
| `--url` | Yes | Registration target (org, repo, or enterprise URL, e.g. `https://github.com/org/repo`). |
|
||||
| `--name` | Yes | Runner scale set name (must be unique within the runner group). |
|
||||
| `--labels` | No | Labels for workflow targeting (comma-separated or repeated). Defaults to `--name` if not provided. |
|
||||
| `--max-runners` | No | Upper bound of concurrently provisioned runners (default 10). |
|
||||
| `--min-runners` | No | Lower bound to maintain (default 0). |
|
||||
| `--runner-group` | No | Runner group name (default `default`). |
|
||||
|
||||
@@ -15,6 +15,7 @@ type Config struct {
|
||||
MaxRunners int
|
||||
MinRunners int
|
||||
ScaleSetName string
|
||||
Labels []string
|
||||
RunnerGroup string
|
||||
GitHubApp scaleset.GitHubAppAuth
|
||||
Token string
|
||||
@@ -47,6 +48,11 @@ func (c *Config) Validate() error {
|
||||
if c.ScaleSetName == "" {
|
||||
return fmt.Errorf("scale set name is required")
|
||||
}
|
||||
for i, label := range c.Labels {
|
||||
if strings.TrimSpace(label) == "" {
|
||||
return fmt.Errorf("label at index %d is empty", i)
|
||||
}
|
||||
}
|
||||
if c.MaxRunners < c.MinRunners {
|
||||
return fmt.Errorf("max runners cannot be less than min-runners")
|
||||
}
|
||||
@@ -120,3 +126,16 @@ func (c *Config) Logger() *slog.Logger {
|
||||
return slog.New(slog.DiscardHandler)
|
||||
}
|
||||
}
|
||||
|
||||
// BuildLabels returns the labels to use for the runner scale set.
|
||||
// If custom labels are provided, those are used; otherwise, the scale set name is used as the label.
|
||||
func (c *Config) BuildLabels() []scaleset.Label {
|
||||
if len(c.Labels) > 0 {
|
||||
labels := make([]scaleset.Label, len(c.Labels))
|
||||
for i, name := range c.Labels {
|
||||
labels[i] = scaleset.Label{Name: strings.TrimSpace(name)}
|
||||
}
|
||||
return labels
|
||||
}
|
||||
return []scaleset.Label{{Name: c.ScaleSetName}}
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ func init() {
|
||||
flags.IntVar(&cfg.MaxRunners, "max-runners", 10, "Maximum number of runners")
|
||||
flags.IntVar(&cfg.MinRunners, "min-runners", 0, "Minimum number of runners")
|
||||
flags.StringVar(&cfg.ScaleSetName, "name", "", "REQUIRED: Name of your scale set")
|
||||
flags.StringSliceVar(&cfg.Labels, "labels", nil, "Labels for workflow targeting (comma-separated or repeated). Defaults to --name if not provided.")
|
||||
flags.StringVar(&cfg.RunnerGroup, "runner-group", scaleset.DefaultRunnerGroup, "Name of the runner group your scale set should belong to")
|
||||
flags.StringVar(&cfg.GitHubApp.ClientID, "app-client-id", "", "GitHub App client id")
|
||||
flags.Int64Var(&cfg.GitHubApp.InstallationID, "app-installation-id", 0, "GitHub App installation ID")
|
||||
@@ -77,11 +78,7 @@ func run(ctx context.Context, c Config) error {
|
||||
scaleSet, err := scalesetClient.CreateRunnerScaleSet(ctx, &scaleset.RunnerScaleSet{
|
||||
Name: c.ScaleSetName,
|
||||
RunnerGroupID: runnerGroupID,
|
||||
Labels: []scaleset.Label{
|
||||
{
|
||||
Name: c.ScaleSetName,
|
||||
},
|
||||
},
|
||||
Labels: c.BuildLabels(),
|
||||
RunnerSetting: scaleset.RunnerSetting{
|
||||
DisableUpdate: true,
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user