diff --git a/Makefile b/Makefile index 6b5dcf4..32495dd 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/pkg/dagger/runner.go b/pkg/dagger/runner.go index 04bbc5a..edb0051 100644 --- a/pkg/dagger/runner.go +++ b/pkg/dagger/runner.go @@ -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 { @@ -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) }