Skip to content
This repository has been archived by the owner on Sep 29, 2021. It is now read-only.

Commit

Permalink
Don't pull the probe image if we already have it.
Browse files Browse the repository at this point in the history
Its freshness is not a concern.
  • Loading branch information
Nic Cope committed Feb 22, 2016
1 parent af0c71e commit 08f957c
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
Expand Up @@ -31,6 +31,7 @@
import com.spotify.docker.client.DockerClient;
import com.spotify.docker.client.DockerException;
import com.spotify.docker.client.DockerHost;
import com.spotify.docker.client.ImageNotFoundException;
import com.spotify.docker.client.messages.ContainerConfig;
import com.spotify.docker.client.messages.ContainerCreation;
import com.spotify.docker.client.messages.ContainerExit;
Expand Down Expand Up @@ -209,9 +210,10 @@ private String checkDockerAndGetGateway() throws HeliosDeploymentException {
.cmd(probeCommand(probeName))
.build();


final ContainerCreation creation;
try {
dockerClient.pull(PROBE_IMAGE);
pullIfAbsent(PROBE_IMAGE);
creation = dockerClient.createContainer(containerConfig, probeName);
} catch (DockerException | InterruptedException e) {
throw new HeliosDeploymentException("helios-solo probe container creation failed", e);
Expand Down Expand Up @@ -245,6 +247,17 @@ private String checkDockerAndGetGateway() throws HeliosDeploymentException {
return gateway;
}

private void pullIfAbsent(final String image) throws DockerException, InterruptedException {
try {
dockerClient.inspectImage(image);
log.info("helios-solo image {} is present. Not pulling it.", image);
return;
} catch (ImageNotFoundException e) {
log.info("helios-solo pulling new image: {}", image);
}
dockerClient.pull(PROBE_IMAGE);
}

private List<String> probeCommand(final String probeName) {
final List<String> cmd = new ArrayList<>(ImmutableList.of("curl", "-f"));
switch (containerDockerHost.uri().getScheme()) {
Expand Down
Expand Up @@ -23,10 +23,12 @@

import com.spotify.docker.client.DockerClient;
import com.spotify.docker.client.DockerHost;
import com.spotify.docker.client.ImageNotFoundException;
import com.spotify.docker.client.messages.ContainerConfig;
import com.spotify.docker.client.messages.ContainerCreation;
import com.spotify.docker.client.messages.ContainerExit;
import com.spotify.docker.client.messages.ContainerInfo;
import com.spotify.docker.client.messages.ImageInfo;
import com.spotify.docker.client.messages.Info;
import com.spotify.docker.client.messages.NetworkSettings;
import com.spotify.docker.client.messages.PortBinding;
Expand All @@ -46,6 +48,8 @@
import static org.junit.Assert.assertTrue;
import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

public class HeliosSoloDeploymentTest {
Expand Down Expand Up @@ -155,4 +159,28 @@ public void testConfig() throws Exception {
assertTrue("Could not find helios-solo container creation", foundSolo);

}

@Test
public void testDoesNotPullPresentProbeImage() throws Exception {
when(this.dockerClient.inspectImage(HeliosSoloDeployment.PROBE_IMAGE))
.thenReturn(mock(ImageInfo.class));

HeliosSoloDeployment.builder()
.dockerClient(this.dockerClient)
.build();

verify(this.dockerClient, never()).pull(HeliosSoloDeployment.PROBE_IMAGE);
}

@Test
public void testDoesPullAbsentProbeImage() throws Exception {
when(this.dockerClient.inspectImage(HeliosSoloDeployment.PROBE_IMAGE))
.thenThrow(new ImageNotFoundException(HeliosSoloDeployment.PROBE_IMAGE));

HeliosSoloDeployment.builder()
.dockerClient(this.dockerClient)
.build();

verify(this.dockerClient).pull(HeliosSoloDeployment.PROBE_IMAGE);
}
}

0 comments on commit 08f957c

Please sign in to comment.