Skip to content

Commit 19f261d

Browse files
authored
Adds command line option for setting target image. (GoogleContainerTools#339)
1 parent dea7eda commit 19f261d

6 files changed

Lines changed: 23 additions & 4 deletions

File tree

‎jib-gradle-plugin/CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ All notable changes to this project will be documented in this file.
1616
- Warns if build may not be reproducible ([#245](https://github.com/GoogleContainerTools/jib/pull/245))
1717
- `jibBuildDocker` gradle task to build straight to Docker daemon ([#265](https://github.com/GoogleContainerTools/jib/pull/265))
1818
- `mainClass` is inferred by searching through class files if configuration is missing ([#278](https://github.com/GoogleContainerTools/jib/pull/278))
19+
- Can now specify target image with `--image` ([#328](https://github.com/GoogleContainerTools/jib/issues/328))
1920

2021
### Changed
2122

‎jib-gradle-plugin/src/main/java/com/google/cloud/tools/jib/gradle/BuildDockerTask.java‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import org.gradle.api.GradleException;
3333
import org.gradle.api.tasks.Nested;
3434
import org.gradle.api.tasks.TaskAction;
35+
import org.gradle.api.tasks.options.Option;
3536

3637
/** Builds a container image and exports to the default Docker daemon. */
3738
public class BuildDockerTask extends DefaultTask {
@@ -51,6 +52,12 @@ public JibExtension getJib() {
5152
return jibExtension;
5253
}
5354

55+
/** The target image can be overriden with the {@code --image} command line option. */
56+
@Option(option = "image", description = "The image reference for the target image")
57+
public void setTargetImage(String targetImage) {
58+
Preconditions.checkNotNull(jibExtension).getTo().setImage(targetImage);
59+
}
60+
5461
@TaskAction
5562
public void buildDocker() throws InvalidImageReferenceException {
5663
if (!new DockerClient().isDockerInstalled()) {

‎jib-gradle-plugin/src/main/java/com/google/cloud/tools/jib/gradle/BuildImageTask.java‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import org.gradle.api.GradleException;
3636
import org.gradle.api.tasks.Nested;
3737
import org.gradle.api.tasks.TaskAction;
38+
import org.gradle.api.tasks.options.Option;
3839
import org.gradle.internal.logging.events.LogEvent;
3940
import org.gradle.internal.logging.events.OutputEventListener;
4041
import org.gradle.internal.logging.slf4j.OutputEventListenerBackedLoggerContext;
@@ -61,6 +62,12 @@ public JibExtension getJib() {
6162
return jibExtension;
6263
}
6364

65+
/** The target image can be overriden with the {@code --image} command line option. */
66+
@Option(option = "image", description = "The image reference for the target image")
67+
public void setTargetImage(String targetImage) {
68+
Preconditions.checkNotNull(jibExtension).getTo().setImage(targetImage);
69+
}
70+
6471
@TaskAction
6572
public void buildImage() throws InvalidImageReferenceException {
6673
// Asserts required @Input parameters are not null.

‎jib-gradle-plugin/src/main/java/com/google/cloud/tools/jib/gradle/JibExtension.java‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ private Class<? extends BuildableManifestTemplate> getManifestTemplateClass() {
8181
private static final ImageFormat DEFAULT_FORMAT = ImageFormat.Docker;
8282
private static final boolean DEFAULT_USE_ONLY_PROJECT_CACHE = false;
8383

84-
private ImageConfiguration from;
85-
private ImageConfiguration to;
84+
private final ImageConfiguration from;
85+
private final ImageConfiguration to;
8686
private final ListProperty<String> jvmFlags;
8787
private final Property<String> mainClass;
8888
private final Property<ImageFormat> format;
@@ -146,7 +146,6 @@ ImageConfiguration getFrom() {
146146
return from;
147147
}
148148

149-
@Nested
150149
ImageConfiguration getTo() {
151150
return to;
152151
}

‎jib-maven-plugin/CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ All notable changes to this project will be documented in this file.
1515
- Warns if build may not be reproducible ([#245](https://github.com/GoogleContainerTools/jib/pull/245))
1616
- `jib:buildDocker` maven goal to build straight to Docker daemon ([#266](https://github.com/GoogleContainerTools/jib/pull/266))
1717
- `mainClass` is inferred by searching through class files if configuration is missing ([#278](https://github.com/GoogleContainerTools/jib/pull/278))
18+
- Can now specify target image with `-Dimage` ([#328](https://github.com/GoogleContainerTools/jib/issues/328))
1819

1920
### Changed
2021
- Removed `enableReproducibleBuilds` parameter - application layers will always be reproducible ([#245](https://github.com/GoogleContainerTools/jib/pull/245))

‎jib-maven-plugin/src/main/java/com/google/cloud/tools/jib/maven/JibPluginConfiguration.java‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ public static class ToConfiguration {
5353
private String image;
5454

5555
@Nullable @Parameter private String credHelper;
56+
57+
public void set(String image) {
58+
this.image = image;
59+
}
5660
}
5761

5862
/** @return the {@link ImageReference} parsed from {@code from}. */
@@ -84,7 +88,7 @@ static ImageReference parseTargetImageReference(String to) {
8488
@Nullable @Parameter private FromConfiguration from = new FromConfiguration();
8589

8690
@Nullable
87-
@Parameter(required = true)
91+
@Parameter(property = "image", required = true)
8892
private ToConfiguration to;
8993

9094
@Parameter private List<String> jvmFlags = Collections.emptyList();

0 commit comments

Comments
 (0)