From dcb1602f907ca7017a4a84e268413624a917dd29 Mon Sep 17 00:00:00 2001 From: Kamesh Sampath Date: Mon, 1 Aug 2022 16:32:11 +0530 Subject: [PATCH] (fix): add labels for tooling to query containers (#218) * (fix): add labels for tooling to query containers --- drone/exec/exec.go | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/drone/exec/exec.go b/drone/exec/exec.go index f21e6ee..4686ed7 100644 --- a/drone/exec/exec.go +++ b/drone/exec/exec.go @@ -19,6 +19,7 @@ import ( "github.com/drone/envsubst" "github.com/drone/runner-go/environ" "github.com/drone/runner-go/environ/provider" + "github.com/drone/runner-go/labels" "github.com/drone/runner-go/logger" "github.com/drone/runner-go/manifest" "github.com/drone/runner-go/pipeline" @@ -227,7 +228,15 @@ func exec(cliContext *cli.Context) error { // disabled in favor of mounting the source code // from the current working directory. if !commy.Clone { - comp.Mount, _ = os.Getwd() + pwd, _ := os.Getwd() + comp.Mount = pwd + //Add the new labels that helps looking up the step containers + //by names + if comp.Labels == nil { + comp.Labels = make(map[string]string) + } + comp.Labels["io.drone.desktop.pipeline.dir"] = pwd + } args := runtime.CompilerArgs{ @@ -241,6 +250,15 @@ func exec(cliContext *cli.Context) error { } spec := comp.Compile(nocontext, args).(*engine.Spec) + //As the Compiler does not add labels for Steps adding few here + for i, step := range spec.Steps { + step.Labels = labels.Combine(step.Labels, + map[string]string{ + "io.drone.step.name": step.Name, + "io.drone.step.number": fmt.Sprint(i), + }) + } + // include only steps that are in the include list, // if the list in non-empty. if len(commy.Include) > 0 { @@ -294,6 +312,7 @@ func exec(cliContext *cli.Context) error { if step.RunPolicy == runtime.RunNever { continue } + commy.Stage.Steps = append(commy.Stage.Steps, &drone.Step{ StageID: commy.Stage.ID, Number: len(commy.Stage.Steps) + 1,