Skip to content

Commit 671eae8

Browse files
committed
fix : Introduce pullRetries and pushRetries fields
Signed-off-by: Rohan Kumar <[email protected]>
1 parent e823b55 commit 671eae8

File tree

11 files changed

+81
-22
lines changed

11 files changed

+81
-22
lines changed

src/main/asciidoc/inc/build/_configuration.adoc

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,6 @@ a| Scan the archive specified in `dockerArchive` and find the actual repository
120120
| *shell*
121121
| Shell to be used for the *runCmds*. It contains *arg* elements which are defining the executable and its params.
122122

123-
| *retries*
124-
| If pulling an image is required, how often should a pull be retried before giving up. This useful for flaky registries which tend to return 500 error codes from time to time. The default is 0 which means no retry at all.
125-
126123
| *runCmds*
127124
| Commands to be run during the build process. It contains *run* elements which are passed to the shell. Whitespace is trimmed from each element and empty elements are ignored. The run commands are inserted right after the assembly and after *workdir* into the Dockerfile. This tag is not to be confused with the `<run>` section for this image which specifies the runtime behaviour when starting containers.
128125

src/main/asciidoc/inc/start/_configuration.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ In addition to the <<global-configuration>>, this goal supports the following gl
99
| Default pattern for naming all containers when they are created. See <<container-name, Container Names>> for details.
1010
| `docker.containerNamePattern`
1111

12-
| *retries*
12+
| *pullRetries*
1313
| If pulling an image is required, how often should a pull be retried before giving up. This useful for flaky registries which tend to return 500 error codes from time to time. The default is 0 which means no retry at all.
1414
| `docker.pull.retries`
1515

src/main/asciidoc/inc/watch/_configuration.adoc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,14 @@ below how this can be specified.
5555
| `docker.keepRunning`
5656

5757
| *keepContainer*
58-
| As for `{plugin}:stop`, if this is set to `true` (and `keepRunning` is disabled) then all container will be removed after they have been stopped. The default is `true`.
58+
| As for `{plugin}:stop`, if this is set to `true` (and `keepRunning` is disabled) then all container will be removed after they have been stopped. The default is `false`.
5959
| `docker.keepContainer`
6060

6161
| *removeVolumes*
6262
| if set to `true` will remove any volumes associated to the container as well. This option will be ignored if either `keepContainer` or `keepRunning` are `true`.
6363
| `docker.removeVolumes`
6464

65-
| *retries*
65+
| *pullRetries*
6666
| If pulling an image is required, how often should a pull be retried before giving up. This useful for flaky registries which tend to return 500 error codes from time to time. The default is 0 which means no retry at all.
6767
| `docker.pull.retries`
6868
|===

src/main/java/io/fabric8/maven/docker/AbstractDockerMojo.java

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,15 @@ public abstract class AbstractDockerMojo extends AbstractMojo implements Context
121121
@Parameter(property = "docker.removeVolumes", defaultValue = "false")
122122
protected boolean removeVolumes;
123123

124-
@Parameter(property = "docker.pull.retries", defaultValue = "0")
124+
@Parameter(property = "docker.retries", defaultValue = "0")
125125
protected int retries;
126126

127+
@Parameter(property = "docker.pull.retries", defaultValue = "0")
128+
protected int pullRetries;
129+
130+
@Parameter(property = "docker.push.retries", defaultValue = "0")
131+
protected int pushRetries;
132+
127133
@Parameter(property = "docker.apiVersion")
128134
private String apiVersion;
129135

@@ -580,7 +586,7 @@ protected void pullImage(RegistryService registryService, ImageConfiguration ima
580586
RunImageConfiguration runConfiguration = imageConfig.getRunConfiguration();
581587
ImagePullManager pullManager = getImagePullManager(determinePullPolicy(runConfiguration), autoPull);
582588
RegistryConfig registryConfig = getRegistryConfig(pullRegistry);
583-
registryService.pullImageWithPolicy(imageName, pullManager, registryConfig, imageConfig.getBuildConfiguration(), retries);
589+
registryService.pullImageWithPolicy(imageName, pullManager, registryConfig, imageConfig.getBuildConfiguration(), getPullRetries());
584590
}
585591

