Add agent tagging / filtering for pipelines (#902)

Officially support labels for pipelines and agents to improve pipeline picking. 

* add pipeline labels
* update, improve docs  and add migration
* update proto file

---
closes #304 & #860
This commit is contained in:
Anbraten
2022-05-31 01:12:18 +02:00
committed by GitHub
parent 56a55842f6
commit e79ad00826
44 changed files with 385 additions and 1218 deletions

View File

@@ -20,6 +20,7 @@ import (
"net/http"
"os"
"runtime"
"strings"
"sync"
"github.com/rs/zerolog"
@@ -39,18 +40,26 @@ import (
)
func loop(c *cli.Context) error {
filter := rpc.Filter{
Labels: map[string]string{
"platform": runtime.GOOS + "/" + runtime.GOARCH,
},
Expr: c.String("filter"),
}
hostname := c.String("hostname")
if len(hostname) == 0 {
hostname, _ = os.Hostname()
}
labels := map[string]string{
"hostname": hostname,
"platform": runtime.GOOS + "/" + runtime.GOARCH,
"repo": "*", // allow all repos by default
}
for _, v := range c.StringSlice("filter-labels") {
parts := strings.SplitN(v, "=", 2)
labels[parts[0]] = parts[1]
}
filter := rpc.Filter{
Labels: labels,
}
if c.Bool("pretty") {
log.Logger = log.Output(
zerolog.ConsoleWriter{

View File

@@ -72,10 +72,10 @@ var flags = []cli.Flag{
Name: "hostname",
Usage: "agent hostname",
},
&cli.StringFlag{
EnvVars: []string{"WOODPECKER_FILTER"},
&cli.StringSliceFlag{
EnvVars: []string{"WOODPECKER_FILTER_LABELS"},
Name: "filter",
Usage: "filter expression to restrict builds by label",
Usage: "List of labels to filter tasks on. An agent must be assigned every tag listed in a task to be selected.",
},
&cli.IntFlag{
EnvVars: []string{"WOODPECKER_MAX_PROCS"},