From 42a9dbf4b4b0ea54f90aba136a8d09fa7f7813df Mon Sep 17 00:00:00 2001 From: Cornelius Weig Date: Tue, 5 Feb 2019 22:14:44 +0100 Subject: [PATCH 1/2] Add custom build arguments in jib artifacts (#1565) Before, there was no way to pass custom arguments to the jib artifacts. Now, there is the `mavenArgs` and `gradleArgs` field which expect a list of strings which is forwarded to the maven and gradle builder, respectively. Signed-off-by: Cornelius Weig --- examples/annotated-skaffold.yaml | 12 +++++++++--- integration/examples/annotated-skaffold.yaml | 12 +++++++++--- pkg/skaffold/jib/jib_gradle.go | 1 + pkg/skaffold/jib/jib_gradle_test.go | 1 + pkg/skaffold/jib/jib_maven.go | 2 ++ pkg/skaffold/jib/jib_maven_test.go | 10 ++++++++++ pkg/skaffold/schema/latest/config.go | 6 ++++++ 7 files changed, 38 insertions(+), 6 deletions(-) diff --git a/examples/annotated-skaffold.yaml b/examples/annotated-skaffold.yaml index baefd942472..9f590dab3a3 100644 --- a/examples/annotated-skaffold.yaml +++ b/examples/annotated-skaffold.yaml @@ -76,10 +76,16 @@ build: # jibMaven: # module: modulename # selects which maven module to build, for a multimodule project # profile: profilename # selects which maven profile to activate + # mavenArgs: # additional arguments to pass to maven + # - "arg1" + # - "arg2" # jibGradle builds containers using the Jib plugin for Gradle. # jibGradle: # project: projectname # selects which gradle project to build + # gradleArgs: # additional arguments to pass to gradle + # - "arg1" + # - "arg2" # This next section is where you'll put your specific builder configuration. # Valid builders are `local` (beta), `googleCloudBuild` (beta) and `kaniko` (beta). @@ -120,17 +126,17 @@ build: # Docker artifacts can be built on a Kubernetes cluster with Kaniko. # Exactly one buildContext must be specified to use kaniko - # If localDir is specified, skaffold will mount sources directly via a emptyDir volume + # If localDir is specified, skaffold will mount sources directly via a emptyDir volume # If gcsBucket is specified, skaffold will send sources to the GCS bucket provided # Kaniko also needs access to a service account to push the final image. # See https://github.com/GoogleContainerTools/kaniko#running-kaniko-in-a-kubernetes-cluster # If cache is specified, kaniko will use a remote cache which will speed up builds. # A cache repo can be specified to store cached layers, otherwise one will be inferred - # from the image name. See https://github.com/GoogleContainerTools/kaniko#caching + # from the image name. See https://github.com/GoogleContainerTools/kaniko#caching # # Additional flags can be specified as a list. To see all additional flags, visit: # https://github.com/GoogleContainerTools/kaniko#additional-flags - # + # # kaniko: # buildContext: # gcsBucket: k8s-skaffold diff --git a/integration/examples/annotated-skaffold.yaml b/integration/examples/annotated-skaffold.yaml index 621e8dffbbd..bc4f074601c 100644 --- a/integration/examples/annotated-skaffold.yaml +++ b/integration/examples/annotated-skaffold.yaml @@ -73,10 +73,16 @@ build: # jibMaven: # module: modulename # selects which maven module to build, for a multimodule project # profile: profilename # selects which maven profile to activate + # mavenArgs: # additional arguments to pass to maven + # - "arg1" + # - "arg2" # jibGradle builds containers using the Jib plugin for Gradle. # jibGradle: # project: projectname # selects which gradle project to build + # gradleArgs: # additional arguments to pass to gradle + # - "arg1" + # - "arg2" # This next section is where you'll put your specific builder configuration. # Valid builders are `local` (beta), `googleCloudBuild` (beta) and `kaniko` (beta). @@ -117,17 +123,17 @@ build: # Docker artifacts can be built on a Kubernetes cluster with Kaniko. # Exactly one buildContext must be specified to use kaniko - # If localDir is specified, skaffold will mount sources directly via a emptyDir volume + # If localDir is specified, skaffold will mount sources directly via a emptyDir volume # If gcsBucket is specified, skaffold will send sources to the GCS bucket provided # Kaniko also needs access to a service account to push the final image. # See https://github.com/GoogleContainerTools/kaniko#running-kaniko-in-a-kubernetes-cluster # If cache is specified, kaniko will use a remote cache which will speed up builds. # A cache repo can be specified to store cached layers, otherwise one will be inferred - # from the image name. See https://github.com/GoogleContainerTools/kaniko#caching + # from the image name. See https://github.com/GoogleContainerTools/kaniko#caching # # Additional flags can be specified as a list. To see all additional flags, visit: # https://github.com/GoogleContainerTools/kaniko#additional-flags - # + # # kaniko: # buildContext: # gcsBucket: k8s-skaffold diff --git a/pkg/skaffold/jib/jib_gradle.go b/pkg/skaffold/jib/jib_gradle.go index 24be90049c6..1885c073d56 100644 --- a/pkg/skaffold/jib/jib_gradle.go +++ b/pkg/skaffold/jib/jib_gradle.go @@ -52,6 +52,7 @@ func GenerateGradleArgs(task string, imageName string, a *latest.JibGradleArtifa if skipTests { args = append(args, "-x", "test") } + args = append(args, a.Flags...) return args } diff --git a/pkg/skaffold/jib/jib_gradle_test.go b/pkg/skaffold/jib/jib_gradle_test.go index 3c40dc7c011..6a62e718453 100644 --- a/pkg/skaffold/jib/jib_gradle_test.go +++ b/pkg/skaffold/jib/jib_gradle_test.go @@ -151,6 +151,7 @@ func TestGenerateGradleArgs(t *testing.T) { out []string }{ {latest.JibGradleArtifact{}, false, []string{":task", "--image=image"}}, + {latest.JibGradleArtifact{Flags: []string{"-extra", "args"}}, false, []string{":task", "--image=image", "-extra", "args"}}, {latest.JibGradleArtifact{}, true, []string{":task", "--image=image", "-x", "test"}}, {latest.JibGradleArtifact{Project: "project"}, false, []string{":project:task", "--image=image"}}, {latest.JibGradleArtifact{Project: "project"}, true, []string{":project:task", "--image=image", "-x", "test"}}, diff --git a/pkg/skaffold/jib/jib_maven.go b/pkg/skaffold/jib/jib_maven.go index a155aa2210f..9f8dc4b4900 100644 --- a/pkg/skaffold/jib/jib_maven.go +++ b/pkg/skaffold/jib/jib_maven.go @@ -70,6 +70,8 @@ func GenerateMavenArgs(goal string, imageName string, a *latest.JibMavenArtifact func mavenArgs(a *latest.JibMavenArtifact) []string { var args []string + args = append(args, a.Flags...) + if a.Profile != "" { args = append(args, "--activate-profiles", a.Profile) } diff --git a/pkg/skaffold/jib/jib_maven_test.go b/pkg/skaffold/jib/jib_maven_test.go index b0ef9b7ce16..df990fd2925 100644 --- a/pkg/skaffold/jib/jib_maven_test.go +++ b/pkg/skaffold/jib/jib_maven_test.go @@ -99,6 +99,16 @@ func TestGetCommandMaven(t *testing.T) { return MavenCommand.CreateCommand(ctx, workspace, []string{"--non-recursive", "jib:_skaffold-files", "--quiet"}) }, }, + { + description: "maven with extra flags", + jibMavenArtifact: latest.JibMavenArtifact{ + Flags: []string{"-DskipTests", "-x"}, + }, + filesInWorkspace: []string{}, + expectedCmd: func(workspace string) *exec.Cmd { + return MavenCommand.CreateCommand(ctx, workspace, []string{"-DskipTests", "-x", "--non-recursive", "jib:_skaffold-files", "--quiet"}) + }, + }, { description: "maven with profile", jibMavenArtifact: latest.JibMavenArtifact{Profile: "profile"}, diff --git a/pkg/skaffold/schema/latest/config.go b/pkg/skaffold/schema/latest/config.go index a1e89acc52c..98d2f9219f3 100644 --- a/pkg/skaffold/schema/latest/config.go +++ b/pkg/skaffold/schema/latest/config.go @@ -504,10 +504,16 @@ type JibMavenArtifact struct { // Profile selects which maven profile to activate. Profile string `yaml:"profile"` + + // Flags is passed as additional build flags to maven + Flags []string `yaml:"mavenArgs,omitempty"` } // JibGradleArtifact builds containers using the Jib plugin for Gradle. type JibGradleArtifact struct { // Project selects which gradle project to build. Project string `yaml:"project"` + + // Flags is passed as additional build flags to gradle + Flags []string `yaml:"gradleArgs,omitempty"` } From 78bd61927202296f535a34ff23c2464cccca8b8e Mon Sep 17 00:00:00 2001 From: Cornelius Weig Date: Wed, 6 Feb 2019 20:02:02 +0100 Subject: [PATCH 2/2] Rename `mavenArgs`/`gradleArgs` to `args` (#1565) Signed-off-by: Cornelius Weig --- examples/annotated-skaffold.yaml | 4 ++-- integration/examples/annotated-skaffold.yaml | 4 ++-- pkg/skaffold/jib/jib_gradle.go | 2 +- pkg/skaffold/jib/jib_gradle_test.go | 2 +- pkg/skaffold/jib/jib_maven.go | 2 +- pkg/skaffold/jib/jib_maven_test.go | 2 +- pkg/skaffold/schema/latest/config.go | 4 ++-- 7 files changed, 10 insertions(+), 10 deletions(-) diff --git a/examples/annotated-skaffold.yaml b/examples/annotated-skaffold.yaml index 9f590dab3a3..323214770ad 100644 --- a/examples/annotated-skaffold.yaml +++ b/examples/annotated-skaffold.yaml @@ -76,14 +76,14 @@ build: # jibMaven: # module: modulename # selects which maven module to build, for a multimodule project # profile: profilename # selects which maven profile to activate - # mavenArgs: # additional arguments to pass to maven + # args: # additional arguments to pass to maven # - "arg1" # - "arg2" # jibGradle builds containers using the Jib plugin for Gradle. # jibGradle: # project: projectname # selects which gradle project to build - # gradleArgs: # additional arguments to pass to gradle + # args: # additional arguments to pass to gradle # - "arg1" # - "arg2" diff --git a/integration/examples/annotated-skaffold.yaml b/integration/examples/annotated-skaffold.yaml index bc4f074601c..cba4f108bee 100644 --- a/integration/examples/annotated-skaffold.yaml +++ b/integration/examples/annotated-skaffold.yaml @@ -73,14 +73,14 @@ build: # jibMaven: # module: modulename # selects which maven module to build, for a multimodule project # profile: profilename # selects which maven profile to activate - # mavenArgs: # additional arguments to pass to maven + # args: # additional arguments to pass to maven # - "arg1" # - "arg2" # jibGradle builds containers using the Jib plugin for Gradle. # jibGradle: # project: projectname # selects which gradle project to build - # gradleArgs: # additional arguments to pass to gradle + # args: # additional arguments to pass to gradle # - "arg1" # - "arg2" diff --git a/pkg/skaffold/jib/jib_gradle.go b/pkg/skaffold/jib/jib_gradle.go index 1885c073d56..0dc9cda909d 100644 --- a/pkg/skaffold/jib/jib_gradle.go +++ b/pkg/skaffold/jib/jib_gradle.go @@ -52,7 +52,7 @@ func GenerateGradleArgs(task string, imageName string, a *latest.JibGradleArtifa if skipTests { args = append(args, "-x", "test") } - args = append(args, a.Flags...) + args = append(args, a.BuildArgs...) return args } diff --git a/pkg/skaffold/jib/jib_gradle_test.go b/pkg/skaffold/jib/jib_gradle_test.go index 6a62e718453..c2cc9ec85ee 100644 --- a/pkg/skaffold/jib/jib_gradle_test.go +++ b/pkg/skaffold/jib/jib_gradle_test.go @@ -151,7 +151,7 @@ func TestGenerateGradleArgs(t *testing.T) { out []string }{ {latest.JibGradleArtifact{}, false, []string{":task", "--image=image"}}, - {latest.JibGradleArtifact{Flags: []string{"-extra", "args"}}, false, []string{":task", "--image=image", "-extra", "args"}}, + {latest.JibGradleArtifact{BuildArgs: []string{"-extra", "args"}}, false, []string{":task", "--image=image", "-extra", "args"}}, {latest.JibGradleArtifact{}, true, []string{":task", "--image=image", "-x", "test"}}, {latest.JibGradleArtifact{Project: "project"}, false, []string{":project:task", "--image=image"}}, {latest.JibGradleArtifact{Project: "project"}, true, []string{":project:task", "--image=image", "-x", "test"}}, diff --git a/pkg/skaffold/jib/jib_maven.go b/pkg/skaffold/jib/jib_maven.go index 9f8dc4b4900..bd15e932858 100644 --- a/pkg/skaffold/jib/jib_maven.go +++ b/pkg/skaffold/jib/jib_maven.go @@ -70,7 +70,7 @@ func GenerateMavenArgs(goal string, imageName string, a *latest.JibMavenArtifact func mavenArgs(a *latest.JibMavenArtifact) []string { var args []string - args = append(args, a.Flags...) + args = append(args, a.BuildArgs...) if a.Profile != "" { args = append(args, "--activate-profiles", a.Profile) diff --git a/pkg/skaffold/jib/jib_maven_test.go b/pkg/skaffold/jib/jib_maven_test.go index df990fd2925..6e3e05091d5 100644 --- a/pkg/skaffold/jib/jib_maven_test.go +++ b/pkg/skaffold/jib/jib_maven_test.go @@ -102,7 +102,7 @@ func TestGetCommandMaven(t *testing.T) { { description: "maven with extra flags", jibMavenArtifact: latest.JibMavenArtifact{ - Flags: []string{"-DskipTests", "-x"}, + BuildArgs: []string{"-DskipTests", "-x"}, }, filesInWorkspace: []string{}, expectedCmd: func(workspace string) *exec.Cmd { diff --git a/pkg/skaffold/schema/latest/config.go b/pkg/skaffold/schema/latest/config.go index 98d2f9219f3..db1572b4de1 100644 --- a/pkg/skaffold/schema/latest/config.go +++ b/pkg/skaffold/schema/latest/config.go @@ -506,7 +506,7 @@ type JibMavenArtifact struct { Profile string `yaml:"profile"` // Flags is passed as additional build flags to maven - Flags []string `yaml:"mavenArgs,omitempty"` + BuildArgs []string `yaml:"args,omitempty"` } // JibGradleArtifact builds containers using the Jib plugin for Gradle. @@ -515,5 +515,5 @@ type JibGradleArtifact struct { Project string `yaml:"project"` // Flags is passed as additional build flags to gradle - Flags []string `yaml:"gradleArgs,omitempty"` + BuildArgs []string `yaml:"args,omitempty"` }