From 45c099b6ac75121e71eb8eab83a977e5cb934a8f Mon Sep 17 00:00:00 2001 From: Rohan Kumar Date: Fri, 2 Oct 2020 12:29:58 +0530 Subject: [PATCH] Fix #1384: Building spring-boot-with-jib fails with NoSuchMethodEror + Updating jib-core to 0.15.0 broke our current JIB support due to incompatibility with httpclient. Updated apache httpclient to 4.5.10 + Somehow behavior of Jib setting ImageFormat has been changed(maybe it was not working earlier. Introduced a new parameter in mojo `docker.build.jib.imageFormat` to allow users specify image format(OCI or Docker) with Docker as default ImageFormat. + Minor Cleanup in Integration tests; Added an integration test for JIB mode which builds image tarball and verifies it by loading into docker daemon This should also fix #1385 --- .circleci/config.yml | 2 +- doc/changelog.md | 4 + it/docker-compose/pom.xml | 10 +- it/dockerfile/pom.xml | 12 +- .../samples/dockerfile/HelloWorldServlet.java | 2 +- it/dockerfile/src/main/webapp/WEB-INF/web.xml | 2 +- it/dockerignore/pom.xml | 12 +- it/healthcheck/pom.xml | 10 +- it/helloworld/pom.xml | 12 +- it/log/pom.xml | 10 +- it/net/pom.xml | 10 +- it/pom.xml | 7 +- it/properties/pom.xml | 11 +- it/run-java/pom.xml | 12 +- it/smallest/pom.xml | 10 +- it/spring-boot-with-jib/pom.xml | 141 ++++++++++++++++++ .../sample/springboot/jib/Application.java | 13 ++ .../springboot/jib/HelloController.java | 15 ++ it/volume/pom.xml | 10 +- it/zero-config/Dockerfile | 2 +- it/zero-config/pom.xml | 12 +- pom.xml | 3 +- .../asciidoc/inc/_global-configuration.adoc | 4 + .../maven/docker/AbstractDockerMojo.java | 3 + .../io/fabric8/maven/docker/BuildMojo.java | 2 +- .../maven/docker/service/JibBuildService.java | 5 +- .../maven/docker/util/JibServiceUtil.java | 12 +- .../maven/docker/util/JibServiceUtilTest.java | 12 +- 28 files changed, 279 insertions(+), 81 deletions(-) create mode 100644 it/spring-boot-with-jib/pom.xml create mode 100644 it/spring-boot-with-jib/src/main/java/io/fabric8/maven/sample/springboot/jib/Application.java create mode 100644 it/spring-boot-with-jib/src/main/java/io/fabric8/maven/sample/springboot/jib/HelloController.java diff --git a/.circleci/config.yml b/.circleci/config.yml index 81ed0aa80..deaf1bbaa 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -42,7 +42,7 @@ jobs: mvn clean install -DskipTests PROJECT_VERSION=$(mvn -q -Dexec.executable=echo -Dexec.args='${project.version}' --non-recursive exec:exec) cd it/ - find . -type f -exec sed -i 's/0.29-SNAPSHOT/'"$PROJECT_VERSION"'/g' {} + + find . -type f -exec sed -i 's/0.34-SNAPSHOT/'"$PROJECT_VERSION"'/g' {} + mvn clean install - save_cache: key: dmp-{{ checksum "pom.xml" }} diff --git a/doc/changelog.md b/doc/changelog.md index 1572340ac..89eee383f 100644 --- a/doc/changelog.md +++ b/doc/changelog.md @@ -1,5 +1,9 @@ # ChangeLog +* 0.34-SNAPSHOT + - Building 'spring-boot-with-jib' sample fails with NoSuchMethodError ([1384](https://github.com/fabric8io/docker-maven-plugin/issues/1384)) + - Loading Image tarball into docker daemon fails in JIB mode ([1385](https://github.com/fabric8io/docker-maven-plugin/issues/1385)) + * **0.34.1** (2020-09-27) - Fix NPE with "skipPush" and no build configuration given ([#1381](https://github.com/fabric8io/docker-maven-plugin/issues/1381)) - upgrade to jib-core 0.15.0 ([#1378](https://github.com/fabric8io/docker-maven-plugin/issues/1378)) diff --git a/it/docker-compose/pom.xml b/it/docker-compose/pom.xml index 6b884bc35..7b8cc526b 100644 --- a/it/docker-compose/pom.xml +++ b/it/docker-compose/pom.xml @@ -20,14 +20,14 @@ --> - io.fabric8.dmp.samples - dmp-sample-parent - 0.29-SNAPSHOT + io.fabric8.dmp.itests + dmp-it-parent + 0.34-SNAPSHOT ../pom.xml - dmp-sample-docker-compose - 0.29-SNAPSHOT + dmp-it-docker-compose + 0.34-SNAPSHOT http://www.jolokia.org diff --git a/it/dockerfile/pom.xml b/it/dockerfile/pom.xml index d83739884..a08ee6af0 100644 --- a/it/dockerfile/pom.xml +++ b/it/dockerfile/pom.xml @@ -10,16 +10,16 @@ 4.0.0 - io.fabric8.dmp.samples - dmp-sample-parent - 0.29-SNAPSHOT + io.fabric8.dmp.itests + dmp-it-parent + 0.34-SNAPSHOT ../pom.xml dockerfile - 0.29-SNAPSHOT + 0.34-SNAPSHOT war - dmp-sample-dockerfile + dmp-it-dockerfile welcome.txt @@ -77,7 +77,7 @@ - fabric8:dmp-sample-dockerfile + fabric8:dmp-it-dockerfile dockerfile diff --git a/it/dockerfile/src/main/java/io/fabric8/dmp/samples/dockerfile/HelloWorldServlet.java b/it/dockerfile/src/main/java/io/fabric8/dmp/samples/dockerfile/HelloWorldServlet.java index fff1edc3c..e8eddae95 100644 --- a/it/dockerfile/src/main/java/io/fabric8/dmp/samples/dockerfile/HelloWorldServlet.java +++ b/it/dockerfile/src/main/java/io/fabric8/dmp/samples/dockerfile/HelloWorldServlet.java @@ -1,4 +1,4 @@ -package io.fabric8.dmp.samples.dockerfile; +package io.fabric8.dmp.itests.dockerfile; import java.io.File; import java.io.IOException; diff --git a/it/dockerfile/src/main/webapp/WEB-INF/web.xml b/it/dockerfile/src/main/webapp/WEB-INF/web.xml index 28eed5372..17b078d0d 100644 --- a/it/dockerfile/src/main/webapp/WEB-INF/web.xml +++ b/it/dockerfile/src/main/webapp/WEB-INF/web.xml @@ -6,7 +6,7 @@ xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns HelloWold hello-world - io.fabric8.dmp.samples.dockerfile.HelloWorldServlet + io.fabric8.dmp.itests.dockerfile.HelloWorldServlet diff --git a/it/dockerignore/pom.xml b/it/dockerignore/pom.xml index 60b5a4341..e4efc9d78 100644 --- a/it/dockerignore/pom.xml +++ b/it/dockerignore/pom.xml @@ -8,14 +8,14 @@ --> - io.fabric8.dmp.samples - dmp-sample-parent - 0.29-SNAPSHOT + io.fabric8.dmp.itests + dmp-it-parent + 0.34-SNAPSHOT ../pom.xml - dmp-sample-dockerignore - 0.29-SNAPSHOT + dmp-it-dockerignore + 0.34-SNAPSHOT docker-build @@ -44,7 +44,7 @@ simple - dmp-sample/dockerignore + dmp-it/dockerignore ${project.basedir} gzip diff --git a/it/healthcheck/pom.xml b/it/healthcheck/pom.xml index dec96bc3e..c0c9eedd8 100644 --- a/it/healthcheck/pom.xml +++ b/it/healthcheck/pom.xml @@ -10,14 +10,14 @@ --> - io.fabric8.dmp.samples - dmp-sample-parent - 0.29-SNAPSHOT + io.fabric8.dmp.itests + dmp-it-parent + 0.34-SNAPSHOT ../pom.xml - dmp-sample-healthcheck - 0.29-SNAPSHOT + dmp-it-healthcheck + 0.34-SNAPSHOT diff --git a/it/helloworld/pom.xml b/it/helloworld/pom.xml index c4dd7ba06..2ce7fff29 100644 --- a/it/helloworld/pom.xml +++ b/it/helloworld/pom.xml @@ -10,17 +10,17 @@ 4.0.0 - io.fabric8.dmp.samples - dmp-sample-parent - 0.29-SNAPSHOT + io.fabric8.dmp.itests + dmp-it-parent + 0.34-SNAPSHOT ../pom.xml - dmp-sample-helloworld - 0.29-SNAPSHOT + dmp-it-helloworld + 0.34-SNAPSHOT jar - dmp-sample-helloworld + dmp-it-helloworld diff --git a/it/log/pom.xml b/it/log/pom.xml index e58bbbc83..ea99f0a27 100644 --- a/it/log/pom.xml +++ b/it/log/pom.xml @@ -11,16 +11,16 @@ --> - io.fabric8.dmp.samples - dmp-sample-parent - 0.29-SNAPSHOT + io.fabric8.dmp.itests + dmp-it-parent + 0.34-SNAPSHOT ../pom.xml io.fabric8 - dmp-sample-log - 0.29-SNAPSHOT + dmp-it-log + 0.34-SNAPSHOT diff --git a/it/net/pom.xml b/it/net/pom.xml index ef2a647dc..2fbeecab7 100644 --- a/it/net/pom.xml +++ b/it/net/pom.xml @@ -14,14 +14,14 @@ --> - io.fabric8.dmp.samples - dmp-sample-parent - 0.29-SNAPSHOT + io.fabric8.dmp.itests + dmp-it-parent + 0.34-SNAPSHOT ../pom.xml - dmp-sample-net - 0.29-SNAPSHOT + dmp-it-net + 0.34-SNAPSHOT diff --git a/it/pom.xml b/it/pom.xml index 7019de16b..b8480f6f1 100644 --- a/it/pom.xml +++ b/it/pom.xml @@ -19,9 +19,9 @@ --> - io.fabric8.dmp.samples - dmp-sample-parent - 0.29-SNAPSHOT + io.fabric8.dmp.itests + dmp-it-parent + 0.34-SNAPSHOT pom http://www.jolokia.org @@ -58,5 +58,6 @@ dockerfile log run-java + spring-boot-with-jib diff --git a/it/properties/pom.xml b/it/properties/pom.xml index f7421937c..fa975eee4 100644 --- a/it/properties/pom.xml +++ b/it/properties/pom.xml @@ -8,14 +8,14 @@ --> - io.fabric8.dmp.samples - dmp-sample-parent - 0.29-SNAPSHOT + io.fabric8.dmp.itests + dmp-it-parent + 0.34-SNAPSHOT ../pom.xml - dmp-sample-properties - 0.29-SNAPSHOT + dmp-it-properties + 0.34-SNAPSHOT docker-build @@ -23,6 +23,7 @@ io.fabric8 docker-maven-plugin + ${project.version} start diff --git a/it/run-java/pom.xml b/it/run-java/pom.xml index e5e574107..82bcac279 100644 --- a/it/run-java/pom.xml +++ b/it/run-java/pom.xml @@ -5,16 +5,16 @@ 4.0.0 - io.fabric8.dmp.samples - dmp-sample-parent - 0.29-SNAPSHOT + io.fabric8.dmp.itests + dmp-it-parent + 0.34-SNAPSHOT ../pom.xml - io.fabric8.dmp.samples - dmp-sample-run-java + io.fabric8.dmp.itests + dmp-it-run-java jar - 0.29-SNAPSHOT + 0.34-SNAPSHOT diff --git a/it/smallest/pom.xml b/it/smallest/pom.xml index 6e5dd8e07..aba1820ed 100644 --- a/it/smallest/pom.xml +++ b/it/smallest/pom.xml @@ -2,15 +2,15 @@ 4.0.0 - io.fabric8.dmp.samples - dmp-sample-parent - 0.29-SNAPSHOT + io.fabric8.dmp.itests + dmp-it-parent + 0.34-SNAPSHOT ../pom.xml fabric8io - dmp-sample-smallest - 0.29-SNAPSHOT + dmp-it-smallest + 0.34-SNAPSHOT diff --git a/it/spring-boot-with-jib/pom.xml b/it/spring-boot-with-jib/pom.xml new file mode 100644 index 000000000..360dcf0c2 --- /dev/null +++ b/it/spring-boot-with-jib/pom.xml @@ -0,0 +1,141 @@ + + + + 4.0.0 + + io.fabric8.dmp.itests + dmp-it-parent + 0.34-SNAPSHOT + ../pom.xml + + + dmp-it-spring-boot-jib + 0.34-SNAPSHOT + jar + + Docker Maven Plugin Integration test with Spring Boot With Build Mode JIB + + + + sonatype-nexus-snapshots + Sonatype Nexus Snapshots + https://oss.sonatype.org/content/repositories/snapshots/ + + + sonatype-nexus-staging + Nexus Release Repository + https://oss.sonatype.org/service/local/staging/deploy/maven2/ + + + + 1.8 + 1.8 + true + fabric8 + 2.3.3.RELEASE + + + + + + + org.springframework.boot + spring-boot-starter-web + ${spring.version} + + + + org.springframework.boot + spring-boot-starter-actuator + ${spring.version} + + + + + jakarta.xml.bind + jakarta.xml.bind-api + 2.3.2 + + + + + org.glassfish.jaxb + jaxb-runtime + 2.3.2 + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + ${spring.version} + + + + repackage + + + + + + io.fabric8 + docker-maven-plugin + ${project.version} + + true + + + ${docker.user}/spring-boot-dmp-it-jib + + fabric8/java-centos-openjdk8-jdk:1.5.6 + + artifact + + java -jar /maven/${project.artifactId}-${project.version}.jar + + 8080 + + + + + + + + build + pre-integration-test + + build + + + + + + org.apache.maven.plugins + maven-antrun-plugin + 1.8 + + + generateSources + post-integration-test + + + + + + + + + + run + + + + + + + + diff --git a/it/spring-boot-with-jib/src/main/java/io/fabric8/maven/sample/springboot/jib/Application.java b/it/spring-boot-with-jib/src/main/java/io/fabric8/maven/sample/springboot/jib/Application.java new file mode 100644 index 000000000..e7cb430c7 --- /dev/null +++ b/it/spring-boot-with-jib/src/main/java/io/fabric8/maven/sample/springboot/jib/Application.java @@ -0,0 +1,13 @@ +package io.fabric8.maven.sample.springboot.jib; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class Application { + + public static void main(String[] args) { + SpringApplication.run(Application.class, args); + } + +} diff --git a/it/spring-boot-with-jib/src/main/java/io/fabric8/maven/sample/springboot/jib/HelloController.java b/it/spring-boot-with-jib/src/main/java/io/fabric8/maven/sample/springboot/jib/HelloController.java new file mode 100644 index 000000000..7062abd0c --- /dev/null +++ b/it/spring-boot-with-jib/src/main/java/io/fabric8/maven/sample/springboot/jib/HelloController.java @@ -0,0 +1,15 @@ +package io.fabric8.maven.sample.springboot.jib; + +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + + +@RestController +public class HelloController { + + @RequestMapping("/") + public String index() { + return "

