diff --git a/docs/content/en/schemas/v2beta9.json b/docs/content/en/schemas/v2beta9.json
index 4674dc459e9..e1d9ad82b73 100755
--- a/docs/content/en/schemas/v2beta9.json
+++ b/docs/content/en/schemas/v2beta9.json
@@ -1503,6 +1503,11 @@
"[\"--no-build-cache\"]"
]
},
+ "fromImage": {
+ "type": "string",
+ "description": "overrides the configured jib base image.",
+ "x-intellij-html-description": "overrides the configured jib base image."
+ },
"project": {
"type": "string",
"description": "selects which sub-project to build for multi-module builds.",
@@ -1521,7 +1526,8 @@
"preferredOrder": [
"project",
"args",
- "type"
+ "type",
+ "fromImage"
],
"additionalProperties": false,
"description": "builds images using the [Jib plugins for Maven and Gradle](https://github.com/GoogleContainerTools/jib/).",
diff --git a/integration/examples/jib-sync/README.md b/integration/examples/jib-sync/README.md
index a8e99ada543..c2ef3f59c34 100644
--- a/integration/examples/jib-sync/README.md
+++ b/integration/examples/jib-sync/README.md
@@ -63,41 +63,30 @@ build:
This example is designed around the functionality available in [Spring Boot Developer Tools](https://docs.spring.io/spring-boot/docs/current/reference/html/using-spring-boot.html#using-boot-devtools) for developing against running applications.
-Some additional steps in your java build are required for this to work:
-- Sync requires `tar` on the running container to copy files over. The default base image that Jib uses `gcr.io/distroless/java` does not include `tar` or any utilities. During development you must use a base image that includes `tar`, in this example we use the `debug` flavor of distroless: `gcr.io/distroless/java:debug`
+Some additional steps are required for this to work:
+- Sync requires `tar` on the running container to copy files over. The default base image that Jib uses `gcr.io/distroless/java` does not include `tar` or any utilities. During development, you must use a base image that includes `tar`, in this example we use the `debug` flavor of distroless: `gcr.io/distroless/java:debug`
-`maven`
-```xml
-
- com.google.cloud.tools
- jib-maven-plugin
- ${jib.maven-plugin-version}
-
- ...
-
- gcr.io/distroless/java:debug
-
-
-
-```
+This can be done directly in the artifact configuration by overriding the `fromImage` property.
-`gradle`
-```groovy
-jib {
- ...
- from {
- image = "gcr.io/distroless/java:debug"
- }
-}
+```yaml
+build:
+ artifacts:
+ - image: skaffold-example
+ context: .
+ jib:
+ fromImage: gcr.io/distroless/java:debug
+ sync:
+ auto: {}
```
+
- You must include the `spring-boot-devtools` dependency at the `compile/implementation` scope, which is contrary to the configuration outlined in the [official docs](https://docs.spring.io/spring-boot/docs/current/reference/html/using-spring-boot.html#using-boot-devtools). Because jib is unaware of any special spring only configuration in your builds, we recommend using profiles to turn on or off devtools support in your jib container builds.
`maven`
```xml
- sync
+ sync
org.springframework.boot
diff --git a/integration/examples/jib-sync/build.gradle b/integration/examples/jib-sync/build.gradle
index ff3f6949177..d5202b46fb0 100644
--- a/integration/examples/jib-sync/build.gradle
+++ b/integration/examples/jib-sync/build.gradle
@@ -21,9 +21,3 @@ dependencies {
testImplementation "org.springframework.boot:spring-boot-starter-test"
}
-
-jib {
- from {
- image = "gcr.io/distroless/java:debug"
- }
-}
diff --git a/integration/examples/jib-sync/pom.xml b/integration/examples/jib-sync/pom.xml
index 8030aa71376..c04cfc4d295 100644
--- a/integration/examples/jib-sync/pom.xml
+++ b/integration/examples/jib-sync/pom.xml
@@ -37,9 +37,6 @@
jib-maven-plugin
${jib.maven-plugin-version}
-
- gcr.io/distroless/java:debug
-
-Djava.security.egd=file:/dev/./urandom
diff --git a/integration/examples/jib-sync/skaffold-gradle.yaml b/integration/examples/jib-sync/skaffold-gradle.yaml
index 5672464c690..ca9521b8874 100644
--- a/integration/examples/jib-sync/skaffold-gradle.yaml
+++ b/integration/examples/jib-sync/skaffold-gradle.yaml
@@ -7,6 +7,7 @@ build:
type: gradle
args:
- -Psync
+ fromImage: gcr.io/distroless/java:debug
sync:
auto: {}
diff --git a/integration/examples/jib-sync/skaffold-maven.yaml b/integration/examples/jib-sync/skaffold-maven.yaml
index 6a1d0f107e7..d808bd1cc55 100644
--- a/integration/examples/jib-sync/skaffold-maven.yaml
+++ b/integration/examples/jib-sync/skaffold-maven.yaml
@@ -8,6 +8,7 @@ build:
args:
- --no-transfer-progress
- -Psync
+ fromImage: gcr.io/distroless/java:debug
sync:
auto: {}
diff --git a/pkg/skaffold/build/jib/gradle.go b/pkg/skaffold/build/jib/gradle.go
index 3229c2845b6..3984629646d 100644
--- a/pkg/skaffold/build/jib/gradle.go
+++ b/pkg/skaffold/build/jib/gradle.go
@@ -103,7 +103,9 @@ func GenerateGradleBuildArgs(task string, imageName string, a *latest.JibArtifac
// jib doesn't support marking specific registries as insecure
args = append(args, "-Djib.allowInsecureRegistries=true")
}
-
+ if a.BaseImage != "" {
+ args = append(args, fmt.Sprintf("-Djib.from.image=%s", a.BaseImage))
+ }
args = append(args, "--image="+imageName)
return args
}
diff --git a/pkg/skaffold/build/jib/gradle_test.go b/pkg/skaffold/build/jib/gradle_test.go
index 02e72f545f4..a7a8fad948c 100644
--- a/pkg/skaffold/build/jib/gradle_test.go
+++ b/pkg/skaffold/build/jib/gradle_test.go
@@ -55,6 +55,13 @@ func TestBuildJibGradleToDocker(t *testing.T) {
"gradle fake-gradleBuildArgs-for-project-for-jibDockerBuild --image=img:tag",
),
},
+ {
+ description: "build with custom base image",
+ artifact: &latest.JibArtifact{BaseImage: "docker://busybox"},
+ commands: testutil.CmdRun(
+ "gradle fake-gradleBuildArgs-for-jibDockerBuild -Djib.from.image=docker://busybox --image=img:tag",
+ ),
+ },
{
description: "fail build",
artifact: &latest.JibArtifact{},
@@ -114,6 +121,13 @@ func TestBuildJibGradleToRegistry(t *testing.T) {
"gradle fake-gradleBuildArgs-for-project-for-jib --image=img:tag",
),
},
+ {
+ description: "build with custom base image",
+ artifact: &latest.JibArtifact{BaseImage: "docker://busybox"},
+ commands: testutil.CmdRun(
+ "gradle fake-gradleBuildArgs-for-jib -Djib.from.image=docker://busybox --image=img:tag",
+ ),
+ },
{
description: "fail build",
artifact: &latest.JibArtifact{},
@@ -337,6 +351,8 @@ func TestGenerateGradleBuildArgs(t *testing.T) {
{"multi module", latest.JibArtifact{Project: "project"}, "image", false, nil, []string{"fake-gradleBuildArgs-for-project-for-testTask", "--image=image"}},
{"multi module without tests", latest.JibArtifact{Project: "project"}, "image", true, nil, []string{"fake-gradleBuildArgs-for-project-for-testTask-skipTests", "--image=image"}},
{"multi module without tests with insecure registries", latest.JibArtifact{Project: "project"}, "registry.tld/image", true, map[string]bool{"registry.tld": true}, []string{"fake-gradleBuildArgs-for-project-for-testTask-skipTests", "-Djib.allowInsecureRegistries=true", "--image=registry.tld/image"}},
+ {"single module with custom base image", latest.JibArtifact{BaseImage: "docker://busybox"}, "image", false, nil, []string{"fake-gradleBuildArgs-for-testTask", "-Djib.from.image=docker://busybox", "--image=image"}},
+ {"multi module with custom base image", latest.JibArtifact{Project: "project", BaseImage: "docker://busybox"}, "image", false, nil, []string{"fake-gradleBuildArgs-for-project-for-testTask", "-Djib.from.image=docker://busybox", "--image=image"}},
}
for _, test := range tests {
testutil.Run(t, test.description, func(t *testutil.T) {
diff --git a/pkg/skaffold/build/jib/maven.go b/pkg/skaffold/build/jib/maven.go
index 43a7981f5e5..4b860e28d35 100644
--- a/pkg/skaffold/build/jib/maven.go
+++ b/pkg/skaffold/build/jib/maven.go
@@ -104,6 +104,9 @@ func GenerateMavenBuildArgs(goal string, imageName string, a *latest.JibArtifact
// jib doesn't support marking specific registries as insecure
args = append(args, "-Djib.allowInsecureRegistries=true")
}
+ if a.BaseImage != "" {
+ args = append(args, fmt.Sprintf("-Djib.from.image=%s", a.BaseImage))
+ }
args = append(args, "-Dimage="+imageName)
return args
diff --git a/pkg/skaffold/build/jib/maven_test.go b/pkg/skaffold/build/jib/maven_test.go
index cb6b965f106..f4be49a84f7 100644
--- a/pkg/skaffold/build/jib/maven_test.go
+++ b/pkg/skaffold/build/jib/maven_test.go
@@ -55,6 +55,13 @@ func TestBuildJibMavenToDocker(t *testing.T) {
"mvn fake-mavenBuildArgs-for-module-for-dockerBuild -Dimage=img:tag",
),
},
+ {
+ description: "build with custom base image",
+ artifact: &latest.JibArtifact{BaseImage: "docker://busybox"},
+ commands: testutil.CmdRun(
+ "mvn fake-mavenBuildArgs-for-dockerBuild -Djib.from.image=docker://busybox -Dimage=img:tag",
+ ),
+ },
{
description: "fail build",
artifact: &latest.JibArtifact{},
@@ -110,6 +117,11 @@ func TestBuildJibMavenToRegistry(t *testing.T) {
artifact: &latest.JibArtifact{Project: "module"},
commands: testutil.CmdRun("mvn fake-mavenBuildArgs-for-module-for-build -Dimage=img:tag"),
},
+ {
+ description: "build with custom base image",
+ artifact: &latest.JibArtifact{BaseImage: "docker://busybox"},
+ commands: testutil.CmdRun("mvn fake-mavenBuildArgs-for-build -Djib.from.image=docker://busybox -Dimage=img:tag"),
+ },
{
description: "fail build",
artifact: &latest.JibArtifact{},
@@ -325,6 +337,8 @@ func TestGenerateMavenBuildArgs(t *testing.T) {
{"multi module", latest.JibArtifact{Project: "module"}, "image", false, nil, []string{"fake-mavenBuildArgs-for-module-for-test-goal", "-Dimage=image"}},
{"multi module without tests", latest.JibArtifact{Project: "module"}, "image", true, nil, []string{"fake-mavenBuildArgs-for-module-for-test-goal-skipTests", "-Dimage=image"}},
{"multi module without tests with insecure-registry", latest.JibArtifact{Project: "module"}, "registry.tld/image", true, map[string]bool{"registry.tld": true}, []string{"fake-mavenBuildArgs-for-module-for-test-goal-skipTests", "-Djib.allowInsecureRegistries=true", "-Dimage=registry.tld/image"}},
+ {"single module with custom base image", latest.JibArtifact{BaseImage: "docker://busybox"}, "image", false, nil, []string{"fake-mavenBuildArgs-for-test-goal", "-Djib.from.image=docker://busybox", "-Dimage=image"}},
+ {"multi module with custom base image", latest.JibArtifact{Project: "module", BaseImage: "docker://busybox"}, "image", false, nil, []string{"fake-mavenBuildArgs-for-module-for-test-goal", "-Djib.from.image=docker://busybox", "-Dimage=image"}},
}
for _, test := range tests {
testutil.Run(t, test.description, func(t *testutil.T) {
diff --git a/pkg/skaffold/schema/latest/config.go b/pkg/skaffold/schema/latest/config.go
index a592893db93..4bb98357e2e 100644
--- a/pkg/skaffold/schema/latest/config.go
+++ b/pkg/skaffold/schema/latest/config.go
@@ -1077,4 +1077,7 @@ type JibArtifact struct {
// `maven`: for Maven.
// `gradle`: for Gradle.
Type string `yaml:"type,omitempty"`
+
+ // BaseImage overrides the configured jib base image.
+ BaseImage string `yaml:"fromImage,omitempty"`
}