diff --git a/engine/default.go b/engine/default.go index 41fe236e..188ae208 100644 --- a/engine/default.go +++ b/engine/default.go @@ -37,6 +37,10 @@ func RegisterMounter(runtime, name string, mounter runtime.Mounter) { defaultEngine.RegisterMounter(runtime, name, mounter) } +func RegisterRuntime(rt runtime.Runtime) { + defaultEngine.RegisterRuntime(rt) +} + func RegisterDatastoreProvider(name string, provider datastore.Provider) { defaultEngine.RegisterDatastoreProvider(name, provider) } diff --git a/engine/engine.go b/engine/engine.go index 7cdf0443..93446022 100644 --- a/engine/engine.go +++ b/engine/engine.go @@ -50,6 +50,7 @@ type Engine struct { broker mq.Broker ds datastore.Datastore mounters map[string]*runtime.MultiMounter + runtime runtime.Runtime coordinator *coordinator.Coordinator worker *worker.Worker dsProviders map[string]datastore.Provider @@ -281,6 +282,16 @@ func (e *Engine) RegisterMounter(rt string, name string, mounter runtime.Mounter mounters.RegisterMounter(name, mounter) } +func (e *Engine) RegisterRuntime(rt runtime.Runtime) { + e.mu.Lock() + defer e.mu.Unlock() + e.mustState(StateIdle) + if e.runtime != nil { + panic("engine: RegisterRuntime called twice") + } + e.runtime = rt +} + func (e *Engine) RegisterDatastoreProvider(name string, provider datastore.Provider) { e.mu.Lock() defer e.mu.Unlock() diff --git a/engine/engine_test.go b/engine/engine_test.go index d8b053e9..fea9d0d5 100644 --- a/engine/engine_test.go +++ b/engine/engine_test.go @@ -10,6 +10,7 @@ import ( "github.com/runabol/tork" "github.com/runabol/tork/datastore" "github.com/runabol/tork/input" + "github.com/runabol/tork/runtime/shell" "github.com/runabol/tork/mq" "github.com/runabol/tork/runtime" @@ -224,6 +225,20 @@ func TestRegisterMounter(t *testing.T) { assert.NoError(t, err) } +func TestRegisterRuntime(t *testing.T) { + eng := New(Config{Mode: ModeStandalone}) + assert.Equal(t, StateIdle, eng.state) + + eng.RegisterRuntime(shell.NewShellRuntime(shell.Config{})) + + err := eng.Start() + assert.NoError(t, err) + assert.Equal(t, StateRunning, eng.state) + + err = eng.Terminate() + assert.NoError(t, err) +} + func TestRegisterDatastoreProvider(t *testing.T) { eng := New(Config{Mode: ModeStandalone}) assert.Equal(t, StateIdle, eng.state) diff --git a/engine/worker.go b/engine/worker.go index e0c2d916..9c061a0b 100644 --- a/engine/worker.go +++ b/engine/worker.go @@ -38,6 +38,9 @@ func (e *Engine) initWorker() error { } func (e *Engine) initRuntime() (runtime.Runtime, error) { + if e.runtime != nil { + return e.runtime, nil + } runtimeType := conf.StringDefault("runtime.type", runtime.Docker) switch runtimeType { case runtime.Docker: diff --git a/runtime/shell/shell.go b/runtime/shell/shell.go index 92d15774..bd65512b 100644 --- a/runtime/shell/shell.go +++ b/runtime/shell/shell.go @@ -52,6 +52,12 @@ func NewShellRuntime(cfg Config) *ShellRuntime { if cfg.Rexec == nil { cfg.Rexec = reexec.Command } + if cfg.UID == "" { + cfg.UID = DEFAULT_UID + } + if cfg.GID == "" { + cfg.GID = DEFAULT_GID + } return &ShellRuntime{ cmds: new(syncx.Map[string, *exec.Cmd]), shell: cfg.CMD,