Add support for a global env from a server flag

This commit is contained in:
Ian 2020-05-18 16:48:31 +01:00
parent 6ee3adc72c
commit 070f6ea49c
4 changed files with 32 additions and 1 deletions

View file

@ -133,6 +133,10 @@ var flags = []cli.Flag{
EnvVar: "DRONE_VOLUME", EnvVar: "DRONE_VOLUME",
Name: "volume", Name: "volume",
}, },
cli.StringSliceFlag{
EnvVar: "DRONE_ENVIRONMENT",
Name: "environment",
},
cli.StringSliceFlag{ cli.StringSliceFlag{
EnvVar: "DRONE_NETWORK", EnvVar: "DRONE_NETWORK",
Name: "network", Name: "network",

View file

@ -21,6 +21,7 @@ import (
"github.com/dimfeld/httptreemux" "github.com/dimfeld/httptreemux"
"github.com/laszlocph/woodpecker/cncd/queue" "github.com/laszlocph/woodpecker/cncd/queue"
"github.com/laszlocph/woodpecker/model" "github.com/laszlocph/woodpecker/model"
"github.com/laszlocph/woodpecker/plugins/environments"
"github.com/laszlocph/woodpecker/plugins/registry" "github.com/laszlocph/woodpecker/plugins/registry"
"github.com/laszlocph/woodpecker/plugins/secrets" "github.com/laszlocph/woodpecker/plugins/secrets"
"github.com/laszlocph/woodpecker/remote" "github.com/laszlocph/woodpecker/remote"
@ -63,7 +64,7 @@ func setupRegistryService(c *cli.Context, s store.Store) model.RegistryService {
} }
func setupEnvironService(c *cli.Context, s store.Store) model.EnvironService { func setupEnvironService(c *cli.Context, s store.Store) model.EnvironService {
return nil return environments.Filesystem(c.StringSlice("environment"))
} }
func setupPubsub(c *cli.Context) {} func setupPubsub(c *cli.Context) {}

View file

@ -0,0 +1,25 @@
package environments
import (
"github.com/laszlocph/woodpecker/model"
"strings"
)
type builtin struct {
globals []*model.Environ
}
// New returns a new local registry service.
func Filesystem(params []string) model.EnvironService {
var globals []*model.Environ
for _, item := range params {
kvpair := strings.SplitN(item, ":", 2)
globals = append(globals, &model.Environ{Name: kvpair[0], Value: kvpair[1]})
}
return &builtin{globals}
}
func (b *builtin) EnvironList(repo *model.Repo) ([]*model.Environ, error) {
return b.globals, nil
}

View file

@ -0,0 +1 @@
package environments