Skip to content

Commit 87a6e95

Browse files
added --set and --set-string flags to run-pipelines and run-default-pipeline
1 parent 21f818f commit 87a6e95

4 files changed

Lines changed: 97 additions & 1 deletion

File tree

e2e/tests/pipelines/pipelines.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,26 @@ var _ = DevSpaceDescribe("pipelines", func() {
120120
}
121121
})
122122

123+
ginkgo.FIt("should get value from config", func() {
124+
tempDir, err := framework.CopyToTempDir("tests/pipelines/testdata/getconfigvalue")
125+
framework.ExpectNoError(err)
126+
defer framework.CleanupTempDir(initialDir, tempDir)
127+
128+
ns, err := kubeClient.CreateNamespace("pipelines")
129+
framework.ExpectNoError(err)
130+
defer framework.ExpectDeleteNamespace(kubeClient, ns)
131+
132+
devCmd := &cmd.RunPipelineCmd{
133+
GlobalFlags: &flags.GlobalFlags{
134+
NoWarn: true,
135+
Namespace: ns,
136+
},
137+
Pipeline: "dev",
138+
}
139+
err = devCmd.RunDefault(f)
140+
framework.ExpectNoError(err)
141+
})
142+
123143
ginkgo.It("should get value from config", func() {
124144
tempDir, err := framework.CopyToTempDir("tests/pipelines/testdata/getconfigvalue")
125145
framework.ExpectNoError(err)

pkg/devspace/pipeline/engine/pipelinehandler/commands/create_deployments.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ func applySetValues(ctx devspacecontext.Context, name, objName string, set, setS
147147
continue
148148
}
149149

150-
err = strvals.ParseInto(s, mapObj)
150+
err = strvals.ParseIntoString(s, mapObj)
151151
if err != nil {
152152
return nil, errors.Wrap(err, "parsing --set-string flag")
153153
}

pkg/devspace/pipeline/engine/pipelinehandler/commands/run_default_pipeline.go

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,25 @@ package commands
22

33
import (
44
"fmt"
5+
"github.com/jessevdk/go-flags"
6+
"github.com/loft-sh/devspace/pkg/devspace/config"
7+
"github.com/loft-sh/devspace/pkg/devspace/config/versions"
8+
"github.com/loft-sh/devspace/pkg/devspace/config/versions/util"
59
devspacecontext "github.com/loft-sh/devspace/pkg/devspace/context"
610
"github.com/loft-sh/devspace/pkg/devspace/pipeline/engine"
711
enginetypes "github.com/loft-sh/devspace/pkg/devspace/pipeline/engine/types"
812
"github.com/loft-sh/devspace/pkg/devspace/pipeline/types"
13+
"github.com/loft-sh/devspace/pkg/util/strvals"
14+
"github.com/pkg/errors"
915
"io"
1016
"mvdan.cc/sh/v3/interp"
1117
)
1218

19+
type RunDefaultPipelineOptions struct {
20+
Set []string `long:"set" description:"Set configuration"`
21+
SetString []string `long:"set-string" description:"Set configuration as string"`
22+
}
23+
1324
type NewHandlerFn func(ctx devspacecontext.Context, stdout, stderr io.Writer, pipeline types.Pipeline) enginetypes.ExecHandler
1425

1526
func RunDefaultPipeline(ctx devspacecontext.Context, pipeline types.Pipeline, args []string, newHandler NewHandlerFn) error {
@@ -19,10 +30,24 @@ func RunDefaultPipeline(ctx devspacecontext.Context, pipeline types.Pipeline, ar
1930
}
2031

2132
hc := interp.HandlerCtx(ctx.Context())
33+
34+
options := &RunDefaultPipelineOptions{}
35+
args, err = flags.ParseArgs(options, args)
36+
if err != nil {
37+
return errors.Wrap(err, "parse args")
38+
}
39+
2240
if len(args) != 1 {
2341
return fmt.Errorf("usage: run_default_pipeline [pipeline]")
2442
}
2543

44+
if len(args) > 0 {
45+
ctx, err = applyPipelineSetValue(ctx, options.Set, options.SetString)
46+
if err != nil {
47+
return err
48+
}
49+
}
50+
2651
defaultPipeline, err := types.GetDefaultPipeline(args[0])
2752
if err != nil {
2853
return err
@@ -31,3 +56,45 @@ func RunDefaultPipeline(ctx devspacecontext.Context, pipeline types.Pipeline, ar
3156
_, err = engine.ExecutePipelineShellCommand(ctx.Context(), defaultPipeline.Run, nil, hc.Dir, false, hc.Stdout, hc.Stderr, hc.Stdin, hc.Env, newHandler(ctx, hc.Stdout, hc.Stderr, pipeline))
3257
return err
3358
}
59+
60+
func applyPipelineSetValue(ctx devspacecontext.Context, set, setString []string) (devspacecontext.Context, error) {
61+
if len(set) == 0 && len(setString) == 0 {
62+
return ctx, nil
63+
}
64+
65+
rawConfigOriginal := ctx.Config().RawBeforeConversion()
66+
rawConfig := map[string]interface{}{}
67+
err := util.Convert(rawConfigOriginal, &rawConfig)
68+
if err != nil {
69+
return nil, err
70+
}
71+
72+
for _, s := range set {
73+
err = strvals.ParseInto(s, rawConfig)
74+
if err != nil {
75+
return nil, errors.Wrap(err, "parsing --set flag")
76+
}
77+
}
78+
79+
for _, s := range setString {
80+
err = strvals.ParseIntoString(s, rawConfig)
81+
if err != nil {
82+
return nil, errors.Wrap(err, "parsing --set-string flag")
83+
}
84+
}
85+
86+
latestConfig, err := versions.Parse(rawConfig, ctx.Log())
87+
if err != nil {
88+
return nil, err
89+
}
90+
91+
return ctx.WithConfig(config.NewConfig(
92+
ctx.Config().Raw(),
93+
rawConfig,
94+
latestConfig,
95+
ctx.Config().LocalCache(),
96+
ctx.Config().RemoteCache(),
97+
ctx.Config().Variables(),
98+
ctx.Config().Path(),
99+
)), nil
100+
}

pkg/devspace/pipeline/engine/pipelinehandler/commands/run_pipelines.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ import (
1313

1414
type RunPipelineOptions struct {
1515
types.PipelineOptions
16+
Set []string `long:"set" description:"Set configuration"`
17+
SetString []string `long:"set-string" description:"Set configuration as string"`
1618
}
1719

1820
func RunPipelines(ctx devspacecontext.Context, pipeline types.Pipeline, args []string, environ expand.Environ) error {
@@ -23,6 +25,13 @@ func RunPipelines(ctx devspacecontext.Context, pipeline types.Pipeline, args []s
2325
return errors.Wrap(err, "parse args")
2426
}
2527

28+
if len(args) > 0 {
29+
ctx, err = applyPipelineSetValue(ctx, options.Set, options.SetString)
30+
if err != nil {
31+
return err
32+
}
33+
}
34+
2635
pipelines := []*latest.Pipeline{}
2736
for _, arg := range args {
2837
if arg == "" {

0 commit comments

Comments
 (0)