Skip to content

Commit

Permalink
#512 Tuned a bit according to comments
Browse files Browse the repository at this point in the history
  • Loading branch information
rhuss committed Jul 19, 2016
1 parent 7b02730 commit 1dae1eb
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 10 deletions.
11 changes: 8 additions & 3 deletions src/main/asciidoc/inc/_global-configuration.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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*
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/io/fabric8/maven/docker/AbstractDockerMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> previouslyPulledCache = getPreviouslyPulledImageCache();
if (!queryService.imageRequiresAutoPull(autoPull, image, autoPullAlwaysAllowed, previouslyPulledCache)) {
return;
}

Expand All @@ -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
Expand All @@ -434,8 +436,6 @@ private synchronized Set<String> getPreviouslyPulledImageCache() {
@SuppressWarnings({ "rawtypes", "unchecked" })
Set<String> 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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -209,8 +210,6 @@ private boolean imageRequiresPull(AutoPullMode autoPullMode, String imageName, b
return false;
}

previouslyPulled.add(imageName);

return pullIfNotPresent(autoPullMode, imageName) || alwaysPull(autoPullMode, always);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ public boolean doPullIfNotPresent() {

public boolean alwaysPull() {
return (this == ONCE || this == ALWAYS);

}

static public AutoPullMode fromString(String val) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down

0 comments on commit 1dae1eb

Please sign in to comment.