Skip to content

Commit 9b632ac

Browse files
committed
feat: add pipelines.*.defaults
1 parent 3499dc2 commit 9b632ac

11 files changed

Lines changed: 41 additions & 38 deletions

File tree

cmd/build.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ func NewBuildCmd(f factory.Factory, globalFlags *flags.GlobalFlags, rawConfig *R
1414
Pipeline: "build",
1515
ForceBuild: true,
1616
}
17+
18+
var pipeline *latest.Pipeline
19+
if rawConfig != nil && rawConfig.Config != nil && rawConfig.Config.Pipelines != nil {
20+
pipeline = rawConfig.Config.Pipelines["build"]
21+
}
1722
buildCmd := &cobra.Command{
1823
Use: "build",
1924
Short: "Builds all defined images and pushes them",
@@ -27,11 +32,6 @@ Builds all defined images and pushes them
2732
return cmd.Run(cobraCmd, args, f, "buildCommand")
2833
},
2934
}
30-
31-
var pipeline *latest.Pipeline
32-
if rawConfig != nil && rawConfig.Config != nil && rawConfig.Config.Pipelines != nil {
33-
pipeline = rawConfig.Config.Pipelines["build"]
34-
}
3535
cmd.AddPipelineFlags(f, buildCmd, pipeline)
3636
return buildCmd
3737
}

cmd/deploy.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ func NewDeployCmd(f factory.Factory, globalFlags *flags.GlobalFlags, rawConfig *
1515
Pipeline: "deploy",
1616
}
1717

18+
var pipeline *latest.Pipeline
19+
if rawConfig != nil && rawConfig.Config != nil && rawConfig.Config.Pipelines != nil {
20+
pipeline = rawConfig.Config.Pipelines["deploy"]
21+
}
1822
deployCmd := &cobra.Command{
1923
Use: "deploy",
2024
Short: "Deploys the project",
@@ -32,11 +36,6 @@ devspace deploy --kube-context=deploy-context
3236
return cmd.Run(cobraCmd, args, f, "deployCommand")
3337
},
3438
}
35-
36-
var pipeline *latest.Pipeline
37-
if rawConfig != nil && rawConfig.Config != nil && rawConfig.Config.Pipelines != nil {
38-
pipeline = rawConfig.Config.Pipelines["deploy"]
39-
}
4039
cmd.AddPipelineFlags(f, deployCmd, pipeline)
4140
return deployCmd
4241
}

cmd/dev.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ func NewDevCmd(f factory.Factory, globalFlags *flags.GlobalFlags, rawConfig *Raw
1414
SkipPushLocalKubernetes: true,
1515
Pipeline: "dev",
1616
}
17+
18+
var pipeline *latest.Pipeline
19+
if rawConfig != nil && rawConfig.Config != nil && rawConfig.Config.Pipelines != nil {
20+
pipeline = rawConfig.Config.Pipelines["dev"]
21+
}
1722
devCmd := &cobra.Command{
1823
Use: "dev",
1924
Short: "Starts the development mode",
@@ -27,11 +32,6 @@ Starts your project in development mode
2732
return cmd.Run(cobraCmd, args, f, "devCommand")
2833
},
2934
}
30-
31-
var pipeline *latest.Pipeline
32-
if rawConfig != nil && rawConfig.Config != nil && rawConfig.Config.Pipelines != nil {
33-
pipeline = rawConfig.Config.Pipelines["dev"]
34-
}
3535
cmd.AddPipelineFlags(f, devCmd, pipeline)
3636
return devCmd
3737
}

cmd/purge.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ func NewPurgeCmd(f factory.Factory, globalFlags *flags.GlobalFlags, rawConfig *R
1515
Pipeline: "purge",
1616
SkipPushLocalKubernetes: true,
1717
}
18+
19+
var pipeline *latest.Pipeline
20+
if rawConfig != nil && rawConfig.Config != nil && rawConfig.Config.Pipelines != nil {
21+
pipeline = rawConfig.Config.Pipelines["purge"]
22+
}
1823
purgeCmd := &cobra.Command{
1924
Use: "purge",
2025
Short: "Deletes deployed resources",
@@ -30,11 +35,6 @@ devspace purge
3035
return cmd.Run(cobraCmd, args, f, "purgeCommand")
3136
},
3237
}
33-
34-
var pipeline *latest.Pipeline
35-
if rawConfig != nil && rawConfig.Config != nil && rawConfig.Config.Pipelines != nil {
36-
pipeline = rawConfig.Config.Pipelines["purge"]
37-
}
3838
cmd.AddPipelineFlags(f, purgeCmd, pipeline)
3939
return purgeCmd
4040
}

cmd/render.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ func NewRenderCmd(f factory.Factory, globalFlags *flags.GlobalFlags, rawConfig *
1919
RenderWriter: os.Stdout,
2020
}
2121

22+
var pipeline *latest.Pipeline
23+
if rawConfig != nil && rawConfig.Config != nil && rawConfig.Config.Pipelines != nil {
24+
pipeline = rawConfig.Config.Pipelines["deploy"]
25+
}
2226
renderCmd := &cobra.Command{
2327
Use: "render",
2428
Short: "Builds all defined images and shows the yamls that would be deployed",
@@ -35,11 +39,6 @@ deployment.
3539
return cmd.Run(cobraCmd, args, f, "renderCommand")
3640
},
3741
}
38-
39-
var pipeline *latest.Pipeline
40-
if rawConfig != nil && rawConfig.Config != nil && rawConfig.Config.Pipelines != nil {
41-
pipeline = rawConfig.Config.Pipelines["deploy"]
42-
}
4342
cmd.AddPipelineFlags(f, renderCmd, pipeline)
4443
return renderCmd
4544
}

