Skip to content

Commit 01556b3

Browse files
PostremusrohanKanojia
authored andcommitted
Revert 'Only push the latest tag if no other tags where specified in docker mode. This can break your build, if you rely on the automatic latest tag.'
Signed-off-by: Martin Panzer <[email protected]>
1 parent a77cf73 commit 01556b3

File tree

3 files changed

+14
-55
lines changed

3 files changed

+14
-55
lines changed

doc/changelog.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
# ChangeLog
22

33
* **0.39-SNAPSHOT** :
4-
- Update to jnr-unixsocket 0.38.14 to solve UnsatisfiedLinkError on Apple M1 #1257
5-
- Revert "Only push the `latest` tag if no other tags where specified in jib mode. This can break your build, if you rely on the automatic `latest` tag." ([#1510](https://github.com/fabric8io/docker-maven-plugin/pull/1510))
4+
- Update to jnr-unixsocket 0.38.14 to solve UnsatisfiedLinkError on Apple M1 ([#1257](https://github.com/fabric8io/docker-maven-plugin/pull/1507)) @henningn
5+
- Revert "Only push the `latest` tag if no other tags where specified in jib mode. This can break your build, if you rely on the automatic `latest` tag." ([#1510](https://github.com/fabric8io/docker-maven-plugin/pull/1510)) @Postremus
6+
- Revert "Only push the `latest` tag if no other tags where specified in docker mode. This can break your build, if you rely on the automatic `latest` tag." ([#1509](https://github.com/fabric8io/docker-maven-plugin/pull/1509)) @Postremus
67

78
* **0.38.0** (2021-11-09):
89
- Allow replacement in tags. Added a new replacement `%T` which always adds a timestamp. ([#1491](https://github.com/fabric8io/docker-maven-plugin/pull/1491))

src/main/java/io/fabric8/maven/docker/service/RegistryService.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,16 +59,16 @@ public void pushImages(Collection<ImageConfiguration> imageConfigs,
5959

6060
AuthConfig authConfig = createAuthConfig(true, new ImageName(name).getUser(), configuredRegistry, registryConfig);
6161

62-
if (!skipTag && !buildConfig.getTags().isEmpty()) {
63-
for (String tag : buildConfig.getTags()) {
62+
long start = System.currentTimeMillis();
63+
docker.pushImage(name, authConfig, configuredRegistry, retries);
64+
log.info("Pushed %s in %s", name, EnvUtil.formatDurationTill(start));
65+
66+
if (!skipTag) {
67+
for (String tag : imageConfig.getBuildConfiguration().getTags()) {
6468
if (tag != null) {
6569
docker.pushImage(new ImageName(name, tag).getFullName(), authConfig, configuredRegistry, retries);
6670
}
6771
}
68-
} else {
69-
long start = System.currentTimeMillis();
70-
docker.pushImage(name, authConfig, configuredRegistry, retries);
71-
log.info("Pushed %s in %s", name, EnvUtil.formatDurationTill(start));
7272
}
7373
}
7474
}

src/test/java/io/fabric8/maven/docker/service/RegistryServiceTest.java

Lines changed: 5 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,8 @@
22

33
import io.fabric8.maven.docker.config.BuildImageConfiguration;
44
import io.fabric8.maven.docker.config.ImageConfiguration;
5-
6-
import java.util.ArrayList;
7-
import java.util.Arrays;
85
import java.util.Collections;
96
import java.util.HashMap;
10-
import java.util.List;
117
import java.util.Map;
128

139
import io.fabric8.maven.docker.access.AuthConfig;
@@ -18,14 +14,11 @@
1814
import io.fabric8.maven.docker.util.AutoPullMode;
1915
import io.fabric8.maven.docker.util.ImageName;
2016
import io.fabric8.maven.docker.util.Logger;
21-
import mockit.Expectations;
2217
import mockit.Mocked;
2318
import mockit.Verifications;
24-
import org.apache.maven.plugin.MojoExecutionException;
2519
import org.junit.Before;
2620
import org.junit.Test;
2721

28-
import static org.junit.Assert.assertEquals;
2922
import static org.junit.Assert.assertNotNull;
3023
import static org.junit.Assert.assertNull;
3124
import static org.junit.Assert.assertTrue;
@@ -208,7 +201,7 @@ public void tagForCustomRegistry() throws DockerAccessException {
208201
public void pushImage() throws DockerAccessException {
209202
givenAnImageConfiguration("user/test:1.0.1");
210203

211-
whenPushImageTagSkipped();
204+
whenPushImage();
212205

213206
thenImageHasBeenPushed();
214207
thenNoExceptionThrown();
@@ -218,7 +211,7 @@ public void pushImage() throws DockerAccessException {
218211
public void pushImageWithoutBuildConfig() throws DockerAccessException {
219212
givenAnImageConfigurationWithoutBuildConfig("user/test:1.0.1");
220213

221-
whenPushImageTagSkipped();
214+
whenPushImage();
222215

223216
thenImageHasNotBeenPushed();
224217
thenNoExceptionThrown();
@@ -229,38 +222,12 @@ public void pushImageSkipped() throws DockerAccessException {
229222
givenAnImageConfiguration("user/test:1.0.1");
230223
givenPushSkipped(true);
231224

232-
whenPushImageTagSkipped();
225+
whenPushImage();
233226

234227
thenImageHasNotBeenPushed();
235228
thenNoExceptionThrown();
236229
}
237230

238-
@Test
239-
public void testPushedImageTags() throws MojoExecutionException, DockerAccessException {
240-
241-
List<String> imageNames = new ArrayList<>();
242-
new Expectations() {{
243-
docker.pushImage(withCapture(imageNames), (AuthConfig) withNotNull(), anyString, anyInt);
244-
}};
245-
246-
247-
givenAnImageConfiguration("without-tags");
248-
whenPushImageTagSkipped();
249-
// latest tag is used, because no other tags are specified
250-
assertEquals(imageConfiguration.getName(), imageNames.get(0));
251-
252-
253-
givenAnImageConfigurationWithTags("with-tags");
254-
whenPushImageTagSkipped(true);
255-
whenPushImageTagSkipped();
256-
// latest tag is used, because skipTag = true
257-
assertEquals(imageConfiguration.getName(), imageNames.get(1));
258-
259-
// skipTag = false => both specified tags have to be pushed
260-
assertEquals(imageConfiguration.getName()+":foo", imageNames.get(2));
261-
assertEquals(imageConfiguration.getName()+":bar", imageNames.get(3));
262-
}
263-
264231
// ====================================================================================================
265232

266233
private void thenNoExceptionThrown() {
@@ -329,17 +296,13 @@ private void whenAutoPullImage() {
329296
}
330297
}
331298

332-
private void whenPushImageTagSkipped() {
333-
whenPushImageTagSkipped(false);
334-
}
335-
336-
private void whenPushImageTagSkipped(boolean skipTag) {
299+
private void whenPushImage() {
337300
try {
338301
RegistryService.RegistryConfig.Builder registryConfigBuilder =
339302
new RegistryService.RegistryConfig.Builder()
340303
.authConfigFactory(authConfigFactory)
341304
.authConfig(authConfig);
342-
registryService.pushImages(Collections.singleton(imageConfiguration), 1, registryConfigBuilder.build(), skipTag);
305+
registryService.pushImages(Collections.singleton(imageConfiguration), 1, registryConfigBuilder.build(), false);
343306
} catch (Exception e) {
344307
this.actualException = e;
345308
}
@@ -382,11 +345,6 @@ private void givenAnImageConfiguration(String imageName) {
382345
imageConfiguration = new ImageConfiguration.Builder().name(imageName).buildConfig(buildImageConfiguration).build();
383346
}
384347

385-
private void givenAnImageConfigurationWithTags(String imageName) {
386-
final BuildImageConfiguration buildImageConfiguration = new BuildImageConfiguration.Builder().tags(Arrays.asList("foo", "bar")).build();
387-
imageConfiguration = new ImageConfiguration.Builder().name(imageName).buildConfig(buildImageConfiguration).build();
388-
}
389-
390348
private void givenAnImageConfigurationWithoutBuildConfig(String imageName) {
391349
imageConfiguration = new ImageConfiguration.Builder().name(imageName).buildConfig(null).build();
392350
}

0 commit comments

Comments
 (0)