File tree Expand file tree Collapse file tree
src/main/java/com/google/cloud/tools/jib/gradle
src/main/java/com/google/cloud/tools/jib/maven Expand file tree Collapse file tree Original file line number Diff line number Diff 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
Original file line number Diff line number Diff line change 3232import org .gradle .api .GradleException ;
3333import org .gradle .api .tasks .Nested ;
3434import 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. */
3738public 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 ()) {
Original file line number Diff line number Diff line change 3535import org .gradle .api .GradleException ;
3636import org .gradle .api .tasks .Nested ;
3737import org .gradle .api .tasks .TaskAction ;
38+ import org .gradle .api .tasks .options .Option ;
3839import org .gradle .internal .logging .events .LogEvent ;
3940import org .gradle .internal .logging .events .OutputEventListener ;
4041import 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.
Original file line number Diff line number Diff 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 }
Original file line number Diff line number Diff 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 ) )
Original file line number Diff line number Diff 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 ();
You can’t perform that action at this time.
0 commit comments