mirror of
https://github.com/go-micro/go-micro.git
synced 2024-12-24 10:07:04 +02:00
Runtime (#1160)
* Add String to Runtime interface * Setup Dynamic Runtime Configuration
This commit is contained in:
parent
4333f00a43
commit
bf747a86f4
@ -40,6 +40,11 @@ import (
|
||||
rmem "github.com/micro/go-micro/v2/registry/memory"
|
||||
regSrv "github.com/micro/go-micro/v2/registry/service"
|
||||
|
||||
// runtimes
|
||||
kRuntime "github.com/micro/go-micro/v2/runtime/kubernetes"
|
||||
lRuntime "github.com/micro/go-micro/v2/runtime/local"
|
||||
srvRuntime "github.com/micro/go-micro/v2/runtime/service"
|
||||
|
||||
// selectors
|
||||
"github.com/micro/go-micro/v2/client/selector/dns"
|
||||
"github.com/micro/go-micro/v2/client/selector/router"
|
||||
@ -188,6 +193,12 @@ var (
|
||||
EnvVars: []string{"MICRO_RUNTIME"},
|
||||
Value: "local",
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "runtime_source",
|
||||
Usage: "Runtime source for building and running services e.g github.com/micro/service",
|
||||
EnvVars: []string{"MICRO_RUNTIME_SOURCE"},
|
||||
Value: "github.com/micro/services",
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "selector",
|
||||
EnvVars: []string{"MICRO_SELECTOR"},
|
||||
@ -281,7 +292,9 @@ var (
|
||||
}
|
||||
|
||||
DefaultRuntimes = map[string]func(...runtime.Option) runtime.Runtime{
|
||||
"local": runtime.NewRuntime,
|
||||
"local": lRuntime.NewRuntime,
|
||||
"service": srvRuntime.NewRuntime,
|
||||
"kubernetes": kRuntime.NewRuntime,
|
||||
}
|
||||
|
||||
DefaultStores = map[string]func(...store.Option) store.Store{
|
||||
@ -580,6 +593,12 @@ func (c *cmd) Before(ctx *cli.Context) error {
|
||||
}
|
||||
}
|
||||
|
||||
if len(ctx.String("runtime_source")) > 0 {
|
||||
if err := (*c.opts.Runtime).Init(runtime.WithSource(ctx.String("runtime_source"))); err != nil {
|
||||
log.Fatalf("Error configuring runtime: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
// client opts
|
||||
if r := ctx.Int("client_retries"); r >= 0 {
|
||||
clientOpts = append(clientOpts, client.Retries(r))
|
||||
|
@ -2,7 +2,9 @@
|
||||
package kubernetes
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
@ -245,6 +247,10 @@ func (k *kubernetes) Init(opts ...runtime.Option) error {
|
||||
o(&k.options)
|
||||
}
|
||||
|
||||
if strings.HasPrefix(k.options.Source, "github.com") {
|
||||
return errors.New("invalid source provided to kubernetes runtime, expected docker image")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
11
runtime/local/local.go
Normal file
11
runtime/local/local.go
Normal file
@ -0,0 +1,11 @@
|
||||
// Package local provides a local runtime
|
||||
package local
|
||||
|
||||
import (
|
||||
"github.com/micro/go-micro/v2/runtime"
|
||||
)
|
||||
|
||||
// NewRuntime returns a new local runtime
|
||||
func NewRuntime(opts ...runtime.Option) runtime.Runtime {
|
||||
return runtime.NewRuntime(opts...)
|
||||
}
|
@ -12,6 +12,15 @@ type Options struct {
|
||||
Scheduler Scheduler
|
||||
// Service type to manage
|
||||
Type string
|
||||
// Source of the services repository
|
||||
Source string
|
||||
}
|
||||
|
||||
// WithSource sets the host addresses to be used by the broker
|
||||
func WithSource(src string) Option {
|
||||
return func(o *Options) {
|
||||
o.Source = src
|
||||
}
|
||||
}
|
||||
|
||||
// WithScheduler specifies a scheduler for updates
|
||||
|
@ -17,6 +17,8 @@ var (
|
||||
|
||||
// Runtime is a service runtime manager
|
||||
type Runtime interface {
|
||||
// String describes runtime
|
||||
String() string
|
||||
// Init initializes runtime
|
||||
Init(...Option) error
|
||||
// Create registers a service
|
||||
|
@ -170,6 +170,8 @@ func (s *service) Wait() {
|
||||
s.Metadata["status"] = "error"
|
||||
s.Metadata["error"] = err.Error()
|
||||
s.err = err
|
||||
} else {
|
||||
s.Metadata["status"] = "done"
|
||||
}
|
||||
|
||||
// no longer running
|
||||
|
Loading…
Reference in New Issue
Block a user