diff --git a/helios-testing/src/main/java/com/spotify/helios/testing/HeliosSoloDeployment.java b/helios-testing/src/main/java/com/spotify/helios/testing/HeliosSoloDeployment.java index 7ec54abf4..df8269a5f 100644 --- a/helios-testing/src/main/java/com/spotify/helios/testing/HeliosSoloDeployment.java +++ b/helios-testing/src/main/java/com/spotify/helios/testing/HeliosSoloDeployment.java @@ -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; @@ -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); @@ -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 probeCommand(final String probeName) { final List cmd = new ArrayList<>(ImmutableList.of("curl", "-f")); switch (containerDockerHost.uri().getScheme()) { diff --git a/helios-testing/src/test/java/com/spotify/helios/testing/HeliosSoloDeploymentTest.java b/helios-testing/src/test/java/com/spotify/helios/testing/HeliosSoloDeploymentTest.java index 5ad6ad8aa..6d2d51f5a 100644 --- a/helios-testing/src/test/java/com/spotify/helios/testing/HeliosSoloDeploymentTest.java +++ b/helios-testing/src/test/java/com/spotify/helios/testing/HeliosSoloDeploymentTest.java @@ -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; @@ -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 { @@ -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); + } }