mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2024-11-22 09:51:01 +00:00
Support more addon types (#2984)
Actually support all types that can be possible. Closes https://github.com/woodpecker-ci/woodpecker/discussions/2520
This commit is contained in:
parent
2b1e5f35de
commit
04d1f9ff5f
6 changed files with 91 additions and 25 deletions
|
@ -42,7 +42,6 @@ import (
|
|||
woodpeckerGrpcServer "go.woodpecker-ci.org/woodpecker/v2/server/grpc"
|
||||
"go.woodpecker-ci.org/woodpecker/v2/server/logging"
|
||||
"go.woodpecker-ci.org/woodpecker/v2/server/model"
|
||||
"go.woodpecker-ci.org/woodpecker/v2/server/plugins/config"
|
||||
"go.woodpecker-ci.org/woodpecker/v2/server/plugins/permissions"
|
||||
"go.woodpecker-ci.org/woodpecker/v2/server/pubsub"
|
||||
"go.woodpecker-ci.org/woodpecker/v2/server/router"
|
||||
|
@ -90,7 +89,7 @@ func run(c *cli.Context) error {
|
|||
|
||||
_store, err := setupStore(c)
|
||||
if err != nil {
|
||||
log.Fatal().Err(err).Msg("cant't setup database store")
|
||||
log.Fatal().Err(err).Msg("can't setup database store")
|
||||
}
|
||||
defer func() {
|
||||
if err := _store.Close(); err != nil {
|
||||
|
@ -98,7 +97,10 @@ func run(c *cli.Context) error {
|
|||
}
|
||||
}()
|
||||
|
||||
setupEvilGlobals(c, _store, _forge)
|
||||
err = setupEvilGlobals(c, _store, _forge)
|
||||
if err != nil {
|
||||
log.Fatal().Err(err).Msg("can't setup globals")
|
||||
}
|
||||
|
||||
var g errgroup.Group
|
||||
|
||||
|
@ -266,7 +268,7 @@ func run(c *cli.Context) error {
|
|||
return g.Wait()
|
||||
}
|
||||
|
||||
func setupEvilGlobals(c *cli.Context, v store.Store, f forge.Forge) {
|
||||
func setupEvilGlobals(c *cli.Context, v store.Store, f forge.Forge) error {
|
||||
// forge
|
||||
server.Config.Services.Forge = f
|
||||
server.Config.Services.Timeout = c.Duration("forge-timeout")
|
||||
|
@ -275,7 +277,11 @@ func setupEvilGlobals(c *cli.Context, v store.Store, f forge.Forge) {
|
|||
server.Config.Services.Queue = setupQueue(c, v)
|
||||
server.Config.Services.Logs = logging.New()
|
||||
server.Config.Services.Pubsub = pubsub.New()
|
||||
server.Config.Services.Registries = setupRegistryService(c, v)
|
||||
var err error
|
||||
server.Config.Services.Registries, err = setupRegistryService(c, v)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// TODO(1544): fix encrypted store
|
||||
// // encryption
|
||||
|
@ -285,15 +291,21 @@ func setupEvilGlobals(c *cli.Context, v store.Store, f forge.Forge) {
|
|||
// log.Fatal().Err(err).Msg("could not create encryption service")
|
||||
// }
|
||||
// server.Config.Services.Secrets = setupSecretService(c, encryptedSecretStore)
|
||||
server.Config.Services.Secrets = setupSecretService(c, v)
|
||||
|
||||
server.Config.Services.Environ = setupEnvironService(c, v)
|
||||
server.Config.Services.Secrets, err = setupSecretService(c, v)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
server.Config.Services.Environ, err = setupEnvironService(c, v)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
server.Config.Services.Membership = setupMembershipService(c, f)
|
||||
|
||||
server.Config.Services.SignaturePrivateKey, server.Config.Services.SignaturePublicKey = setupSignatureKeys(v)
|
||||
|
||||
if endpoint := c.String("config-service-endpoint"); endpoint != "" {
|
||||
server.Config.Services.ConfigService = config.NewHTTP(endpoint, server.Config.Services.SignaturePrivateKey)
|
||||
server.Config.Services.ConfigService, err = setupConfigService(c)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// authentication
|
||||
|
@ -368,4 +380,5 @@ func setupEvilGlobals(c *cli.Context, v store.Store, f forge.Forge) {
|
|||
server.Config.Permissions.Admins = permissions.NewAdmins(c.StringSlice("admin"))
|
||||
server.Config.Permissions.Orgs = permissions.NewOrgs(c.StringSlice("orgs"))
|
||||
server.Config.Permissions.OwnersAllowlist = permissions.NewOwnersAllowlist(c.StringSlice("repo-owners"))
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -42,6 +42,7 @@ import (
|
|||
"go.woodpecker-ci.org/woodpecker/v2/server/forge/github"
|
||||
"go.woodpecker-ci.org/woodpecker/v2/server/forge/gitlab"
|
||||
"go.woodpecker-ci.org/woodpecker/v2/server/model"
|
||||
"go.woodpecker-ci.org/woodpecker/v2/server/plugins/config"
|
||||
"go.woodpecker-ci.org/woodpecker/v2/server/plugins/environments"
|
||||
"go.woodpecker-ci.org/woodpecker/v2/server/plugins/registry"
|
||||
"go.woodpecker-ci.org/woodpecker/v2/server/plugins/secrets"
|
||||
|
@ -110,22 +111,46 @@ func setupQueue(c *cli.Context, s store.Store) queue.Queue {
|
|||
return queue.WithTaskStore(queue.New(c.Context), s)
|
||||
}
|
||||
|
||||
func setupSecretService(c *cli.Context, s model.SecretStore) model.SecretService {
|
||||
return secrets.New(c.Context, s)
|
||||
func setupSecretService(c *cli.Context, s model.SecretStore) (model.SecretService, error) {
|
||||
addonService, err := addon.Load[model.SecretService](c.StringSlice("addons"), addonTypes.TypeSecretService)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if addonService != nil {
|
||||
return addonService.Value, nil
|
||||
}
|
||||
|
||||
return secrets.New(c.Context, s), nil
|
||||
}
|
||||
|
||||
func setupRegistryService(c *cli.Context, s store.Store) model.RegistryService {
|
||||
func setupRegistryService(c *cli.Context, s store.Store) (model.RegistryService, error) {
|
||||
addonService, err := addon.Load[model.RegistryService](c.StringSlice("addons"), addonTypes.TypeRegistryService)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if addonService != nil {
|
||||
return addonService.Value, nil
|
||||
}
|
||||
|
||||
if c.String("docker-config") != "" {
|
||||
return registry.Combined(
|
||||
registry.New(s),
|
||||
registry.Filesystem(c.String("docker-config")),
|
||||
)
|
||||
), nil
|
||||
}
|
||||
return registry.New(s)
|
||||
return registry.New(s), nil
|
||||
}
|
||||
|
||||
func setupEnvironService(c *cli.Context, _ store.Store) model.EnvironService {
|
||||
return environments.Parse(c.StringSlice("environment"))
|
||||
func setupEnvironService(c *cli.Context, _ store.Store) (model.EnvironService, error) {
|
||||
addonService, err := addon.Load[model.EnvironService](c.StringSlice("addons"), addonTypes.TypeEnvironmentService)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if addonService != nil {
|
||||
return addonService.Value, nil
|
||||
}
|
||||
|
||||
return environments.Parse(c.StringSlice("environment")), nil
|
||||
}
|
||||
|
||||
func setupMembershipService(_ *cli.Context, r forge.Forge) cache.MembershipService {
|
||||
|
@ -298,3 +323,19 @@ func setupSignatureKeys(_store store.Store) (crypto.PrivateKey, crypto.PublicKey
|
|||
privateKey := ed25519.PrivateKey(privKeyStr)
|
||||
return privateKey, privateKey.Public()
|
||||
}
|
||||
|
||||
func setupConfigService(c *cli.Context) (config.Extension, error) {
|
||||
addonExt, err := addon.Load[config.Extension](c.StringSlice("addons"), addonTypes.TypeConfigService)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if addonExt != nil {
|
||||
return addonExt.Value, nil
|
||||
}
|
||||
|
||||
if endpoint := c.String("config-service-endpoint"); endpoint != "" {
|
||||
return config.NewHTTP(endpoint, server.Config.Services.SignaturePrivateKey), nil
|
||||
}
|
||||
|
||||
return nil, nil
|
||||
}
|
||||
|
|
|
@ -14,6 +14,10 @@ Addons can be used for:
|
|||
|
||||
- Forges
|
||||
- Agent backends
|
||||
- Config services
|
||||
- Secret services
|
||||
- Environment services
|
||||
- Registry services
|
||||
|
||||
## Restrictions
|
||||
|
||||
|
|
|
@ -22,10 +22,14 @@ Directly import Woodpecker's Go package (`go.woodpecker-ci.org/woodpecker/woodpe
|
|||
|
||||
### Return types
|
||||
|
||||
| Addon type | Return type |
|
||||
| ---------- | -------------------------------------------------------------------------------- |
|
||||
| `Forge` | `"go.woodpecker-ci.org/woodpecker/woodpecker/v2/server/forge".Forge` |
|
||||
| `Backend` | `"go.woodpecker-ci.org/woodpecker/woodpecker/v2/pipeline/backend/types".Backend` |
|
||||
| Addon type | Return type |
|
||||
| -------------------- | -------------------------------------------------------------------------------- |
|
||||
| `Forge` | `"go.woodpecker-ci.org/woodpecker/woodpecker/v2/server/forge".Forge` |
|
||||
| `Backend` | `"go.woodpecker-ci.org/woodpecker/woodpecker/v2/pipeline/backend/types".Backend` |
|
||||
| `ConfigService` | `"go.woodpecker-ci.org/woodpecker/v2/server/plugins/config".ConfigService` |
|
||||
| `SecretService` | `"go.woodpecker-ci.org/woodpecker/v2/server/model".SecretService` |
|
||||
| `EnvironmentService` | `"go.woodpecker-ci.org/woodpecker/v2/server/model".EnvironmentService` |
|
||||
| `RegistryService` | `"go.woodpecker-ci.org/woodpecker/v2/server/model".RegistryService` |
|
||||
|
||||
## Compiling
|
||||
|
||||
|
|
|
@ -20,8 +20,8 @@ import (
|
|||
)
|
||||
|
||||
var (
|
||||
errEnvironNameInvalid = errors.New("Invalid Environment Variable Name")
|
||||
errEnvironValueInvalid = errors.New("Invalid Environment Variable Value")
|
||||
errEnvironNameInvalid = errors.New("invalid Environment Variable Name")
|
||||
errEnvironValueInvalid = errors.New("invalid Environment Variable Value")
|
||||
)
|
||||
|
||||
// EnvironService defines a service for managing environment variables.
|
||||
|
|
|
@ -3,6 +3,10 @@ package types
|
|||
type Type string
|
||||
|
||||
const (
|
||||
TypeForge Type = "forge"
|
||||
TypeBackend Type = "backend"
|
||||
TypeForge Type = "forge"
|
||||
TypeBackend Type = "backend"
|
||||
TypeConfigService Type = "config_service"
|
||||
TypeSecretService Type = "secret_service"
|
||||
TypeEnvironmentService Type = "environment_service"
|
||||
TypeRegistryService Type = "registry_service"
|
||||
)
|
||||
|
|
Loading…
Reference in a new issue