cmd/run_pipeline.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -196,10 +196,6 @@ func NewSpecificPipelineCmd(f factory.Factory, globalFlags *flags.GlobalFlags, p
196196
Executes pipeline ` + pipeline.Name + `
197197
#######################################################`,
198198
RunE: func(cobraCmd *cobra.Command, args []string) error {
199-
if pipeline.DefaultNamespace != "" && globalFlags.Namespace == "" {
200-
globalFlags.Namespace = pipeline.DefaultNamespace
201-
}
202-
203199
return cmd.Run(cobraCmd, args, f, "runPipelineCommand")
204200
},
205201
}
@@ -430,6 +426,12 @@ func runPipeline(ctx devspacecontext.Context, args []string, options *CommandOpt
430426
var configPipeline *latest.Pipeline
431427
if ctx.Config().Config().Pipelines != nil && ctx.Config().Config().Pipelines[options.Pipeline] != nil {
432428
configPipeline = ctx.Config().Config().Pipelines[options.Pipeline]
429+
if configPipeline.Run == "" {
430+
defaultPipeline, _ := types.GetDefaultPipeline(options.Pipeline)
431+
if defaultPipeline != nil {
432+
configPipeline.Run = defaultPipeline.Run
433+
}
434+
}
433435
} else {
434436
var err error
435437
configPipeline, err = types.GetDefaultPipeline(options.Pipeline)

pkg/devspace/build/builder/helper/helper.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"github.com/docker/cli/cli/command/image/build"
55
"github.com/docker/docker/api/types"
66
"github.com/docker/docker/pkg/archive"
7+
"github.com/loft-sh/devspace/pkg/devspace/config/localcache"
78
"github.com/loft-sh/devspace/pkg/devspace/config/versions/latest"
89
devspacecontext "github.com/loft-sh/devspace/pkg/devspace/context"
910
dockerclient "github.com/loft-sh/devspace/pkg/devspace/docker"
@@ -146,6 +147,10 @@ func (b *BuildHelper) ShouldRebuild(ctx devspacecontext.Context, forceRebuild bo
146147
if !mustRebuild && ctx.KubeClient() != nil && ctx.Config().LocalCache().GetLastContext() != nil && ctx.Config().LocalCache().GetLastContext().Context != ctx.KubeClient().CurrentContext() && kubectl.IsLocalKubernetes(ctx.Config().LocalCache().GetLastContext().Context) {
147148
mustRebuild = true
148149
ctx.Log().Infof("Rebuild image %s because previous build was local kubernetes", imageCache.ImageName)
150+
ctx.Config().LocalCache().SetLastContext(&localcache.LastContextConfig{
151+
Namespace: ctx.KubeClient().Namespace(),
152+
Context: ctx.KubeClient().CurrentContext(),
153+
})
149154
}
150155

151156
// Check if should consider context path changes for rebuilding

pkg/devspace/config/loader/variable/resolver.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ func (r *resolver) FillVariablesInclude(ctx context.Context, haystack interface{
244244
for _, path := range includedPaths {
245245
path = strings.ReplaceAll(path, "*", "[^/]+")
246246
path = strings.ReplaceAll(path, "**", ".+")
247-
path = "^" + path
247+
path = "^" + path + "$"
248248
expr, err := regexp.Compile(path)
249249
if err != nil {
250250
return nil, err
@@ -274,7 +274,7 @@ func (r *resolver) FillVariablesExclude(ctx context.Context, haystack interface{
274274
for _, path := range excludedPaths {
275275
path = strings.ReplaceAll(path, "*", "[^/]+")
276276
path = strings.ReplaceAll(path, "**", ".+")
277-
path = "^" + path
277+
path = "^" + path + "$"
278278
expr, err := regexp.Compile(path)
279279
if err != nil {
280280
return nil, err

pkg/devspace/config/loader/variable/runtime/runtime_variable.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ import (
1414
var Locations = []string{
1515
"/images/*/build/custom/command",
1616
"/images/*/build/custom/commands/*/command",
17-
"/images/*/build/custom/args/*",
18-
"/images/*/build/custom/appendArgs/*",
17+
"/images/*/build/custom/args/**",
18+
"/images/*/build/custom/appendArgs/**",
1919
"/deployments/*/helm/values/**",
2020
"/hooks/*/command",
2121
"/hooks/*/args/*",
@@ -29,7 +29,8 @@ var Locations = []string{
2929
"/dev/replacePods/*/imageSelector",
3030
"/dev/replacePods/*/replaceImage",
3131
"/dev/terminal/imageSelector",
32-
"/pipelines/**",
32+
"/pipelines/*",
33+
"/pipelines/*/run",
3334
"/commands/*",
3435
"/commands/*/command",
3536
"/functions/**",

pkg/devspace/config/versions/latest/schema.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,6 @@ type Pipeline struct {
136136
// Name of the pipeline, will be filled automatically
137137
Name string `yaml:"name,omitempty" json:"name,omitempty" jsonschema:"enum=dev,enum=deploy,enum=build,enum=purge,enum=.*" jsonschema_description:"Name of the pipeline, will be filled automatically."`
138138

139-
// DefaultNamespace of the pipeline, if no other namespace is configured
140-
DefaultNamespace string `yaml:"defaultNamespace,omitempty" json:"defaultNamespace,omitempty"`
141-
142139
// Run is the actual shell command that should be executed during this pipeline
143140
Run string `yaml:"run,omitempty" json:"run,omitempty" jsonschema:"required" jsonschema_description:"Run is the actual shell command that should be executed during this pipeline."`
144141

0 commit comments

Comments
 (0)