diff --git a/src/main/asciidoc/inc/_global-configuration.adoc b/src/main/asciidoc/inc/_global-configuration.adoc index 8985f044a..df2a5258a 100644 --- a/src/main/asciidoc/inc/_global-configuration.adoc +++ b/src/main/asciidoc/inc/_global-configuration.adoc @@ -35,9 +35,14 @@ be specified by the certPath or machine configuration, or by the | `docker.autoCreate` `CustomNetworks` | *autoPull* -| Valid values: `on|off|always|once`. By default external images (base image for building or images to start) are downloaded automatically if they don't exist locally. - This feature can be turned off by setting this value to `off`. If you want to check for a newer version of an image and download it if it exists, set this value to `always`. - If you are running a `reactor` build, you may set this value to `once` so the image is only checkedn and pulled once for the entire build. +a| Decide how to pull missing base images or images to start: + + * `on` : Automatic download any missing images (default) + * `off` : Automatic pulling is switched off + * `always` : Pull images always even when they are already exist locally + * `once` : For multi-module builds images are only checked once and pulled for the whole build. + + to `once` so the image is only checkedn and pulled once for the entire build. | `docker.autoPull` | *certPath* diff --git a/src/main/java/io/fabric8/maven/docker/AbstractDockerMojo.java b/src/main/java/io/fabric8/maven/docker/AbstractDockerMojo.java index ea92da652..df835b7bc 100644 --- a/src/main/java/io/fabric8/maven/docker/AbstractDockerMojo.java +++ b/src/main/java/io/fabric8/maven/docker/AbstractDockerMojo.java @@ -413,7 +413,8 @@ protected void checkImageWithAutoPull(ServiceHub hub, String image, String regis boolean autoPullAlwaysAllowed) throws DockerAccessException, MojoExecutionException { // TODO: further refactoring could be done to avoid referencing the QueryService here QueryService queryService = hub.getQueryService(); - if (!queryService.imageRequiresAutoPull(autoPull, image, autoPullAlwaysAllowed, getPreviouslyPulledImageCache())) { + Set previouslyPulledCache = getPreviouslyPulledImageCache(); + if (!queryService.imageRequiresAutoPull(autoPull, image, autoPullAlwaysAllowed, previouslyPulledCache)) { return; } @@ -422,6 +423,7 @@ protected void checkImageWithAutoPull(ServiceHub hub, String image, String regis long time = System.currentTimeMillis(); docker.pullImage(withLatestIfNoTag(image), prepareAuthConfig(imageName, registry, false), registry); log.info("Pulled %s in %s", imageName.getFullName(), EnvUtil.formatDurationTill(time)); + previouslyPulledCache.add(image); if (registry != null && !imageName.hasRegistry()) { // If coming from a registry which was not contained in the original name, add a tag from the @@ -434,8 +436,6 @@ private synchronized Set getPreviouslyPulledImageCache() { @SuppressWarnings({ "rawtypes", "unchecked" }) Set cache = (Set) session.getUserProperties().get(CONTEXT_KEY_PREVIOUSLY_PULLED); if (cache == null) { - System.out.println("creating new context"); - cache = Sets.newConcurrentHashSet(); session.getUserProperties().put(CONTEXT_KEY_PREVIOUSLY_PULLED, cache); } diff --git a/src/main/java/io/fabric8/maven/docker/service/QueryService.java b/src/main/java/io/fabric8/maven/docker/service/QueryService.java index e3f42b174..bc98e8bc7 100644 --- a/src/main/java/io/fabric8/maven/docker/service/QueryService.java +++ b/src/main/java/io/fabric8/maven/docker/service/QueryService.java @@ -177,7 +177,8 @@ public boolean hasImage(String name) throws DockerAccessException { * @param mode the auto pull mode coming from the configuration * @param imageName name of the image to check * @param always whether to a alwaysPull mode would be active or is always ignored - * @return + * @return true if the image needs to be pulled, false otherwise + * * @throws DockerAccessException * @throws MojoExecutionException */ @@ -209,8 +210,6 @@ private boolean imageRequiresPull(AutoPullMode autoPullMode, String imageName, b return false; } - previouslyPulled.add(imageName); - return pullIfNotPresent(autoPullMode, imageName) || alwaysPull(autoPullMode, always); } diff --git a/src/main/java/io/fabric8/maven/docker/util/AutoPullMode.java b/src/main/java/io/fabric8/maven/docker/util/AutoPullMode.java index b30ac33cb..be2f6ba1e 100644 --- a/src/main/java/io/fabric8/maven/docker/util/AutoPullMode.java +++ b/src/main/java/io/fabric8/maven/docker/util/AutoPullMode.java @@ -45,7 +45,6 @@ public boolean doPullIfNotPresent() { public boolean alwaysPull() { return (this == ONCE || this == ALWAYS); - } static public AutoPullMode fromString(String val) { diff --git a/src/test/java/io/fabric8/maven/docker/service/QueryServiceAutoPullTest.java b/src/test/java/io/fabric8/maven/docker/service/QueryServiceAutoPullTest.java index 9f2641d7e..8d7a04755 100644 --- a/src/test/java/io/fabric8/maven/docker/service/QueryServiceAutoPullTest.java +++ b/src/test/java/io/fabric8/maven/docker/service/QueryServiceAutoPullTest.java @@ -107,11 +107,17 @@ public void testPullImageOnce() throws Exception { whenCheckIfImageRequiredAutoPull(); thenImageRequiresPull(); + givenPreviousPullHappened(); + givenAnImageExists(); whenCheckIfImageRequiredAutoPull(); thenImageDoesNotRequirePull(); } + private void givenPreviousPullHappened() { + previousImages.add(imageName); + } + private void givenAnImageDoesNotExist() throws DockerAccessException { this.imageName = "test";