Skip to content

Commit

Permalink
fix: better engine selector
Browse files Browse the repository at this point in the history
  • Loading branch information
morlay committed Jun 12, 2024
1 parent 2892b5e commit ac9b7a6
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ ifeq ($(DEBUG),1)
PIPER := $(PIPER) --log-level=debug
endif

#export PIPER_BUILDER_HOST =
export PIPER_BUILDER_HOST =

tidy:
$(PIPER) mod tidy
Expand Down
37 changes: 24 additions & 13 deletions pkg/dagger/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,26 +104,21 @@ type runner struct {
engines sync.Map
}

func (r *runner) ClientParams(scope *Scope) client.Params {
runnerHost := r.GetHost(scope.Platform)
p := r.Params
p.RunnerHost = runnerHost.RunnerHost
scope.ID = runnerHost.Name
return p
func (r *runner) ClientParams(host string) client.Params {
return r.Hosts.ClientParams(host)
}

func (r *runner) Select(ctx context.Context, scope Scope) Engine {
if scope.Platform == "" {
scope.Platform = Platform(fmt.Sprintf("linux/%s", runtime.GOARCH))
}

if v, ok := r.engines.Load(scope.ID); ok {
return v.(Engine)
if scope.ID == "" {
scope.ID = r.GetHost(scope.Platform).Name
}

e := NewEngine(scope, r.ClientParams(&scope))
r.engines.Store(scope.ID, e)
return e
getEngine, _ := r.engines.LoadOrStore(scope.ID, sync.OnceValue(func() Engine {
return NewEngine(scope, r.ClientParams(scope.ID))
}))
return getEngine.(func() Engine)()
}

func (r *runner) Shutdown(ctx context.Context) error {
Expand Down Expand Up @@ -171,6 +166,22 @@ func (h *Hosts) AddHost(runnerHost *PiperRunnerHost) {
}
}

func (h *Hosts) ClientParams(name string) client.Params {
for _, hh := range h.Platformed {
for _, p := range hh {
if p.Name == name {
return client.Params{
RunnerHost: p.RunnerHost,
}
}
}
}

return client.Params{
RunnerHost: h.Default.RunnerHost,
}
}

func Select(ctx context.Context, scope Scope) Engine {
return RunnerContext.From(ctx).Select(ctx, scope)
}

0 comments on commit ac9b7a6

Please sign in to comment.