Skip to content

Commit f9e426b

Browse files
cmortyjonahgraham
authored andcommitted
Bug: Docker: Do not pull all tags
If the latest tag did not exist locally and no tag was given for an image, all tags were pulled.
1 parent 7966c42 commit f9e426b

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

launch/org.eclipse.cdt.docker.launcher.tests/src/org/eclipse/cdt/docker/launcher/tests/DockerServerInteractions.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import static org.hamcrest.MatcherAssert.assertThat;
1414
import static org.hamcrest.Matchers.notNullValue;
1515
import static org.junit.Assert.assertFalse;
16+
import static org.junit.Assert.assertNull;
1617
import static org.junit.Assert.assertTrue;
1718

1819
import org.eclipse.cdt.internal.docker.launcher.ContainerLaunchUtils;
@@ -31,6 +32,9 @@ class DockerServerInteractions {
3132
// A small image that exists
3233
static final String okImage = "alpine:latest";
3334
static final String imageBad = "alasdfasdfga32e:latest";
35+
static final String tagTestImage = "alpine";
36+
static final String tagTestImageTag = "alpine:2.7";
37+
3438
IDockerConnection4 cnn;
3539

3640
DockerServerInteractions() {
@@ -64,4 +68,23 @@ void failPull() throws DockerException, InterruptedException {
6468
assertFalse(di.getMessage().isEmpty());
6569
}
6670

71+
// You can clean up your registry using
72+
// docker images | grep alpine | awk '{print $3}' | xargs docker rmi
73+
@Test
74+
void noPullAllTags() throws DockerException, InterruptedException {
75+
// Remove latest
76+
if (cnn.getImageInfo(tagTestImage + ":latest") != null) {
77+
cnn.removeImage(tagTestImage + ":latest");
78+
}
79+
// Make sure the tag we test exists and remove it
80+
{
81+
final var di = ContainerLaunchUtils.provideDockerImage(null, cnn.getName(), tagTestImageTag);
82+
assertTrue(di.isOK());
83+
cnn.removeImage(tagTestImageTag);
84+
}
85+
// This should pull latest, not all tags
86+
final var di = ContainerLaunchUtils.provideDockerImage(null, cnn.getName(), tagTestImage);
87+
assertTrue(di.isOK());
88+
assertNull(cnn.getImageInfo(tagTestImageTag));
89+
}
6790
}

launch/org.eclipse.cdt.docker.launcher/src/org/eclipse/cdt/internal/docker/launcher/ContainerLaunchUtils.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131

3232
public class ContainerLaunchUtils {
3333

34+
private static final String LATEST = ":latest"; //$NON-NLS-1$
35+
3436
/**
3537
* Maps the local path, to a path that is used within a docker container.
3638
* @param path The host path
@@ -103,7 +105,7 @@ public static final String toDockerVolume(Map<String, String> pMap, IPath path)
103105
*
104106
*/
105107
public static @NonNull IStatus provideDockerImage(IProgressMonitor monitor, @NonNull final String connectionName,
106-
@NonNull final String imageName) {
108+
@NonNull String imageName) {
107109

108110
// Try to pull image, if necessary
109111
final var connection = (IDockerConnection4) DockerConnectionManager.getInstance()
@@ -115,6 +117,12 @@ public static final String toDockerVolume(Map<String, String> pMap, IPath path)
115117
NLS.bind(Messages.ContainerCommandLauncher_pullerr_noConn, imageName, connectionName));
116118
}
117119

120+
// Make sure to not pull all images if no tag is found
121+
// Nothing found -> -1 ; Make sure the : comes after the last /. If neither exists, both are -1.
122+
if (imageName.lastIndexOf(':') <= imageName.lastIndexOf('/')) {
123+
imageName = imageName + LATEST;
124+
}
125+
118126
// See if the image already exists
119127
if (connection.getImageInfo(imageName) != null)
120128
return Status.OK_STATUS;

0 commit comments

Comments
 (0)