From 96521d23a9a36dfc4e898207d64e02f55ffc35b9 Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Thu, 4 Mar 2021 14:08:44 +0100 Subject: [PATCH] add thumbnails --- ocis/pkg/runtime/runtime.go | 19 ++++++++++-------- thumbnails/cmd/thumbnails/main.go | 3 ++- thumbnails/pkg/command/root.go | 33 ++++++++++++++++++++++++++++--- thumbnails/pkg/config/config.go | 4 ++++ thumbnails/pkg/flagset/flagset.go | 9 +++------ 5 files changed, 50 insertions(+), 18 deletions(-) diff --git a/ocis/pkg/runtime/runtime.go b/ocis/pkg/runtime/runtime.go index c65202a2a6..51f50a1d71 100644 --- a/ocis/pkg/runtime/runtime.go +++ b/ocis/pkg/runtime/runtime.go @@ -13,6 +13,7 @@ import ( proxy "github.com/owncloud/ocis/proxy/pkg/command" settings "github.com/owncloud/ocis/settings/pkg/command" store "github.com/owncloud/ocis/store/pkg/command" + thumbnails "github.com/owncloud/ocis/thumbnails/pkg/command" "github.com/thejerf/suture" @@ -38,13 +39,13 @@ var ( // Extensions are oCIS extension services Extensions = []string{ - "glauth", // done - "idp", // done - "ocs", // done - "onlyoffice", // done - "proxy", // done - "settings", // done - "store", + "glauth", // done + "idp", // done + "ocs", // done + "onlyoffice", // done + "proxy", // done + "settings", // done + "store", // done "storage-metadata", // done "storage-frontend", "storage-gateway", @@ -55,7 +56,7 @@ var ( "storage-home", "storage-users", "storage-public-link", - "thumbnails", + "thumbnails", // done "web", "webdav", } @@ -109,6 +110,7 @@ func (r *Runtime) Start() error { // - establish on suture a max number of retries before all initialization comes to a halt. // - remove default log flagset values. // - subcommands MUST also set MICRO_LOG_LEVEL to error. + // - 2021-03-04T14:06:37+01:00 FTL failed to read config error="open /Users/aunger/.ocis/idp.env: no such file or directory" service=idp still exists // propagate reva log config to storage services r.c.Storage.Log.Level = r.c.Log.Level @@ -124,6 +126,7 @@ func (r *Runtime) Start() error { addServiceToken("onlyoffice", supervisor.Add(onlyoffice.NewSutureService(globalCtx, r.c.Onlyoffice))) addServiceToken("proxy", supervisor.Add(proxy.NewSutureService(globalCtx, r.c.Proxy))) addServiceToken("store", supervisor.Add(store.NewSutureService(globalCtx, r.c.Store))) + addServiceToken("thumbnails", supervisor.Add(thumbnails.NewSutureService(globalCtx, r.c.Thumbnails))) // TODO(refs) debug line with supervised services. go supervisor.ServeBackground() diff --git a/thumbnails/cmd/thumbnails/main.go b/thumbnails/cmd/thumbnails/main.go index df37440368..7d89ce29f1 100644 --- a/thumbnails/cmd/thumbnails/main.go +++ b/thumbnails/cmd/thumbnails/main.go @@ -4,10 +4,11 @@ import ( "os" "github.com/owncloud/ocis/thumbnails/pkg/command" + "github.com/owncloud/ocis/thumbnails/pkg/config" ) func main() { - if err := command.Execute(); err != nil { + if err := command.Execute(config.New()); err != nil { os.Exit(1) } } diff --git a/thumbnails/pkg/command/root.go b/thumbnails/pkg/command/root.go index b73e32ad6d..2a7e0cfd2e 100644 --- a/thumbnails/pkg/command/root.go +++ b/thumbnails/pkg/command/root.go @@ -1,6 +1,7 @@ package command import ( + "context" "os" "strings" @@ -13,9 +14,7 @@ import ( ) // Execute is the entry point for the ocis-thumbnails command. -func Execute() error { - cfg := config.New() - +func Execute(cfg *config.Config) error { app := &cli.App{ Name: "ocis-thumbnails", Version: version.String, @@ -108,3 +107,31 @@ func ParseConfig(c *cli.Context, cfg *config.Config) error { return nil } + +// SutureService allows for the thumbnails command to be embedded and supervised by a suture supervisor tree. +type SutureService struct { + ctx context.Context + cancel context.CancelFunc // used to cancel the context go-micro services used to shutdown a service. + cfg *config.Config +} + +// NewSutureService creates a new thumbnails.SutureService +func NewSutureService(ctx context.Context, cfg *config.Config) SutureService { + sctx, cancel := context.WithCancel(ctx) + cfg.Context = sctx // propagate the context down to the go-micro services. + return SutureService{ + ctx: sctx, + cancel: cancel, + cfg: cfg, + } +} + +func (s SutureService) Serve() { + if err := Execute(s.cfg); err != nil { + return + } +} + +func (s SutureService) Stop() { + s.cancel() +} diff --git a/thumbnails/pkg/config/config.go b/thumbnails/pkg/config/config.go index bff257fb29..b050168871 100644 --- a/thumbnails/pkg/config/config.go +++ b/thumbnails/pkg/config/config.go @@ -1,5 +1,7 @@ package config +import "context" + // Log defines the available logging configuration. type Log struct { Level string @@ -40,6 +42,8 @@ type Config struct { Server Server Tracing Tracing Thumbnail Thumbnail + + Context context.Context } // FileSystemStorage defines the available filesystem storage configuration. diff --git a/thumbnails/pkg/flagset/flagset.go b/thumbnails/pkg/flagset/flagset.go index 0d6b7db79f..76eb7bb4c5 100644 --- a/thumbnails/pkg/flagset/flagset.go +++ b/thumbnails/pkg/flagset/flagset.go @@ -13,23 +13,20 @@ func RootWithConfig(cfg *config.Config) []cli.Flag { return []cli.Flag{ &cli.StringFlag{ Name: "log-level", - Value: "info", Usage: "Set logging level", - EnvVars: []string{"THUMBNAILS_LOG_LEVEL"}, + EnvVars: []string{"THUMBNAILS_LOG_LEVEL", "OCIS_LOG_LEVEL"}, Destination: &cfg.Log.Level, }, &cli.BoolFlag{ Name: "log-pretty", - Value: true, Usage: "Enable pretty logging", - EnvVars: []string{"THUMBNAILS_LOG_PRETTY"}, + EnvVars: []string{"THUMBNAILS_LOG_PRETTY", "OCIS_LOG_PRETTY"}, Destination: &cfg.Log.Pretty, }, &cli.BoolFlag{ Name: "log-color", - Value: true, Usage: "Enable colored logging", - EnvVars: []string{"THUMBNAILS_LOG_COLOR"}, + EnvVars: []string{"THUMBNAILS_LOG_COLOR", "OCIS_LOG_COLOR"}, Destination: &cfg.Log.Color, }, }