mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-02-23 14:09:20 -06:00
Merge pull request #2229 from owncloud/runtime-cherrypick
This commit is contained in:
@@ -28,6 +28,10 @@ func RootWithConfig(cfg *config.Config) []cli.Flag {
|
||||
EnvVars: []string{"ACCOUNTS_LOG_COLOR", "OCIS_LOG_COLOR"},
|
||||
Destination: &cfg.Log.Color,
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "extensions",
|
||||
Usage: "Run specific extensions during supervised mode",
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -235,6 +239,10 @@ func ServerWithConfig(cfg *config.Config) []cli.Flag {
|
||||
EnvVars: []string{"ACCOUNTS_GID_INDEX_UPPER_BOUND"},
|
||||
Destination: &cfg.Index.GID.Upper,
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "extensions",
|
||||
Usage: "Run specific extensions during supervised mode",
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
9
changelog/unreleased/extensions-cherrypick.md
Normal file
9
changelog/unreleased/extensions-cherrypick.md
Normal file
@@ -0,0 +1,9 @@
|
||||
Enhancement: Runtime support for cherry picking extensions
|
||||
|
||||
Support for running certain extensions supervised via cli flags. Example usage:
|
||||
|
||||
```
|
||||
> ocis server --extensions="proxy, idp, storage-metadata, accounts"
|
||||
```
|
||||
|
||||
https://github.com/owncloud/ocis/pull/2229
|
||||
@@ -291,5 +291,9 @@ func ServerWithConfig(cfg *config.Config) []cli.Flag {
|
||||
EnvVars: []string{"GLAUTH_FALLBACK_USE_GRAPHAPI"},
|
||||
Destination: &cfg.Fallback.UseGraphAPI,
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "extensions",
|
||||
Usage: "Run specific extensions during supervised mode. This flag is set by the runtime",
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -154,5 +154,9 @@ func ServerWithConfig(cfg *config.Config) []cli.Flag {
|
||||
EnvVars: []string{"GRAPH_EXPLORER_GRAPH_URL"},
|
||||
Destination: &cfg.GraphExplorer.GraphURL,
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "extensions",
|
||||
Usage: "Run specific extensions during supervised mode. This flag is set by the runtime",
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -216,5 +216,9 @@ func ServerWithConfig(cfg *config.Config) []cli.Flag {
|
||||
EnvVars: []string{"STORAGE_WEBDAV_NAMESPACE"},
|
||||
Destination: &cfg.WebdavNamespace,
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "extensions",
|
||||
Usage: "Run specific extensions during supervised mode. This flag is set by the runtime",
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -417,7 +417,10 @@ func ServerWithConfig(cfg *config.Config) []cli.Flag {
|
||||
EnvVars: []string{"IDP_REFRESH_TOKEN_EXPIRATION"},
|
||||
Destination: &cfg.IDP.RefreshTokenDurationSeconds,
|
||||
Value: flags.OverrideDefaultUint64(cfg.IDP.RefreshTokenDurationSeconds, 60*60*24*365*3), // 1 year
|
||||
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "extensions",
|
||||
Usage: "Run specific extensions during supervised mode. This flag is set by the runtime",
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,8 +70,9 @@ type Mode int
|
||||
|
||||
// Runtime configures the oCIS runtime when running in supervised mode.
|
||||
type Runtime struct {
|
||||
Port string
|
||||
Host string
|
||||
Port string
|
||||
Host string
|
||||
Extensions string
|
||||
}
|
||||
|
||||
// Config combines all available configuration parts.
|
||||
|
||||
@@ -162,5 +162,12 @@ func ServerWithConfig(cfg *config.Config) []cli.Flag {
|
||||
EnvVars: []string{"OCIS_GRPC_ADDR"},
|
||||
Destination: &cfg.GRPC.Addr,
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "extensions",
|
||||
Aliases: []string{"e"},
|
||||
Usage: "Run specific extensions during supervised mode",
|
||||
EnvVars: []string{"OCIS_RUN_EXTENSIONS"},
|
||||
Destination: &cfg.Runtime.Extensions,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ import (
|
||||
graphExplorer "github.com/owncloud/ocis/graph-explorer/pkg/command"
|
||||
graph "github.com/owncloud/ocis/graph/pkg/command"
|
||||
idp "github.com/owncloud/ocis/idp/pkg/command"
|
||||
"github.com/owncloud/ocis/ocis-pkg/config"
|
||||
ociscfg "github.com/owncloud/ocis/ocis-pkg/config"
|
||||
"github.com/owncloud/ocis/ocis-pkg/log"
|
||||
ocs "github.com/owncloud/ocis/ocs/pkg/command"
|
||||
@@ -37,11 +38,18 @@ import (
|
||||
"github.com/thejerf/suture/v4"
|
||||
)
|
||||
|
||||
var (
|
||||
// runset keeps track of which extensions to start supervised.
|
||||
runset []string
|
||||
)
|
||||
|
||||
type serviceFuncMap map[string]func(*ociscfg.Config) suture.Service
|
||||
|
||||
// Service represents a RPC service.
|
||||
type Service struct {
|
||||
Supervisor *suture.Supervisor
|
||||
ServicesRegistry map[string]func(*ociscfg.Config) suture.Service
|
||||
Delayed map[string]func(*ociscfg.Config) suture.Service
|
||||
ServicesRegistry serviceFuncMap
|
||||
Delayed serviceFuncMap
|
||||
Log log.Logger
|
||||
|
||||
serviceToken map[string][]suture.ServiceToken
|
||||
@@ -71,8 +79,8 @@ func NewService(options ...Option) (*Service, error) {
|
||||
globalCtx, cancelGlobal := context.WithCancel(context.Background())
|
||||
|
||||
s := &Service{
|
||||
ServicesRegistry: make(map[string]func(*ociscfg.Config) suture.Service),
|
||||
Delayed: make(map[string]func(*ociscfg.Config) suture.Service),
|
||||
ServicesRegistry: make(serviceFuncMap),
|
||||
Delayed: make(serviceFuncMap),
|
||||
Log: l,
|
||||
|
||||
serviceToken: make(map[string][]suture.ServiceToken),
|
||||
@@ -180,10 +188,11 @@ func Start(o ...Option) error {
|
||||
}
|
||||
}()
|
||||
|
||||
for name := range s.ServicesRegistry {
|
||||
swap := deepcopy.Copy(s.cfg)
|
||||
s.serviceToken[name] = append(s.serviceToken[name], s.Supervisor.Add(s.ServicesRegistry[name](swap.(*ociscfg.Config))))
|
||||
}
|
||||
// prepare the set of services to run
|
||||
s.generateRunSet(s.cfg)
|
||||
|
||||
// schedule services that we are sure don't have interdependencies.
|
||||
scheduleServiceTokens(s, s.ServicesRegistry)
|
||||
|
||||
// there are reasons not to do this, but we have race conditions ourselves. Until we resolve them, mind the following disclaimer:
|
||||
// Calling ServeBackground will CORRECTLY start the supervisor running in a new goroutine. It is risky to directly run
|
||||
@@ -195,17 +204,45 @@ func Start(o ...Option) error {
|
||||
// trap will block on halt channel for interruptions.
|
||||
go trap(s, halt)
|
||||
|
||||
time.Sleep(1 * time.Second)
|
||||
|
||||
// add services with delayed execution.
|
||||
for name := range s.Delayed {
|
||||
swap := deepcopy.Copy(s.cfg)
|
||||
s.serviceToken[name] = append(s.serviceToken[name], s.Supervisor.Add(s.Delayed[name](swap.(*ociscfg.Config))))
|
||||
}
|
||||
time.Sleep(1 * time.Second)
|
||||
scheduleServiceTokens(s, s.Delayed)
|
||||
|
||||
return http.Serve(l, nil)
|
||||
}
|
||||
|
||||
// scheduleServiceTokens adds service tokens to the service supervisor.
|
||||
func scheduleServiceTokens(s *Service, funcSet serviceFuncMap) {
|
||||
for _, name := range runset {
|
||||
if _, ok := funcSet[name]; !ok {
|
||||
continue
|
||||
}
|
||||
|
||||
swap := deepcopy.Copy(s.cfg)
|
||||
s.serviceToken[name] = append(s.serviceToken[name], s.Supervisor.Add(funcSet[name](swap.(*ociscfg.Config))))
|
||||
}
|
||||
}
|
||||
|
||||
// generateRunSet interprets the cfg.Runtime.Extensions config option to cherry-pick which services to start using
|
||||
// the runtime.
|
||||
func (s *Service) generateRunSet(cfg *config.Config) {
|
||||
if cfg.Runtime.Extensions != "" {
|
||||
e := strings.Split(strings.ReplaceAll(cfg.Runtime.Extensions, " ", ""), ",")
|
||||
for i := range e {
|
||||
runset = append(runset, e[i])
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
for name := range s.ServicesRegistry {
|
||||
runset = append(runset, name)
|
||||
}
|
||||
|
||||
for name := range s.Delayed {
|
||||
runset = append(runset, name)
|
||||
}
|
||||
}
|
||||
|
||||
// Start indicates the Service Controller to start a new supervised service as an OS thread.
|
||||
func (s *Service) Start(name string, reply *int) error {
|
||||
// RPC calls to a Service object will allow for parsing config. Mind that since the runtime is running on a different
|
||||
|
||||
@@ -179,6 +179,10 @@ func ServerWithConfig(cfg *config.Config) []cli.Flag {
|
||||
EnvVars: []string{"OCS_STORAGE_USERS_DRIVER", "STORAGE_USERS_DRIVER"},
|
||||
Destination: &cfg.StorageUsersDriver,
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "extensions",
|
||||
Usage: "Run specific extensions during supervised mode",
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -154,5 +154,9 @@ func ServerWithConfig(cfg *config.Config) []cli.Flag {
|
||||
EnvVars: []string{"ONLYOFFICE_ASSET_PATH"},
|
||||
Destination: &cfg.Asset.Path,
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "extensions",
|
||||
Usage: "Run specific extensions during supervised mode. This flag is set by the runtime",
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,6 +30,10 @@ func RootWithConfig(cfg *config.Config) []cli.Flag {
|
||||
EnvVars: []string{"PROXY_LOG_COLOR", "OCIS_LOG_COLOR"},
|
||||
Destination: &cfg.Log.Color,
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "extensions",
|
||||
Usage: "Run specific extensions during supervised mode",
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -183,6 +183,10 @@ func ServerWithConfig(cfg *config.Config) []cli.Flag {
|
||||
EnvVars: []string{"SETTINGS_JWT_SECRET", "OCIS_JWT_SECRET"},
|
||||
Destination: &cfg.TokenManager.JWTSecret,
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "extensions",
|
||||
Usage: "Run specific extensions during supervised mode. This flag is set by the runtime",
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -106,6 +106,7 @@ func StorageMetadata(cfg *config.Config) []cli.Flag {
|
||||
f = append(f, DriverOwnCloudWithConfig(cfg)...)
|
||||
f = append(f, DriverOCISWithConfig(cfg)...)
|
||||
f = append(f, DriverS3NGWithConfig(cfg)...)
|
||||
|
||||
return f
|
||||
|
||||
}
|
||||
|
||||
@@ -140,6 +140,10 @@ func ServerWithConfig(cfg *config.Config) []cli.Flag {
|
||||
EnvVars: []string{"STORE_DATA_PATH"},
|
||||
Destination: &cfg.Datapath,
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "extensions",
|
||||
Usage: "Run specific extensions during supervised mode. This flag is set by the runtime",
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -169,6 +169,10 @@ func ServerWithConfig(cfg *config.Config) []cli.Flag {
|
||||
EnvVars: []string{"STORAGE_WEBDAV_NAMESPACE"},
|
||||
Destination: &cfg.Thumbnail.WebdavNamespace,
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "extensions",
|
||||
Usage: "Run specific extensions during supervised mode",
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -223,5 +223,9 @@ func ServerWithConfig(cfg *config.Config) []cli.Flag {
|
||||
EnvVars: []string{"WEB_OIDC_SCOPE"},
|
||||
Destination: &cfg.Web.Config.OpenIDConnect.Scope,
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "extensions",
|
||||
Usage: "Run specific extensions during supervised mode. This flag is set by the runtime",
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -142,19 +142,23 @@ func ServerWithConfig(cfg *config.Config) []cli.Flag {
|
||||
Destination: &cfg.HTTP.Root,
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "ocis-public-url",
|
||||
Value: flags.OverrideDefaultString(cfg.OcisPublicURL, "https://127.0.0.1:9200"),
|
||||
Usage: "The domain under which oCIS is reachable",
|
||||
EnvVars: []string{"OCIS_PUBLIC_URL", "OCIS_URL"},
|
||||
Name: "ocis-public-url",
|
||||
Value: flags.OverrideDefaultString(cfg.OcisPublicURL, "https://127.0.0.1:9200"),
|
||||
Usage: "The domain under which oCIS is reachable",
|
||||
EnvVars: []string{"OCIS_PUBLIC_URL", "OCIS_URL"},
|
||||
Destination: &cfg.OcisPublicURL,
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "webdav-namespace",
|
||||
Value: flags.OverrideDefaultString(cfg.WebdavNamespace, "/home"),
|
||||
Usage: "Namespace prefix for the /webdav endpoint",
|
||||
EnvVars: []string{"STORAGE_WEBDAV_NAMESPACE"},
|
||||
Name: "webdav-namespace",
|
||||
Value: flags.OverrideDefaultString(cfg.WebdavNamespace, "/home"),
|
||||
Usage: "Namespace prefix for the /webdav endpoint",
|
||||
EnvVars: []string{"STORAGE_WEBDAV_NAMESPACE"},
|
||||
Destination: &cfg.WebdavNamespace,
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "extensions",
|
||||
Usage: "Run specific extensions during supervised mode. This flag is set by the runtime",
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user