mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-01-07 12:50:21 -06:00
Merge pull request #148 from owncloud/feature/propagate-config-file
Make extensions handle their config
This commit is contained in:
@@ -78,7 +78,21 @@ To the list of available services.
|
||||
|
||||
## Configuration
|
||||
|
||||
We provide overall three different variants of configuration. The variant based on environment variables and commandline flags are split up into global values and command-specific values.
|
||||
oCIS Single Binary is not responsible for configuring extensions. Instead, each extension could either be configured by environment variables, cli flags or config files.
|
||||
|
||||
### Configuration using config files
|
||||
|
||||
Out of the box extensions will attempt to read configuration details from:
|
||||
|
||||
```console
|
||||
/etc/ocis
|
||||
$HOME/.ocis
|
||||
./config
|
||||
```
|
||||
|
||||
For this configuration to be picked up, have a look at your extension `root` command and look for which default config name it has assigned. *i.e: ocis-proxy reads `ocis.json | yaml | toml ...`*.
|
||||
|
||||
> Important note: As per the time of this writing, Viper does not play nice with urfave/cli flags, this results in values defined on config files taking precedence over cli flags. This behavior is different with environment variables, these will ALWAYS override any value, as they are the most explicit.
|
||||
|
||||
### Envrionment variables
|
||||
|
||||
|
||||
8
go.mod
8
go.mod
@@ -12,6 +12,7 @@ require (
|
||||
github.com/micro/go-micro/v2 v2.0.1-0.20200212105717-d76baf59de2e
|
||||
github.com/micro/micro/v2 v2.0.1-0.20200210100719-f38a1d8d5348
|
||||
github.com/openzipkin/zipkin-go v0.2.2
|
||||
github.com/owncloud/ocis-devldap v0.0.0-20200311185721-105f9cbe4ce4 // indirect
|
||||
github.com/owncloud/ocis-glauth v0.2.0
|
||||
github.com/owncloud/ocis-graph v0.0.0-20200217115956-172417259283
|
||||
github.com/owncloud/ocis-graph-explorer v0.0.0-20200210111049-017eeb40dc0c
|
||||
@@ -19,13 +20,12 @@ require (
|
||||
github.com/owncloud/ocis-konnectd v0.0.0-20200303180152-937016f63393
|
||||
github.com/owncloud/ocis-ocs v0.0.0-20200207130609-800a64d45fac
|
||||
github.com/owncloud/ocis-phoenix v0.1.1-0.20200213204418-06f50c42c225
|
||||
github.com/owncloud/ocis-pkg/v2 v2.0.2
|
||||
github.com/owncloud/ocis-pkg/v2 v2.0.3-0.20200309150924-5c659fd4b0ad
|
||||
github.com/owncloud/ocis-proxy v0.0.0-20200310100127-5a38d286e52c
|
||||
github.com/owncloud/ocis-reva v0.0.0-20200213202552-584d47daa8bc
|
||||
github.com/owncloud/ocis-webdav v0.0.0-20200210113150-6c4d498c38b0
|
||||
github.com/spf13/viper v1.6.2
|
||||
go.opencensus.io v0.22.3
|
||||
golang.org/x/crypto v0.0.0-20200221231518-2aa609cf4a9d // indirect
|
||||
go.opencensus.io v0.22.2
|
||||
golang.org/x/crypto v0.0.0-20200311171314-f7b00557c8c4 // indirect
|
||||
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b // indirect
|
||||
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae // indirect
|
||||
stash.kopano.io/kc/konnect v0.29.0 // indirect
|
||||
|
||||
@@ -18,13 +18,14 @@ func GraphExplorerCommand(cfg *config.Config) *cli.Command {
|
||||
Usage: "Start graph explorer",
|
||||
Category: "Extensions",
|
||||
Flags: flagset.ServerWithConfig(cfg.GraphExplorer),
|
||||
Action: func(c *cli.Context) error {
|
||||
scfg := configureGraphExplorer(cfg)
|
||||
Action: func(ctx *cli.Context) error {
|
||||
graphExplorerCommand := command.Server(configureGraphExplorer(cfg))
|
||||
|
||||
return cli.HandleAction(
|
||||
command.Server(scfg).Action,
|
||||
c,
|
||||
)
|
||||
if err := graphExplorerCommand.Before(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return cli.HandleAction(graphExplorerCommand.Action, ctx)
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -33,9 +34,6 @@ func configureGraphExplorer(cfg *config.Config) *svcconfig.Config {
|
||||
cfg.GraphExplorer.Log.Level = cfg.Log.Level
|
||||
cfg.GraphExplorer.Log.Pretty = cfg.Log.Pretty
|
||||
cfg.GraphExplorer.Log.Color = cfg.Log.Color
|
||||
cfg.GraphExplorer.Tracing.Enabled = false
|
||||
cfg.GraphExplorer.HTTP.Addr = "localhost:9135"
|
||||
cfg.GraphExplorer.HTTP.Root = "/"
|
||||
|
||||
return cfg.GraphExplorer
|
||||
}
|
||||
|
||||
@@ -18,13 +18,14 @@ func GraphCommand(cfg *config.Config) *cli.Command {
|
||||
Usage: "Start graph server",
|
||||
Category: "Extensions",
|
||||
Flags: flagset.ServerWithConfig(cfg.Graph),
|
||||
Action: func(c *cli.Context) error {
|
||||
scfg := configureGraph(cfg)
|
||||
Action: func(ctx *cli.Context) error {
|
||||
graphCommand := command.Server(configureGraph(cfg))
|
||||
|
||||
return cli.HandleAction(
|
||||
command.Server(scfg).Action,
|
||||
c,
|
||||
)
|
||||
if err := graphCommand.Before(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return cli.HandleAction(graphCommand.Action, ctx)
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -33,9 +34,6 @@ func configureGraph(cfg *config.Config) *svcconfig.Config {
|
||||
cfg.Graph.Log.Level = cfg.Log.Level
|
||||
cfg.Graph.Log.Pretty = cfg.Log.Pretty
|
||||
cfg.Graph.Log.Color = cfg.Log.Color
|
||||
cfg.Graph.Tracing.Enabled = false
|
||||
cfg.Graph.HTTP.Addr = "localhost:9120"
|
||||
cfg.Graph.HTTP.Root = "/"
|
||||
|
||||
return cfg.Graph
|
||||
}
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
package command
|
||||
|
||||
import (
|
||||
@@ -18,14 +17,13 @@ func KonnectdCommand(cfg *config.Config) *cli.Command {
|
||||
Category: "Extensions",
|
||||
Flags: flagset.ServerWithConfig(cfg.Konnectd),
|
||||
Action: func(c *cli.Context) error {
|
||||
serverConfig := configureKonnectd(cfg)
|
||||
serverCommand := command.Server(serverConfig)
|
||||
konnectdCommand := command.Server(configureKonnectd(cfg))
|
||||
|
||||
if err := serverCommand.Before(c); err != nil {
|
||||
if err := konnectdCommand.Before(c); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return cli.HandleAction(serverCommand.Action, c)
|
||||
return cli.HandleAction(konnectdCommand.Action, c)
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -34,9 +32,6 @@ func configureKonnectd(cfg *config.Config) *svcconfig.Config {
|
||||
cfg.Konnectd.Log.Level = cfg.Log.Level
|
||||
cfg.Konnectd.Log.Pretty = cfg.Log.Pretty
|
||||
cfg.Konnectd.Log.Color = cfg.Log.Color
|
||||
cfg.Konnectd.Tracing.Enabled = false
|
||||
cfg.Konnectd.HTTP.Addr = "localhost:9130"
|
||||
cfg.Konnectd.HTTP.Root = "/"
|
||||
|
||||
return cfg.Konnectd
|
||||
}
|
||||
|
||||
@@ -18,13 +18,14 @@ func OCSCommand(cfg *config.Config) *cli.Command {
|
||||
Usage: "Start ocs server",
|
||||
Category: "Extensions",
|
||||
Flags: flagset.ServerWithConfig(cfg.OCS),
|
||||
Action: func(c *cli.Context) error {
|
||||
scfg := configureOCS(cfg)
|
||||
Action: func(ctx *cli.Context) error {
|
||||
ocsCommand := command.Server(configureOCS(cfg))
|
||||
|
||||
return cli.HandleAction(
|
||||
command.Server(scfg).Action,
|
||||
c,
|
||||
)
|
||||
if err := ocsCommand.Before(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return cli.HandleAction(ocsCommand.Action, ctx)
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -33,9 +34,6 @@ func configureOCS(cfg *config.Config) *svcconfig.Config {
|
||||
cfg.OCS.Log.Level = cfg.Log.Level
|
||||
cfg.OCS.Log.Pretty = cfg.Log.Pretty
|
||||
cfg.OCS.Log.Color = cfg.Log.Color
|
||||
cfg.OCS.Tracing.Enabled = false
|
||||
cfg.OCS.HTTP.Addr = "localhost:9110"
|
||||
cfg.OCS.HTTP.Root = "/"
|
||||
|
||||
return cfg.OCS
|
||||
}
|
||||
|
||||
@@ -23,17 +23,16 @@ func PhoenixCommand(cfg *config.Config) *cli.Command {
|
||||
}
|
||||
|
||||
cfg.Phoenix.Phoenix.Config.Apps = c.StringSlice("web-config-app")
|
||||
|
||||
return nil
|
||||
},
|
||||
Action: func(c *cli.Context) error {
|
||||
phoenixCommand := command.Server(configurePhoenix(cfg))
|
||||
|
||||
scfg := configurePhoenix(cfg)
|
||||
if err := phoenixCommand.Before(c); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return cli.HandleAction(
|
||||
command.Server(scfg).Action,
|
||||
c,
|
||||
)
|
||||
return cli.HandleAction(phoenixCommand.Action, c)
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,15 +16,14 @@ func ProxyCommand(cfg *config.Config) *cli.Command {
|
||||
Usage: "Start proxy server",
|
||||
Category: "Extensions",
|
||||
Flags: flagset.ServerWithConfig(cfg.Proxy),
|
||||
Action: func(c *cli.Context) error {
|
||||
serverConfig := configureProxy(cfg)
|
||||
serverCommand := command.Server(serverConfig)
|
||||
Action: func(ctx *cli.Context) error {
|
||||
proxyCommand := command.Server(configureProxy(cfg))
|
||||
|
||||
if err := serverCommand.Before(c); err != nil {
|
||||
if err := proxyCommand.Before(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return cli.HandleAction(serverCommand.Action, c)
|
||||
return cli.HandleAction(proxyCommand.Action, ctx)
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ package command
|
||||
|
||||
import (
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/micro/cli/v2"
|
||||
"github.com/owncloud/ocis-pkg/v2/log"
|
||||
@@ -11,7 +10,6 @@ import (
|
||||
"github.com/owncloud/ocis/pkg/micro/runtime"
|
||||
"github.com/owncloud/ocis/pkg/register"
|
||||
"github.com/owncloud/ocis/pkg/version"
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
||||
// Execute is the entry point for the ocis-ocis command.
|
||||
@@ -30,53 +28,9 @@ func Execute() error {
|
||||
Email: "support@owncloud.com",
|
||||
},
|
||||
},
|
||||
|
||||
Flags: flagset.RootWithConfig(cfg),
|
||||
|
||||
Before: func(c *cli.Context) error {
|
||||
logger := NewLogger(cfg)
|
||||
|
||||
viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_"))
|
||||
viper.SetEnvPrefix("OCIS")
|
||||
viper.AutomaticEnv()
|
||||
|
||||
if c.IsSet("config-file") {
|
||||
viper.SetConfigFile(c.String("config-file"))
|
||||
} else {
|
||||
viper.SetConfigName("ocis")
|
||||
|
||||
viper.AddConfigPath("/etc/ocis")
|
||||
viper.AddConfigPath("$HOME/.ocis")
|
||||
viper.AddConfigPath("./config")
|
||||
}
|
||||
|
||||
if err := viper.ReadInConfig(); err != nil {
|
||||
switch err.(type) {
|
||||
case viper.ConfigFileNotFoundError:
|
||||
logger.Info().
|
||||
Msg("Continue without config")
|
||||
case viper.UnsupportedConfigError:
|
||||
logger.Fatal().
|
||||
Err(err).
|
||||
Msg("Unsupported config type")
|
||||
default:
|
||||
logger.Fatal().
|
||||
Err(err).
|
||||
Msg("Failed to read config")
|
||||
}
|
||||
}
|
||||
|
||||
if err := viper.Unmarshal(&cfg); err != nil {
|
||||
logger.Fatal().
|
||||
Err(err).
|
||||
Msg("Failed to parse config")
|
||||
}
|
||||
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
// Load commands from the registry
|
||||
for _, fn := range register.Commands {
|
||||
app.Commands = append(
|
||||
app.Commands,
|
||||
|
||||
@@ -39,6 +39,7 @@ func Server(cfg *config.Config) *cli.Command {
|
||||
runtime.Services(append(runtime.MicroServices, runtime.Extensions...)),
|
||||
runtime.Logger(logger),
|
||||
runtime.MicroRuntime(cmd.DefaultCmd.Options().Runtime),
|
||||
runtime.Context(c),
|
||||
)
|
||||
|
||||
runtime.Start()
|
||||
|
||||
@@ -52,6 +52,7 @@ func Simple(cfg *config.Config) *cli.Command {
|
||||
runtime.Logger(logger),
|
||||
runtime.Services(append(runtime.RuntimeServices, SimpleRuntimeServices...)),
|
||||
runtime.MicroRuntime(cmd.DefaultCmd.Options().Runtime),
|
||||
runtime.Context(c),
|
||||
)
|
||||
|
||||
{
|
||||
|
||||
@@ -19,12 +19,13 @@ func WebDAVCommand(cfg *config.Config) *cli.Command {
|
||||
Category: "Extensions",
|
||||
Flags: flagset.ServerWithConfig(cfg.WebDAV),
|
||||
Action: func(c *cli.Context) error {
|
||||
scfg := configureWebDAV(cfg)
|
||||
webdavCommand := command.Server(configureWebDAV(cfg))
|
||||
|
||||
return cli.HandleAction(
|
||||
command.Server(scfg).Action,
|
||||
c,
|
||||
)
|
||||
if err := webdavCommand.Before(c); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return cli.HandleAction(webdavCommand.Action, c)
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -33,9 +34,6 @@ func configureWebDAV(cfg *config.Config) *svcconfig.Config {
|
||||
cfg.WebDAV.Log.Level = cfg.Log.Level
|
||||
cfg.WebDAV.Log.Pretty = cfg.Log.Pretty
|
||||
cfg.WebDAV.Log.Color = cfg.Log.Color
|
||||
cfg.WebDAV.Tracing.Enabled = false
|
||||
cfg.WebDAV.HTTP.Addr = "localhost:9115"
|
||||
cfg.WebDAV.HTTP.Root = "/"
|
||||
|
||||
return cfg.WebDAV
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package runtime
|
||||
|
||||
import (
|
||||
"github.com/micro/cli/v2"
|
||||
gorun "github.com/micro/go-micro/v2/runtime"
|
||||
"github.com/owncloud/ocis-pkg/v2/log"
|
||||
)
|
||||
@@ -10,6 +11,7 @@ type Options struct {
|
||||
Services []string
|
||||
Logger log.Logger
|
||||
MicroRuntime *gorun.Runtime
|
||||
Context *cli.Context
|
||||
}
|
||||
|
||||
// Option undocummented
|
||||
@@ -46,3 +48,10 @@ func MicroRuntime(rt *gorun.Runtime) Option {
|
||||
o.MicroRuntime = rt
|
||||
}
|
||||
}
|
||||
|
||||
// Context option
|
||||
func Context(c *cli.Context) Option {
|
||||
return func(o *Options) {
|
||||
o.Context = c
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,16 +21,16 @@ var (
|
||||
|
||||
// MicroServices to start as part of the fullstack option
|
||||
MicroServices = []string{
|
||||
"api", // :8080
|
||||
"proxy", // :8081
|
||||
"api", // :8080
|
||||
// "proxy", // :8081
|
||||
"web", // :8082
|
||||
"registry", // :8000
|
||||
"runtime", // :8088 (future proof. We want to be able to control extensions through a runtime)
|
||||
// "runtime", // :8088 (future proof. We want to be able to control extensions through a runtime)
|
||||
}
|
||||
|
||||
// Extensions are ocis extension services
|
||||
Extensions = []string{
|
||||
"hello",
|
||||
// "hello",
|
||||
"phoenix",
|
||||
"graph",
|
||||
"graph-explorer",
|
||||
@@ -49,7 +49,7 @@ var (
|
||||
"reva-storage-oc-data",
|
||||
"glauth",
|
||||
"konnectd",
|
||||
"proxy",
|
||||
"proxy", // TODO rename this command. It collides with micro's `proxy`
|
||||
}
|
||||
)
|
||||
|
||||
@@ -57,6 +57,7 @@ var (
|
||||
type Runtime struct {
|
||||
Logger log.Logger
|
||||
R *gorun.Runtime
|
||||
Ctx *cli.Context
|
||||
|
||||
services []*gorun.Service
|
||||
}
|
||||
@@ -68,6 +69,7 @@ func New(opts ...Option) Runtime {
|
||||
r := Runtime{
|
||||
Logger: options.Logger,
|
||||
R: options.MicroRuntime,
|
||||
Ctx: options.Context,
|
||||
}
|
||||
|
||||
for _, v := range append(MicroServices, Extensions...) {
|
||||
@@ -109,14 +111,18 @@ func (r Runtime) Trap() {
|
||||
func (r *Runtime) Start() {
|
||||
env := os.Environ()
|
||||
|
||||
for i := range r.services {
|
||||
args := []gorun.CreateOption{
|
||||
gorun.WithCommand(os.Args[0], r.services[i].Name),
|
||||
for _, s := range r.services {
|
||||
args := []string{os.Args[0]}
|
||||
|
||||
args = append(args, s.Name)
|
||||
gorunArgs := []gorun.CreateOption{
|
||||
gorun.WithCommand(args...),
|
||||
gorun.WithEnv(env),
|
||||
gorun.WithOutput(os.Stdout),
|
||||
}
|
||||
|
||||
go (*r.R).Create(r.services[i], args...)
|
||||
go (*r.R).Create(s, gorunArgs...)
|
||||
// args = args[:len(args)-1]
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user