@@ -29,16 +29,23 @@ import (
29
29
"github.com/sirupsen/logrus"
30
30
)
31
31
32
- func (b * Builder ) buildJibMavenToDocker (ctx context.Context , out io.Writer , workspace string , a * latest.JibMavenArtifact ) (string , error ) {
32
+ func (b * Builder ) buildJibMaven (ctx context.Context , out io.Writer , workspace string , artifact * latest.Artifact ) (string , error ) {
33
+ if b .pushImages {
34
+ return buildJibMavenToRegistry (ctx , out , workspace , artifact )
35
+ }
36
+ return buildJibMavenToDocker (ctx , out , workspace , artifact .JibMavenArtifact )
37
+ }
38
+
39
+ func buildJibMavenToDocker (ctx context.Context , out io.Writer , workspace string , artifact * latest.JibMavenArtifact ) (string , error ) {
33
40
// If this is a multi-module project, we require `package` be bound to jib:dockerBuild
34
- if a .Module != "" {
35
- if err := verifyJibPackageGoal (ctx , "dockerBuild" , workspace , a ); err != nil {
41
+ if artifact .Module != "" {
42
+ if err := verifyJibPackageGoal (ctx , "dockerBuild" , workspace , artifact ); err != nil {
36
43
return "" , err
37
44
}
38
45
}
39
46
40
- skaffoldImage := generateJibImageRef (workspace , a .Module )
41
- args := generateMavenArgs ("dockerBuild" , skaffoldImage , a )
47
+ skaffoldImage := generateJibImageRef (workspace , artifact .Module )
48
+ args := generateMavenArgs ("dockerBuild" , skaffoldImage , artifact )
42
49
43
50
if err := runMavenCommand (ctx , out , workspace , args ); err != nil {
44
51
return "" , err
@@ -47,7 +54,7 @@ func (b *Builder) buildJibMavenToDocker(ctx context.Context, out io.Writer, work
47
54
return skaffoldImage , nil
48
55
}
49
56
50
- func ( b * Builder ) buildJibMavenToRegistry (ctx context.Context , out io.Writer , workspace string , artifact * latest.Artifact ) (string , error ) {
57
+ func buildJibMavenToRegistry (ctx context.Context , out io.Writer , workspace string , artifact * latest.Artifact ) (string , error ) {
51
58
// If this is a multi-module project, we require `package` be bound to jib:build
52
59
if artifact .JibMavenArtifact .Module != "" {
53
60
if err := verifyJibPackageGoal (ctx , "build" , workspace , artifact .JibMavenArtifact ); err != nil {
@@ -67,30 +74,30 @@ func (b *Builder) buildJibMavenToRegistry(ctx context.Context, out io.Writer, wo
67
74
}
68
75
69
76
// generateMavenArgs generates the arguments to Maven for building the project as an image called `skaffoldImage`.
70
- func generateMavenArgs (goal string , skaffoldImage string , a * latest.JibMavenArtifact ) []string {
77
+ func generateMavenArgs (goal string , imageName string , artifact * latest.JibMavenArtifact ) []string {
71
78
var command []string
72
- if a .Module == "" {
79
+ if artifact .Module == "" {
73
80
// single-module project
74
81
command = []string {"--non-recursive" , "prepare-package" , "jib:" + goal }
75
82
} else {
76
83
// multi-module project: we assume `package` is bound to `jib:<goal>`
77
- command = []string {"--projects" , a .Module , "--also-make" , "package" }
84
+ command = []string {"--projects" , artifact .Module , "--also-make" , "package" }
78
85
}
79
- command = append (command , "-Dimage=" + skaffoldImage )
80
- if a .Profile != "" {
81
- command = append (command , "--activate-profiles" , a .Profile )
86
+ command = append (command , "-Dimage=" + imageName )
87
+ if artifact .Profile != "" {
88
+ command = append (command , "--activate-profiles" , artifact .Profile )
82
89
}
83
90
84
91
return command
85
92
}
86
93
87
94
// verifyJibPackageGoal verifies that the referenced module has `package` bound to a single jib goal.
88
95
// It returns `nil` if the goal is matched, and an error if there is a mismatch.
89
- func verifyJibPackageGoal (ctx context.Context , requiredGoal string , workspace string , a * latest.JibMavenArtifact ) error {
96
+ func verifyJibPackageGoal (ctx context.Context , requiredGoal string , workspace string , artifact * latest.JibMavenArtifact ) error {
90
97
// cannot use --non-recursive
91
- command := []string {"--quiet" , "--projects" , a .Module , "jib:_skaffold-package-goals" }
92
- if a .Profile != "" {
93
- command = append (command , "--activate-profiles" , a .Profile )
98
+ command := []string {"--quiet" , "--projects" , artifact .Module , "jib:_skaffold-package-goals" }
99
+ if artifact .Profile != "" {
100
+ command = append (command , "--activate-profiles" , artifact .Profile )
94
101
}
95
102
96
103
cmd := jib .MavenCommand .CreateCommand (ctx , workspace , command )
@@ -100,7 +107,7 @@ func verifyJibPackageGoal(ctx context.Context, requiredGoal string, workspace st
100
107
return errors .Wrap (err , "could not obtain jib package goals" )
101
108
}
102
109
goals := util .NonEmptyLines (stdout )
103
- logrus .Debugf ("jib bound package goals for %s %s: %v (%d)" , workspace , a .Module , goals , len (goals ))
110
+ logrus .Debugf ("jib bound package goals for %s %s: %v (%d)" , workspace , artifact .Module , goals , len (goals ))
104
111
if len (goals ) != 1 {
105
112
return errors .New ("skaffold requires a single jib goal bound to 'package'" )
106
113
}
0 commit comments