Greetings from Spring Boot(Powered by JIB)!!

"; + } + +} diff --git a/it/volume/pom.xml b/it/volume/pom.xml index 23ce71565..a26379da9 100644 --- a/it/volume/pom.xml +++ b/it/volume/pom.xml @@ -13,14 +13,14 @@ --> - io.fabric8.dmp.samples - dmp-sample-parent - 0.29-SNAPSHOT + io.fabric8.dmp.itests + dmp-it-parent + 0.34-SNAPSHOT ../pom.xml - dmp-sample-volume - 0.29-SNAPSHOT + dmp-it-volume + 0.34-SNAPSHOT diff --git a/it/zero-config/Dockerfile b/it/zero-config/Dockerfile index fd49554dc..ececd21d8 100644 --- a/it/zero-config/Dockerfile +++ b/it/zero-config/Dockerfile @@ -1,7 +1,7 @@ FROM openjdk:jre #RUN VERSION=$(mvn -q -Dexec.executable=echo -Dexec.args='${project.version}' --non-recursive exec:exec) -ARG jar_file=target/zero-config-${project.version}.jar +ARG jar_file=target/dmp-it-zero-config-${project.version}.jar ADD $jar_file /tmp/zero-config.jar CMD java -cp /tmp/zero-config.jar HelloWorld diff --git a/it/zero-config/pom.xml b/it/zero-config/pom.xml index 292aecd4e..43b61ed0f 100644 --- a/it/zero-config/pom.xml +++ b/it/zero-config/pom.xml @@ -5,17 +5,17 @@ 4.0.0 - io.fabric8.dmp.samples - dmp-sample-parent - 0.29-SNAPSHOT + io.fabric8.dmp.itests + dmp-it-parent + 0.34-SNAPSHOT ../pom.xml - io.fabric8.dmp.samples - zero-config + io.fabric8.dmp.itests + dmp-it-zero-config jar - 0.29-SNAPSHOT + 0.34-SNAPSHOT ${project.build.directory}/${project.build.finalName}.jar diff --git a/pom.xml b/pom.xml index bfbfa36a1..c65e3877f 100644 --- a/pom.xml +++ b/pom.xml @@ -38,6 +38,7 @@ 1.43 3.0.0-M2 0.15.0 + 4.5.10 @@ -102,7 +103,7 @@ org.apache.httpcomponents httpclient - 4.5.5 + ${httpclient.version} diff --git a/src/main/asciidoc/inc/_global-configuration.adoc b/src/main/asciidoc/inc/_global-configuration.adoc index 860a9ba5d..aeda824e7 100644 --- a/src/main/asciidoc/inc/_global-configuration.adoc +++ b/src/main/asciidoc/inc/_global-configuration.adoc @@ -109,6 +109,10 @@ By default a progress meter is printed out on the console, which is omitted when | Delegate Image Build process to https://github.com/GoogleContainerTools/jib[JIB], `false` by default. Note that this option is applicable only for <> and <> goals, other goals won't work if this is enabled (since they dependend on Docker specific features) | `docker.build.jib` +| *jibImageFormat* +| Format of the image to be built. Values can be `oci` and `docker` with `docker` as default value +| `docker.build.jib.imageFormat` + | *outputDirectory* | Default output directory to be used by this plugin. The default value is `target/docker` and is only used for the goal `{plugin}:build`. | `docker.target.dir` diff --git a/src/main/java/io/fabric8/maven/docker/AbstractDockerMojo.java b/src/main/java/io/fabric8/maven/docker/AbstractDockerMojo.java index b2a68b246..e9fa9e662 100644 --- a/src/main/java/io/fabric8/maven/docker/AbstractDockerMojo.java +++ b/src/main/java/io/fabric8/maven/docker/AbstractDockerMojo.java @@ -171,6 +171,9 @@ public abstract class AbstractDockerMojo extends AbstractMojo implements Context @Parameter(property = "docker.build.jib", defaultValue = "false") public boolean jib; + @Parameter(property = "docker.build.jib.imageFormat", defaultValue = "docker") + public String jibImageFormat; + @Parameter(property = "docker.source.dir", defaultValue="src/main/docker") public String sourceDirectory; diff --git a/src/main/java/io/fabric8/maven/docker/BuildMojo.java b/src/main/java/io/fabric8/maven/docker/BuildMojo.java index 07080a4e3..dd3931508 100644 --- a/src/main/java/io/fabric8/maven/docker/BuildMojo.java +++ b/src/main/java/io/fabric8/maven/docker/BuildMojo.java @@ -89,7 +89,7 @@ private void proceedWithBuildProcess(ServiceHub hub, BuildService.BuildContext b private void proceedWithJibBuild(ServiceHub hub, BuildService.BuildContext buildContext, ImageConfiguration imageConfig) throws MojoExecutionException { log.info("Building Container image with [[B]]JIB(Java Image Builder)[[B]] mode"); - new JibBuildService(hub, createMojoParameters(), log).build(imageConfig, buildContext.getRegistryConfig()); + new JibBuildService(hub, createMojoParameters(), log).build(jibImageFormat, imageConfig, buildContext.getRegistryConfig()); } private void proceedWithDockerBuild(BuildService buildService, BuildService.BuildContext buildContext, ImageConfiguration imageConfig, ImagePullManager pullManager) throws MojoExecutionException, IOException { diff --git a/src/main/java/io/fabric8/maven/docker/service/JibBuildService.java b/src/main/java/io/fabric8/maven/docker/service/JibBuildService.java index aa191aef3..2d7baf2de 100644 --- a/src/main/java/io/fabric8/maven/docker/service/JibBuildService.java +++ b/src/main/java/io/fabric8/maven/docker/service/JibBuildService.java @@ -17,7 +17,6 @@ import org.apache.maven.plugin.MojoExecutionException; import java.io.File; -import java.io.IOException; import java.util.Arrays; import java.util.Collection; import java.util.List; @@ -45,7 +44,7 @@ public JibBuildService(ServiceHub hub, MojoParameters mojoParameters, Logger log this.log = log; } - public void build(ImageConfiguration imageConfig, RegistryService.RegistryConfig registryConfig) throws MojoExecutionException { + public void build(String jibImageFormat, ImageConfiguration imageConfig, RegistryService.RegistryConfig registryConfig) throws MojoExecutionException { try { log.info("[[B]]JIB[[B]] image build started"); if (imageConfig.getBuildConfiguration().isDockerFileMode()) { @@ -55,7 +54,7 @@ public void build(ImageConfiguration imageConfig, RegistryService.RegistryConfig BuildDirs buildDirs = new BuildDirs(imageConfig.getName(), mojoParameters); final Credential pullRegistryCredential = getRegistryCredentials( registryConfig, false, imageConfig, log); - final JibContainerBuilder containerBuilder = containerFromImageConfiguration(imageConfig, pullRegistryCredential); + final JibContainerBuilder containerBuilder = containerFromImageConfiguration(jibImageFormat, imageConfig, pullRegistryCredential); File dockerTarArchive = getAssemblyTarArchive(imageConfig, serviceHub, mojoParameters, log); diff --git a/src/main/java/io/fabric8/maven/docker/util/JibServiceUtil.java b/src/main/java/io/fabric8/maven/docker/util/JibServiceUtil.java index e2fd118d3..5b95c272d 100644 --- a/src/main/java/io/fabric8/maven/docker/util/JibServiceUtil.java +++ b/src/main/java/io/fabric8/maven/docker/util/JibServiceUtil.java @@ -20,6 +20,7 @@ import io.fabric8.maven.docker.config.Arguments; import io.fabric8.maven.docker.config.BuildImageConfiguration; import io.fabric8.maven.docker.config.ImageConfiguration; +import io.fabric8.maven.docker.model.Image; import org.apache.commons.lang3.StringUtils; import java.io.File; @@ -97,10 +98,10 @@ public static void buildContainer(JibContainerBuilder jibContainerBuilder, TarIm } } - public static JibContainerBuilder containerFromImageConfiguration( + public static JibContainerBuilder containerFromImageConfiguration(String jibImageFormat, ImageConfiguration imageConfiguration, Credential pullRegistryCredential) throws InvalidImageReferenceException { final JibContainerBuilder containerBuilder = Jib.from(getRegistryImage(getBaseImage(imageConfiguration), pullRegistryCredential)) - .setFormat(ImageFormat.OCI); + .setFormat(getImageFormat(jibImageFormat)); return populateContainerBuilderFromImageConfiguration(containerBuilder, imageConfiguration); } @@ -202,6 +203,13 @@ static Set getAllImageTags(List tags, String imageName) { return tagSet; } + static ImageFormat getImageFormat(String jibImageFormat) { + if (jibImageFormat != null && jibImageFormat.toLowerCase().equalsIgnoreCase("oci")) { + return ImageFormat.OCI; + } + return ImageFormat.Docker; + } + private static void submitPushToJib(TarImage baseImage, RegistryImage targetImage, ExecutorService jibBuildExecutor, Logger logger) throws InterruptedException, ExecutionException, RegistryException, CacheDirectoryCreationException, IOException { Jib.from(baseImage).containerize(Containerizer.to(targetImage) .setAllowInsecureRegistries(true) diff --git a/src/test/java/io/fabric8/maven/docker/util/JibServiceUtilTest.java b/src/test/java/io/fabric8/maven/docker/util/JibServiceUtilTest.java index b4682cc84..f8fb5f460 100644 --- a/src/test/java/io/fabric8/maven/docker/util/JibServiceUtilTest.java +++ b/src/test/java/io/fabric8/maven/docker/util/JibServiceUtilTest.java @@ -27,6 +27,7 @@ import static io.fabric8.maven.docker.util.JibServiceUtil.BUSYBOX; import static io.fabric8.maven.docker.util.JibServiceUtil.containerFromImageConfiguration; +import static io.fabric8.maven.docker.util.JibServiceUtil.getImageFormat; import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; @@ -52,7 +53,7 @@ public void testContainerFromImageConfiguration(@Mocked JibContainerBuilder cont // Given ImageConfiguration imageConfiguration = getSampleImageConfiguration(); // When - JibContainerBuilder jibContainerBuilder = containerFromImageConfiguration(imageConfiguration, null); + JibContainerBuilder jibContainerBuilder = containerFromImageConfiguration(ImageFormat.Docker.name(), imageConfiguration, null); // Then // @formatter:off new Verifications() {{ @@ -68,7 +69,7 @@ public void testContainerFromImageConfiguration(@Mocked JibContainerBuilder cont times = 1; jibContainerBuilder.setVolumes(new HashSet<>(Collections.singletonList(AbsoluteUnixPath.get("/mnt/volume1")))); times = 1; - jibContainerBuilder.setFormat(ImageFormat.OCI); + jibContainerBuilder.setFormat(ImageFormat.Docker); times = 1; }}; // @formatter:on @@ -122,6 +123,13 @@ public void testGetFullImageNameWithProvidedTag() { assertEquals("test/test-project:0.0.1", JibServiceUtil.getFullImageName(getSampleImageConfiguration(), "0.0.1")); } + @Test + public void testGetImageFormat() { + assertEquals(ImageFormat.Docker, JibServiceUtil.getImageFormat("Docker")); + assertEquals(ImageFormat.OCI, JibServiceUtil.getImageFormat("OCI")); + assertEquals(ImageFormat.OCI, JibServiceUtil.getImageFormat("oci")); + } + private ImageConfiguration getSampleImageConfiguration() { Assembly assembly = new Assembly(); FileItem fileItem = new FileItem();