mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2024-11-25 19:31:05 +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"
|
woodpeckerGrpcServer "go.woodpecker-ci.org/woodpecker/v2/server/grpc"
|
||||||
"go.woodpecker-ci.org/woodpecker/v2/server/logging"
|
"go.woodpecker-ci.org/woodpecker/v2/server/logging"
|
||||||
"go.woodpecker-ci.org/woodpecker/v2/server/model"
|
"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/plugins/permissions"
|
||||||
"go.woodpecker-ci.org/woodpecker/v2/server/pubsub"
|
"go.woodpecker-ci.org/woodpecker/v2/server/pubsub"
|
||||||
"go.woodpecker-ci.org/woodpecker/v2/server/router"
|
"go.woodpecker-ci.org/woodpecker/v2/server/router"
|
||||||
|
@ -90,7 +89,7 @@ func run(c *cli.Context) error {
|
||||||
|
|
||||||
_store, err := setupStore(c)
|
_store, err := setupStore(c)
|
||||||
if err != nil {
|
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() {
|
defer func() {
|
||||||
if err := _store.Close(); err != nil {
|
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
|
var g errgroup.Group
|
||||||
|
|
||||||
|
@ -266,7 +268,7 @@ func run(c *cli.Context) error {
|
||||||
return g.Wait()
|
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
|
// forge
|
||||||
server.Config.Services.Forge = f
|
server.Config.Services.Forge = f
|
||||||
server.Config.Services.Timeout = c.Duration("forge-timeout")
|
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.Queue = setupQueue(c, v)
|
||||||
server.Config.Services.Logs = logging.New()
|
server.Config.Services.Logs = logging.New()
|
||||||
server.Config.Services.Pubsub = pubsub.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
|
// TODO(1544): fix encrypted store
|
||||||
// // encryption
|
// // 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")
|
// log.Fatal().Err(err).Msg("could not create encryption service")
|
||||||
// }
|
// }
|
||||||
// server.Config.Services.Secrets = setupSecretService(c, encryptedSecretStore)
|
// server.Config.Services.Secrets = setupSecretService(c, encryptedSecretStore)
|
||||||
server.Config.Services.Secrets = setupSecretService(c, v)
|
server.Config.Services.Secrets, err = setupSecretService(c, v)
|
||||||
|
if err != nil {
|
||||||
server.Config.Services.Environ = setupEnvironService(c, v)
|
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.Membership = setupMembershipService(c, f)
|
||||||
|
|
||||||
server.Config.Services.SignaturePrivateKey, server.Config.Services.SignaturePublicKey = setupSignatureKeys(v)
|
server.Config.Services.SignaturePrivateKey, server.Config.Services.SignaturePublicKey = setupSignatureKeys(v)
|
||||||
|
|
||||||
if endpoint := c.String("config-service-endpoint"); endpoint != "" {
|
server.Config.Services.ConfigService, err = setupConfigService(c)
|
||||||
server.Config.Services.ConfigService = config.NewHTTP(endpoint, server.Config.Services.SignaturePrivateKey)
|
if err != nil {
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// authentication
|
// 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.Admins = permissions.NewAdmins(c.StringSlice("admin"))
|
||||||
server.Config.Permissions.Orgs = permissions.NewOrgs(c.StringSlice("orgs"))
|
server.Config.Permissions.Orgs = permissions.NewOrgs(c.StringSlice("orgs"))
|
||||||
server.Config.Permissions.OwnersAllowlist = permissions.NewOwnersAllowlist(c.StringSlice("repo-owners"))
|
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/github"
|
||||||
"go.woodpecker-ci.org/woodpecker/v2/server/forge/gitlab"
|
"go.woodpecker-ci.org/woodpecker/v2/server/forge/gitlab"
|
||||||
"go.woodpecker-ci.org/woodpecker/v2/server/model"
|
"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/environments"
|
||||||
"go.woodpecker-ci.org/woodpecker/v2/server/plugins/registry"
|
"go.woodpecker-ci.org/woodpecker/v2/server/plugins/registry"
|
||||||
"go.woodpecker-ci.org/woodpecker/v2/server/plugins/secrets"
|
"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)
|
return queue.WithTaskStore(queue.New(c.Context), s)
|
||||||
}
|
}
|
||||||
|
|
||||||
func setupSecretService(c *cli.Context, s model.SecretStore) model.SecretService {
|
func setupSecretService(c *cli.Context, s model.SecretStore) (model.SecretService, error) {
|
||||||
return secrets.New(c.Context, s)
|
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") != "" {
|
if c.String("docker-config") != "" {
|
||||||
return registry.Combined(
|
return registry.Combined(
|
||||||
registry.New(s),
|
registry.New(s),
|
||||||
registry.Filesystem(c.String("docker-config")),
|
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 {
|
func setupEnvironService(c *cli.Context, _ store.Store) (model.EnvironService, error) {
|
||||||
return environments.Parse(c.StringSlice("environment"))
|
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 {
|
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)
|
privateKey := ed25519.PrivateKey(privKeyStr)
|
||||||
return privateKey, privateKey.Public()
|
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
|
- Forges
|
||||||
- Agent backends
|
- Agent backends
|
||||||
|
- Config services
|
||||||
|
- Secret services
|
||||||
|
- Environment services
|
||||||
|
- Registry services
|
||||||
|
|
||||||
## Restrictions
|
## Restrictions
|
||||||
|
|
||||||
|
|
|
@ -22,10 +22,14 @@ Directly import Woodpecker's Go package (`go.woodpecker-ci.org/woodpecker/woodpe
|
||||||
|
|
||||||
### Return types
|
### Return types
|
||||||
|
|
||||||
| Addon type | Return type |
|
| Addon type | Return type |
|
||||||
| ---------- | -------------------------------------------------------------------------------- |
|
| -------------------- | -------------------------------------------------------------------------------- |
|
||||||
| `Forge` | `"go.woodpecker-ci.org/woodpecker/woodpecker/v2/server/forge".Forge` |
|
| `Forge` | `"go.woodpecker-ci.org/woodpecker/woodpecker/v2/server/forge".Forge` |
|
||||||
| `Backend` | `"go.woodpecker-ci.org/woodpecker/woodpecker/v2/pipeline/backend/types".Backend` |
|
| `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
|
## Compiling
|
||||||
|
|
||||||
|
|
|
@ -20,8 +20,8 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
errEnvironNameInvalid = errors.New("Invalid Environment Variable Name")
|
errEnvironNameInvalid = errors.New("invalid Environment Variable Name")
|
||||||
errEnvironValueInvalid = errors.New("Invalid Environment Variable Value")
|
errEnvironValueInvalid = errors.New("invalid Environment Variable Value")
|
||||||
)
|
)
|
||||||
|
|
||||||
// EnvironService defines a service for managing environment variables.
|
// EnvironService defines a service for managing environment variables.
|
||||||
|
|
|
@ -3,6 +3,10 @@ package types
|
||||||
type Type string
|
type Type string
|
||||||
|
|
||||||
const (
|
const (
|
||||||
TypeForge Type = "forge"
|
TypeForge Type = "forge"
|
||||||
TypeBackend Type = "backend"
|
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