Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simple Ocis Binary #79

Merged
merged 13 commits into from
Jan 10, 2020
2 changes: 2 additions & 0 deletions pkg/command/graph.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// +build !simple

package command

import (
Expand Down
5 changes: 5 additions & 0 deletions pkg/command/health.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/micro/cli"
"github.com/owncloud/ocis/pkg/config"
"github.com/owncloud/ocis/pkg/flagset"
"github.com/owncloud/ocis/pkg/register"
)

// Health is the entrypoint for the health command.
Expand Down Expand Up @@ -47,3 +48,7 @@ func Health(cfg *config.Config) cli.Command {
},
}
}

func init() {
register.AddCommand(Health)
}
2 changes: 2 additions & 0 deletions pkg/command/konnectd.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// +build simple

package command

import (
Expand Down
2 changes: 2 additions & 0 deletions pkg/command/ocs.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// +build !simple

package command

import (
Expand Down
2 changes: 2 additions & 0 deletions pkg/command/reva.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// +build !simple

package command

import (
Expand Down
10 changes: 0 additions & 10 deletions pkg/command/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,26 +74,16 @@ func Execute() error {

return nil
},

Commands: []cli.Command{
Server(cfg),
Health(cfg),
},
}

// TODO(refs) fix this interface and make it play nice with cli.Command to reuse and skip
// doing runtime.AddRuntime(app)
for _, fn := range register.Commands {
app.Commands = append(
app.Commands,
fn(cfg),
)
}

// add runtime commands to the binary
runtime.AddRuntime(app)

// add the runtime.Run command to the binary
app.Commands = append(
app.Commands,
runtime.Command(app),
Expand Down
7 changes: 7 additions & 0 deletions pkg/command/server.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// +build !simple

package command

import (
Expand All @@ -14,6 +16,7 @@ import (
"github.com/owncloud/ocis/pkg/config"
"github.com/owncloud/ocis/pkg/flagset"
"github.com/owncloud/ocis/pkg/micro/runtime"
"github.com/owncloud/ocis/pkg/register"
"go.opencensus.io/stats/view"
"go.opencensus.io/trace"
)
Expand Down Expand Up @@ -135,3 +138,7 @@ func Server(cfg *config.Config) cli.Command {
},
}
}

func init() {
register.AddCommand(Server)
}
153 changes: 153 additions & 0 deletions pkg/command/simple.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
// +build simple

package command

import (
"strings"
"time"

"contrib.go.opencensus.io/exporter/jaeger"
"contrib.go.opencensus.io/exporter/ocagent"
"contrib.go.opencensus.io/exporter/zipkin"
"github.com/micro/cli"
"github.com/micro/go-micro/config/cmd"
openzipkin "github.com/openzipkin/zipkin-go"
zipkinhttp "github.com/openzipkin/zipkin-go/reporter/http"
"github.com/owncloud/ocis/pkg/config"
"github.com/owncloud/ocis/pkg/flagset"
"github.com/owncloud/ocis/pkg/micro/runtime"
"github.com/owncloud/ocis/pkg/register"
"go.opencensus.io/stats/view"
"go.opencensus.io/trace"
)

// Simple is the entrypoint for the server command.
func Simple(cfg *config.Config) cli.Command {
return cli.Command{
Name: "server",
Usage: "Start fullstack server",
Category: "Fullstack",
Flags: flagset.ServerWithConfig(cfg),
Before: func(c *cli.Context) error {
if cfg.HTTP.Root != "/" {
cfg.HTTP.Root = strings.TrimSuffix(cfg.HTTP.Root, "/")
}

return nil
},
Action: func(c *cli.Context) error {
logger := NewLogger(cfg)

if cfg.Tracing.Enabled {
switch t := cfg.Tracing.Type; t {
case "agent":
exporter, err := ocagent.NewExporter(
ocagent.WithReconnectionPeriod(5*time.Second),
ocagent.WithAddress(cfg.Tracing.Endpoint),
ocagent.WithServiceName(cfg.Tracing.Service),
)

if err != nil {
logger.Error().
Err(err).
Str("endpoint", cfg.Tracing.Endpoint).
Str("collector", cfg.Tracing.Collector).
Msg("Failed to create agent tracing")

return err
}

trace.RegisterExporter(exporter)
view.RegisterExporter(exporter)

case "jaeger":
exporter, err := jaeger.NewExporter(
jaeger.Options{
AgentEndpoint: cfg.Tracing.Endpoint,
CollectorEndpoint: cfg.Tracing.Collector,
ServiceName: cfg.Tracing.Service,
},
)

if err != nil {
logger.Error().
Err(err).
Str("endpoint", cfg.Tracing.Endpoint).
Str("collector", cfg.Tracing.Collector).
Msg("Failed to create jaeger tracing")

return err
}

trace.RegisterExporter(exporter)

case "zipkin":
endpoint, err := openzipkin.NewEndpoint(
cfg.Tracing.Service,
cfg.Tracing.Endpoint,
)

if err != nil {
logger.Error().
Err(err).
Str("endpoint", cfg.Tracing.Endpoint).
Str("collector", cfg.Tracing.Collector).
Msg("Failed to create zipkin tracing")

return err
}

exporter := zipkin.NewExporter(
zipkinhttp.NewReporter(
cfg.Tracing.Collector,
),
endpoint,
)

trace.RegisterExporter(exporter)

default:
logger.Warn().
Str("type", t).
Msg("Unknown tracing backend")
}

trace.ApplyConfig(
trace.Config{
DefaultSampler: trace.AlwaysSample(),
},
)
} else {
logger.Debug().
Msg("Tracing is not enabled")
}

runtime := runtime.New(
runtime.Services(
append(
runtime.RuntimeServices,
[]string{
"hello",
"konnectd",
"phoenix",
}...,
),
),
runtime.Logger(logger),
runtime.MicroRuntime(cmd.DefaultCmd.Options().Runtime),
)

// fork uses the micro runtime to fork go-micro services
runtime.Start()

// trap blocks until a kill signal is sent
runtime.Trap()

return nil
},
}
}

func init() {
register.AddCommand(Simple)
}
2 changes: 2 additions & 0 deletions pkg/command/webdav.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// +build !simple

package command

import (
Expand Down
62 changes: 0 additions & 62 deletions pkg/micro/runtime/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,12 @@ import (
"github.com/micro/micro/broker"
"github.com/micro/micro/health"
"github.com/micro/micro/monitor"
"github.com/micro/micro/network"
"github.com/micro/micro/plugin/build"
"github.com/micro/micro/proxy"
"github.com/micro/micro/registry"
"github.com/micro/micro/router"
"github.com/micro/micro/runtime"
"github.com/micro/micro/server"
"github.com/micro/micro/service"
"github.com/micro/micro/store"
"github.com/micro/micro/token"
"github.com/micro/micro/tunnel"
"github.com/micro/micro/web"
"github.com/owncloud/ocis-pkg/log"
Expand All @@ -31,19 +27,13 @@ var OwncloudNamespace = "com.owncloud."

// RuntimeServices to start as part of the fullstack option
var RuntimeServices = []string{
// "network", // :8085
"runtime", // :8088
"registry", // :8000
"broker", // :8001
"store", // :8002
"tunnel", // :8083
"router", // :8084
"proxy", // :8081
"api", // :8080
"web", // :8082
"monitor", // :????
// "debug", // :????
// "bot", // :????
}

// Extensions are ocis extension services
Expand Down Expand Up @@ -106,7 +96,6 @@ func (r *Runtime) Start() {
// the binary calls itself with the micro service as a subcommand as first argument
gorun.WithCommand(os.Args[0], service),
gorun.WithEnv(env),
// and logs to STDOUT. Perhaps this can be overridden to use a log.Logger
gorun.WithOutput(os.Stdout),
}

Expand All @@ -119,28 +108,16 @@ func (r *Runtime) Start() {

// AddRuntime adds the micro subcommands to the cli app
func AddRuntime(app *cli.App) {
// load this from disk / env?
setDefaults()

app.Commands = append(app.Commands, api.Commands()...)
app.Commands = append(app.Commands, broker.Commands()...)
app.Commands = append(app.Commands, health.Commands()...)
app.Commands = append(app.Commands, proxy.Commands()...)
app.Commands = append(app.Commands, monitor.Commands()...)
app.Commands = append(app.Commands, router.Commands()...)
app.Commands = append(app.Commands, tunnel.Commands()...)
app.Commands = append(app.Commands, network.Commands()...)
app.Commands = append(app.Commands, registry.Commands()...)
app.Commands = append(app.Commands, runtime.Commands()...)
app.Commands = append(app.Commands, server.Commands()...)
app.Commands = append(app.Commands, service.Commands()...)
app.Commands = append(app.Commands, store.Commands()...)
app.Commands = append(app.Commands, token.Commands()...)
app.Commands = append(app.Commands, build.Commands()...)
app.Commands = append(app.Commands, web.Commands()...)
// app.Commands = append(app.Commands, bot.Commands()...)
// app.Commands = append(app.Commands, new.Commands()...)
// app.Commands = append(app.Commands, debug.Commands()...)
}

// provide a config.Config with default values?
Expand All @@ -149,74 +126,35 @@ func setDefaults() {
api.Name = OwncloudNamespace + "api"
api.Namespace = OwncloudNamespace + "api"
api.HeaderPrefix = "X-Micro-Owncloud-"
// api.EnableRPC = false
// api.RPCPath
// api.Address
// api.Handler
// api.Resolver
// api.ProxyPath
// api.APIPath

// broker
broker.Name = OwncloudNamespace + "http.broker"
// broker.Address

// proxy
proxy.Name = OwncloudNamespace + "proxy"
// proxy.Address
// proxy.Protocol
// proxy.Endpoint

// monitor
monitor.Name = OwncloudNamespace + "monitor"

// router
router.Name = OwncloudNamespace + "router"
// router.Address
// router.Network
// router.Topic

// tunnel
tunnel.Name = OwncloudNamespace + "tunnel"
// tunnel.Address
// tunnel.Token
// tunnel.Tunnel

// network
network.Name = OwncloudNamespace + "network"
// network.Address
// network.Advertise
// network.Resolver
// network.Token

// registry
registry.Name = OwncloudNamespace + "registry"
// registry.Address
// registry.SyncTime
// registry.Topic

// runtime
runtime.Name = OwncloudNamespace + "runtime"
// runtime.Address

// server
server.Name = OwncloudNamespace + "server"
// server.Address
// server.Network
// server.Router

// store
store.Name = OwncloudNamespace + "store"
// store.Address

// web
web.Name = OwncloudNamespace + "web"
web.Namespace = OwncloudNamespace + "web"
// web.ACMECA
// web.ACMEChallengeProvider
// web.ACMEProvider
// web.Address
// web.BasePathHeader
// web.DefaultIcon

}