Skip to content

Commit 02e9ed2

Browse files
authored
Merge pull request #2016 from FabianKramm/master
Improve variable parsing & allow !/.git excludes
2 parents 05a6193 + f5644e4 commit 02e9ed2

35 files changed

Lines changed: 755 additions & 1071 deletions

File tree

cmd/build.go

Lines changed: 7 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,18 @@
11
package cmd
22

33
import (
4-
"context"
54
"github.com/loft-sh/devspace/cmd/flags"
6-
"github.com/loft-sh/devspace/pkg/devspace/build"
7-
"github.com/loft-sh/devspace/pkg/devspace/config/loader"
8-
devspacecontext "github.com/loft-sh/devspace/pkg/devspace/context"
9-
"github.com/loft-sh/devspace/pkg/devspace/context/values"
10-
pipelinetypes "github.com/loft-sh/devspace/pkg/devspace/pipeline/types"
11-
"github.com/loft-sh/devspace/pkg/devspace/plugin"
125
"github.com/loft-sh/devspace/pkg/util/factory"
136
"github.com/spf13/cobra"
147
)
158

16-
// BuildCmd is a struct that defines a command call for "build"
17-
type BuildCmd struct {
18-
*flags.GlobalFlags
19-
20-
Tags []string
21-
22-
SkipPush bool
23-
SkipPushLocalKubernetes bool
24-
SkipDependency []string
25-
Dependency []string
26-
27-
Pipeline string
28-
29-
ForceBuild bool
30-
BuildSequential bool
31-
MaxConcurrentBuilds int
32-
33-
Ctx context.Context
34-
}
35-
369
// NewBuildCmd creates a new devspace build command
3710
func NewBuildCmd(f factory.Factory, globalFlags *flags.GlobalFlags) *cobra.Command {
38-
cmd := &BuildCmd{GlobalFlags: globalFlags}
39-
11+
cmd := &RunPipelineCmd{
12+
GlobalFlags: globalFlags,
13+
Pipeline: "build",
14+
ForceBuild: true,
15+
}
4016
buildCmd := &cobra.Command{
4117
Use: "build",
4218
Short: "Builds all defined images and pushes them",
@@ -47,69 +23,10 @@ func NewBuildCmd(f factory.Factory, globalFlags *flags.GlobalFlags) *cobra.Comma
4723
Builds all defined images and pushes them
4824
#######################################################`,
4925
RunE: func(cobraCmd *cobra.Command, args []string) error {
50-
plugin.SetPluginCommand(cobraCmd, args)
51-
return cmd.Run(f)
26+
return cmd.Run(cobraCmd, args, f, "build", "buildCommand")
5227
},
5328
}
5429

55-
buildCmd.Flags().BoolVarP(&cmd.ForceBuild, "force-build", "b", false, "Forces to build every image")
56-
buildCmd.Flags().BoolVar(&cmd.BuildSequential, "build-sequential", false, "Builds the images one after another instead of in parallel")
57-
buildCmd.Flags().IntVar(&cmd.MaxConcurrentBuilds, "max-concurrent-builds", 0, "The maximum number of image builds built in parallel (0 for infinite)")
58-
59-
buildCmd.Flags().StringSliceVarP(&cmd.Tags, "tag", "t", []string{}, "Use the given tag for all built images")
60-
buildCmd.Flags().StringSliceVar(&cmd.SkipDependency, "skip-dependency", []string{}, "Skips building the following dependencies")
61-
buildCmd.Flags().StringSliceVar(&cmd.Dependency, "dependency", []string{}, "Builds only the specific named dependencies")
62-
buildCmd.Flags().StringVar(&cmd.Pipeline, "pipeline", "", "The pipeline to execute")
63-
64-
buildCmd.Flags().BoolVar(&cmd.SkipPush, "skip-push", false, "Skips image pushing, useful for minikube deployment")
65-
buildCmd.Flags().BoolVar(&cmd.SkipPushLocalKubernetes, "skip-push-local-kube", false, "Skips image pushing, if a local kubernetes environment is detected")
66-
30+
cmd.AddFlags(buildCmd)
6731
return buildCmd
6832
}
69-
70-
// Run executes the command logic
71-
func (cmd *BuildCmd) Run(f factory.Factory) error {
72-
if cmd.Ctx == nil {
73-
var cancelFn context.CancelFunc
74-
cmd.Ctx, cancelFn = context.WithCancel(context.Background())
75-
defer cancelFn()
76-
}
77-
78-
// set command in context
79-
cmd.Ctx = values.WithCommand(cmd.Ctx, "build")
80-
81-
configOptions := cmd.ToConfigOptions()
82-
ctx, err := prepare(cmd.Ctx, f, configOptions, cmd.GlobalFlags, true)
83-
if err != nil {
84-
return err
85-
}
86-
87-
return runWithHooks(ctx, "buildCommand", func() error {
88-
return cmd.runCommand(ctx, f, configOptions)
89-
})
90-
}
91-
92-
func (cmd *BuildCmd) runCommand(ctx *devspacecontext.Context, f factory.Factory, configOptions *loader.ConfigOptions) error {
93-
if cmd.Pipeline == "" {
94-
cmd.Pipeline = "build"
95-
}
96-
97-
return runPipeline(ctx, f, true, &PipelineOptions{
98-
Options: pipelinetypes.Options{
99-
BuildOptions: build.Options{
100-
Tags: cmd.Tags,
101-
SkipPush: cmd.SkipPush,
102-
SkipPushOnLocalKubernetes: cmd.SkipPushLocalKubernetes,
103-
ForceRebuild: cmd.ForceBuild,
104-
Sequential: cmd.BuildSequential,
105-
MaxConcurrentBuilds: cmd.MaxConcurrentBuilds,
106-
},
107-
DependencyOptions: pipelinetypes.DependencyOptions{
108-
Exclude: cmd.SkipDependency,
109-
Only: cmd.Dependency,
110-
},
111-
},
112-
ConfigOptions: configOptions,
113-
Pipeline: cmd.Pipeline,
114-
})
115-
}

0 commit comments

Comments
 (0)