Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add custom build arguments in jib artifacts #1609

Merged
merged 2 commits into from
Feb 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions examples/annotated-skaffold.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
# 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
# args: # 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).
Expand Down Expand Up @@ -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
Expand Down
12 changes: 9 additions & 3 deletions integration/examples/annotated-skaffold.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
# 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
# args: # 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).
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions pkg/skaffold/jib/jib_gradle.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ func GenerateGradleArgs(task string, imageName string, a *latest.JibGradleArtifa
if skipTests {
args = append(args, "-x", "test")
}
args = append(args, a.BuildArgs...)
return args
}

Expand Down
1 change: 1 addition & 0 deletions pkg/skaffold/jib/jib_gradle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ func TestGenerateGradleArgs(t *testing.T) {
out []string
}{
{latest.JibGradleArtifact{}, false, []string{":task", "--image=image"}},
{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"}},
Expand Down
2 changes: 2 additions & 0 deletions pkg/skaffold/jib/jib_maven.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.BuildArgs...)

if a.Profile != "" {
args = append(args, "--activate-profiles", a.Profile)
}
Expand Down
10 changes: 10 additions & 0 deletions pkg/skaffold/jib/jib_maven_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
BuildArgs: []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"},
Expand Down
6 changes: 6 additions & 0 deletions pkg/skaffold/schema/latest/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
BuildArgs []string `yaml:"args,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
BuildArgs []string `yaml:"args,omitempty"`
}