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
21 changes: 21 additions & 0 deletions docs/content/building.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,27 @@ cd ocis

All required tool besides Go itself and make are bundled or getting automatically installed within the `GOPATH`. All commands to build this project are part of our `Makefile`.

### Simple Ocis

Building the simple ocis binary:

```console
TAGS=simple make build
```

The artifact lives in `/bin/ocis`

The generated simple ocis binary is a subset of the ocis command with a restricted set of services meant for ease up development. The services included are


```
ocis-hello
phoenix
konnectd
devldap
micro's own services
```

### Backend

{{< highlight txt >}}
Expand Down
42 changes: 42 additions & 0 deletions go.sum

Large diffs are not rendered by default.

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
100 changes: 10 additions & 90 deletions pkg/command/server.go
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
// +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"
"go.opencensus.io/stats/view"
"go.opencensus.io/trace"
"github.com/owncloud/ocis/pkg/register"
"github.com/owncloud/ocis/pkg/tracing"
)

// Server is the entrypoint for the server command.
Expand All @@ -35,88 +31,8 @@ func Server(cfg *config.Config) cli.Command {
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")
if err := tracing.Start(cfg); err != nil {
return err
}

runtime := runtime.New(
Expand All @@ -135,3 +51,7 @@ func Server(cfg *config.Config) cli.Command {
},
}
}

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

package command

import (
"strings"

"github.com/micro/cli"
"github.com/micro/go-micro/config/cmd"
"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"
"github.com/owncloud/ocis/pkg/tracing"
)

var (
// SimpleRuntimeServices declares which services will be started for the fullstack server
SimpleRuntimeServices = []string{"hello", "konnectd", "phoenix"}
)

// Simple is the entrypoint for the server command. It is the `ocis server` subcommand overloaded with a different set of services
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 err := tracing.Start(cfg); err != nil {
return err
}

runtime := runtime.New(
runtime.Logger(logger),
runtime.Services(append(runtime.RuntimeServices, SimpleRuntimeServices...)),
runtime.MicroRuntime(cmd.DefaultCmd.Options().Runtime),
)

{
runtime.Start()
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
Loading