586592
protected boolean shouldSkipPom() {
@@ -611,4 +617,18 @@ protected String determinePullPolicy(RunImageConfiguration runConfig) {
611617
protected ProjectPaths createProjectPaths() {
612618
return new ProjectPaths(project.getBasedir(), outputDirectory);
613619
}
620+
621+
protected int getPullRetries() {
622+
if (pullRetries > 0) {
623+
return pullRetries;
624+
}
625+
return retries;
626+
}
627+
628+
protected int getPushRetries() {
629+
if (pushRetries > 0) {
630+
return pushRetries;
631+
}
632+
return retries;
633+
}
614634
}

src/main/java/io/fabric8/maven/docker/BuildMojo.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,6 @@ public class BuildMojo extends AbstractBuildSupportMojo {
6464
*/
6565
@Parameter(property = "docker.skip.tag", defaultValue = "false")
6666
protected boolean skipTag;
67-
@Parameter(property = "docker.pull.retries", defaultValue = "0")
68-
private int retries;
6967

7068
@Override
7169
protected void executeInternal(ServiceHub hub) throws IOException, MojoExecutionException {
@@ -113,7 +111,7 @@ private void proceedWithDockerBuild(ServiceHub hub, BuildService.BuildContext bu
113111
if (imageConfig.isBuildX()) {
114112
hub.getBuildXService().build(createProjectPaths(), imageConfig, null, getAuthConfig(imageConfig), buildArchiveFile);
115113
} else {
116-
buildService.buildImage(imageConfig, pullManager, buildContext, buildArchiveFile, retries);
114+
buildService.buildImage(imageConfig, pullManager, buildContext, buildArchiveFile, getPullRetries());
117115
if (!skipTag) {
118116
buildService.tagImage(imageConfig);
119117
}

src/main/java/io/fabric8/maven/docker/PushMojo.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,6 @@ public class PushMojo extends AbstractDockerMojo {
3030
*/
3131
@Parameter(property = "docker.skip.tag", defaultValue = "false")
3232
private boolean skipTag;
33-
34-
@Parameter(property = "docker.push.retries", defaultValue = "0")
35-
private int retries;
3633

3734
/**
3835
* {@inheritDoc}
@@ -51,14 +48,14 @@ public void executeInternal(ServiceHub hub) throws DockerAccessException, MojoEx
5148
}
5249

5350
private void executeDockerPush(ServiceHub hub) throws MojoExecutionException, DockerAccessException {
54-
hub.getRegistryService().pushImages(createProjectPaths(), getResolvedImages(), retries, getRegistryConfig(pushRegistry), skipTag);
51+
hub.getRegistryService().pushImages(createProjectPaths(), getResolvedImages(), getPushRetries(), getRegistryConfig(pushRegistry), skipTag);
5552
}
5653

5754
private void executeJibPush(ServiceHub hub) throws MojoExecutionException {
5855
log.info("Pushing Container image with [[B]]JIB(Java Image Builder)[[B]] mode");
5956
JibBuildService jibBuildService = new JibBuildService(hub, new MojoParameters(session, project, null, null, null,
6057
settings, sourceDirectory, outputDirectory, null), log);
61-
jibBuildService.push(getResolvedImages(), retries, getRegistryConfig(pushRegistry), skipTag);
58+
jibBuildService.push(getResolvedImages(), getPushRetries(), getRegistryConfig(pushRegistry), skipTag);
6259
}
6360

6461
}

src/main/java/io/fabric8/maven/docker/StartMojo.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
import io.fabric8.maven.docker.config.RunVolumeConfiguration;
3535
import io.fabric8.maven.docker.config.VolumeConfiguration;
3636
import io.fabric8.maven.docker.log.LogDispatcher;
37-
import io.fabric8.maven.docker.service.ImagePullManager;
3837
import io.fabric8.maven.docker.service.QueryService;
3938
import io.fabric8.maven.docker.service.RegistryService;
4039
import io.fabric8.maven.docker.service.RunService;

src/main/java/io/fabric8/maven/docker/WatchMojo.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,17 +73,14 @@ public class WatchMojo extends AbstractBuildSupportMojo {
7373
@Parameter(property = "docker.autoCreateCustomNetworks", defaultValue = "false")
7474
protected boolean autoCreateCustomNetworks;
7575

76-
@Parameter(property = "docker.pull.retries", defaultValue = "0")
77-
private int retries;
78-
7976
@Override
8077
protected synchronized void executeInternal(ServiceHub hub) throws IOException,
8178
MojoExecutionException {
8279

8380
BuildService.BuildContext buildContext = getBuildContext();
8481
WatchService.WatchContext watchContext = getWatchContext(hub);
8582

86-
hub.getWatchService().watch(watchContext, buildContext, getResolvedImages(), retries);
83+
hub.getWatchService().watch(watchContext, buildContext, getResolvedImages(), getPullRetries());
8784
}
8885

8986
protected WatchService.WatchContext getWatchContext(ServiceHub hub) throws IOException {

src/test/java/io/fabric8/maven/docker/BuildMojoTest.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
import java.util.List;
3333
import java.util.Map;
3434

35+
import static org.junit.jupiter.api.Assertions.assertEquals;
36+
3537
@ExtendWith(MockitoExtension.class)
3638
class BuildMojoTest extends MojoTestBase {
3739
private static final String NON_NATIVE_PLATFORM = "linux/amd64";
@@ -241,6 +243,29 @@ void buildUsingBuildxWithMultipleAuth() throws IOException, MojoExecutionExcepti
241243
thenAuthContainsRegistry("custom-registry.org");
242244
}
243245

246+
@Test
247+
void getPullRetries_whenPullRetriesConfigured_thenUsePullRetries() {
248+
givenMavenProject(buildMojo);
249+
buildMojo.pullRetries = 2;
250+
251+
assertEquals(2, buildMojo.getPullRetries());
252+
}
253+
254+
@Test
255+
void getPullRetries_whenRetriesConfigured_thenUseRetries() {
256+
givenMavenProject(buildMojo);
257+
buildMojo.retries = 2;
258+
259+
assertEquals(2, buildMojo.getPullRetries());
260+
}
261+
262+
@Test
263+
void getPullRetries_whenNothingConfigured_thenReturnDefaultValue() {
264+
givenMavenProject(buildMojo);
265+
266+
assertEquals(0, buildMojo.getPullRetries());
267+
}
268+
244269
private void givenBuildXService() {
245270
BuildXService buildXService = new BuildXService(dockerAccess, dockerAssemblyManager, log, exec);
246271

src/test/java/io/fabric8/maven/docker/PushMojoTest.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212

1313
import java.io.IOException;
1414

15+
import static org.junit.jupiter.api.Assertions.assertEquals;
16+
1517
@ExtendWith(MockitoExtension.class)
1618
class PushMojoTest extends MojoTestBase {
1719
@InjectMocks
@@ -71,6 +73,29 @@ void executeInternal_whenSkipDisabled_thenImageIsPushed() throws MojoExecutionEx
7173
thenImagePushed();
7274
}
7375

76+
@Test
77+
void getPushRetries_whenPushRetriesConfigured_thenUsePushRetries() {
78+
givenMavenProject(pushMojo);
79+
pushMojo.pushRetries = 2;
80+
81+
assertEquals(2, pushMojo.getPushRetries());
82+
}
83+
84+
@Test
85+
void getPushRetries_whenRetriesConfigured_thenUseRetries() {
86+
givenMavenProject(pushMojo);
87+
pushMojo.retries = 2;
88+
89+
assertEquals(2, pushMojo.getPushRetries());
90+
}
91+
92+
@Test
93+
void getPushRetries_whenNothingConfigured_thenReturnDefaultValue() {
94+
givenMavenProject(pushMojo);
95+
96+
assertEquals(0, pushMojo.getPushRetries());
97+
}
98+
7499
private void thenImagePushed() throws MojoExecutionException, DockerAccessException {
75100
verifyPush(1);
76101
}

0 commit comments

Comments
 (0)