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

Introduce fromImage field in jib builder interface. #4873

Merged
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
8 changes: 7 additions & 1 deletion docs/content/en/schemas/v2beta9.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand All @@ -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/).",
Expand Down
39 changes: 14 additions & 25 deletions integration/examples/jib-sync/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
<plugin>
<groupId>com.google.cloud.tools</groupId>
<artifactId>jib-maven-plugin</artifactId>
<version>${jib.maven-plugin-version}</version>
<configuration>
...
<from>
<image>gcr.io/distroless/java:debug</image>
</from>
</configuration>
</plugin>
```
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
<profiles>
<profile>
<id>sync<id>
<id>sync</id>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
Expand Down
6 changes: 0 additions & 6 deletions integration/examples/jib-sync/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,3 @@ dependencies {

testImplementation "org.springframework.boot:spring-boot-starter-test"
}

jib {
from {
image = "gcr.io/distroless/java:debug"
}
}
3 changes: 0 additions & 3 deletions integration/examples/jib-sync/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@
<artifactId>jib-maven-plugin</artifactId>
<version>${jib.maven-plugin-version}</version>
<configuration>
<from>
<image>gcr.io/distroless/java:debug</image>
</from>
<container>
<jvmFlags>
<jvmFlag>-Djava.security.egd=file:/dev/./urandom</jvmFlag>
Expand Down
1 change: 1 addition & 0 deletions integration/examples/jib-sync/skaffold-gradle.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ build:
type: gradle
args:
- -Psync
fromImage: gcr.io/distroless/java:debug
sync:
auto: {}

Expand Down
1 change: 1 addition & 0 deletions integration/examples/jib-sync/skaffold-maven.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ build:
args:
- --no-transfer-progress
- -Psync
fromImage: gcr.io/distroless/java:debug
sync:
auto: {}

Expand Down
4 changes: 3 additions & 1 deletion pkg/skaffold/build/jib/gradle.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
16 changes: 16 additions & 0 deletions pkg/skaffold/build/jib/gradle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{},
Expand Down Expand Up @@ -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{},
Expand Down Expand Up @@ -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) {
Expand Down
3 changes: 3 additions & 0 deletions pkg/skaffold/build/jib/maven.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions pkg/skaffold/build/jib/maven_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{},
Expand Down Expand Up @@ -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{},
Expand Down Expand Up @@ -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) {
Expand Down
3 changes: 3 additions & 0 deletions pkg/skaffold/schema/latest/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}