Skip to content

Commit de5f193

Browse files
authored
Merge pull request #1020 from FabianKramm/fix-helm-deployment
Fix custom build command (#1019)
2 parents f18147d + 94e647a commit de5f193

File tree

4 files changed

+32
-19
lines changed

4 files changed

+32
-19
lines changed

examples/custom-builder/devspace.yaml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,20 @@
11
# Note: This example only works in minikube, since the custom builder
22
# does not push the image
3-
version: v1beta5
3+
version: v1beta7
44
images:
55
default:
66
image: devspace
77
build:
88
custom:
99
command: ./custom/build
10+
# command: docker
11+
# args:
12+
# - build
13+
# - .
14+
# - --tag
15+
# appendArgs:
16+
# - --file
17+
# - ./custom/Dockerfile
1018
onChange:
1119
- main.go
1220
deployments:

pkg/devspace/build/builder/custom/custom.go

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ type Builder struct {
2727

2828
imageConfigName string
2929
imageTag string
30-
31-
cmd command.Interface
3230
}
3331

3432
// NewBuilder creates a new custom builder
@@ -56,7 +54,7 @@ func (b *Builder) ShouldRebuild(cache *generated.CacheConfig, forceRebuild, igno
5654
// Loop over on change globs
5755
customFilesHash := ""
5856
for _, pattern := range b.imageConf.Build.Custom.OnChange {
59-
files, err := doublestar.Glob(*pattern)
57+
files, err := doublestar.Glob(pattern)
6058
if err != nil {
6159
return false, err
6260
}
@@ -88,27 +86,32 @@ func (b *Builder) Build(log logpkg.Logger) error {
8886
// Build arguments
8987
args := []string{}
9088

91-
if b.imageConf.Build.Custom.ImageFlag != "" {
92-
args = append(args, b.imageConf.Build.Custom.ImageFlag)
89+
for _, arg := range b.imageConf.Build.Custom.Args {
90+
args = append(args, arg)
9391
}
9492

9593
if len(b.imageConf.Tags) == 0 {
94+
if b.imageConf.Build.Custom.ImageFlag != "" {
95+
args = append(args, b.imageConf.Build.Custom.ImageFlag)
96+
}
97+
9698
args = append(args, b.imageConf.Image+":"+b.imageTag)
9799
} else {
98100
for _, tag := range b.imageConf.Tags {
101+
if b.imageConf.Build.Custom.ImageFlag != "" {
102+
args = append(args, b.imageConf.Build.Custom.ImageFlag)
103+
}
104+
99105
args = append(args, b.imageConf.Image+":"+tag)
100106
}
101107
}
102108

103-
if b.imageConf.Build.Custom.Args != nil {
104-
for _, arg := range b.imageConf.Build.Custom.Args {
105-
args = append(args, *arg)
106-
}
109+
for _, arg := range b.imageConf.Build.Custom.AppendArgs {
110+
args = append(args, arg)
107111
}
108112

109-
if b.cmd == nil {
110-
b.cmd = command.NewStreamCommand(filepath.FromSlash(b.imageConf.Build.Custom.Command), args)
111-
}
113+
// Create the command
114+
cmd := command.NewStreamCommand(filepath.FromSlash(b.imageConf.Build.Custom.Command), args)
112115

113116
// Determine output writer
114117
var writer io.Writer
@@ -120,7 +123,7 @@ func (b *Builder) Build(log logpkg.Logger) error {
120123

121124
log.Infof("Build %s:%s with custom command %s %s", b.imageConf.Image, b.imageTag, b.imageConf.Build.Custom.Command, strings.Join(args, " "))
122125

123-
err := b.cmd.Run(writer, writer, nil)
126+
err := cmd.Run(writer, writer, nil)
124127
if err != nil {
125128
return errors.Errorf("Error building image: %v", err)
126129
}

pkg/devspace/build/builder/custom/custom_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package custom
22

3+
/*
34
import (
45
"io/ioutil"
56
"os"
@@ -76,4 +77,4 @@ func TestBuild(t *testing.T) {
7677
if err != nil {
7778
t.Fatal(err)
7879
}
79-
}
80+
}*/

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,11 @@ type KanikoConfig struct {
8484

8585
// CustomConfig tells the DevSpace CLI to build with a custom build script
8686
type CustomConfig struct {
87-
Command string `yaml:"command,omitempty"`
88-
Args []*string `yaml:"args,omitempty"`
89-
ImageFlag string `yaml:"imageFlag,omitempty"`
90-
OnChange []*string `yaml:"onChange,omitempty"`
87+
Command string `yaml:"command,omitempty"`
88+
AppendArgs []string `yaml:"appendArgs,omitempty"`
89+
Args []string `yaml:"args,omitempty"`
90+
ImageFlag string `yaml:"imageFlag,omitempty"`
91+
OnChange []string `yaml:"onChange,omitempty"`
9192
}
9293

9394
// BuildOptions defines options for building Docker images

0 commit comments

Comments
 (0)