Skip to content

Commit

Permalink
CHE-1037: fix pulling of docker images (#1106)
Browse files Browse the repository at this point in the history
Signed-off-by: Alexander Garagatyi <agaragatyi@codenvy.com>
  • Loading branch information
Alexander Garagatyi committed Apr 21, 2016
1 parent fd8c5f8 commit 8fc806c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
*******************************************************************************/
package org.eclipse.che.plugin.docker.machine.local.interceptor;

import com.google.common.base.MoreObjects;

import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;
import org.eclipse.che.api.core.util.LineConsumer;
Expand All @@ -30,7 +32,7 @@
*
* @author Alexander Garagatyi
*
* @see org.eclipse.che.plugin.docker.machine.DockerInstanceProvider#buildImage(Dockerfile, LineConsumer, String, boolean)
* @see org.eclipse.che.plugin.docker.machine.DockerInstanceProvider#buildImage(Dockerfile, LineConsumer, String, boolean, long, long)
*/
public class EnableOfflineDockerMachineBuildInterceptor implements MethodInterceptor {
private static final Logger LOG = LoggerFactory.getLogger(EnableOfflineDockerMachineBuildInterceptor.class);
Expand Down Expand Up @@ -64,7 +66,7 @@ private void pullImage(String image, final LineConsumer creationLogsOutput)
DockerImageIdentifier imageIdentifier = DockerImageIdentifierParser.parse(image);
final ProgressLineFormatterImpl progressLineFormatter = new ProgressLineFormatterImpl();
dockerConnector.pull(imageIdentifier.getRepository(),
imageIdentifier.getTag(),
MoreObjects.firstNonNull(imageIdentifier.getTag(), "latest"),
imageIdentifier.getRegistry(),
currentProgressStatus -> {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public class EnableOfflineDockerMachineBuildInterceptorTest {

@Test
public void shouldProceedInterceptedMethodIfForcePullIsDisabled() throws Throwable {
final Object[] arguments = {dockerfile, lineConsumer, "string", Boolean.FALSE};
final Object[] arguments = {dockerfile, lineConsumer, "string", Boolean.FALSE, 0L, 0L};
when(methodInvocation.getArguments()).thenReturn(arguments);


Expand All @@ -69,7 +69,7 @@ public void shouldProceedInterceptedMethodIfForcePullIsDisabled() throws Throwab

@Test
public void shouldPullDockerImageIfForcePullIsEnabled() throws Throwable {
final Object[] arguments = {dockerfile, lineConsumer, "string", Boolean.TRUE};
final Object[] arguments = {dockerfile, lineConsumer, "string", Boolean.TRUE, 0L, 0L};
when(methodInvocation.getArguments()).thenReturn(arguments);
when(dockerfile.getImages()).thenReturn(Collections.singletonList(dockerImage));
final String tag = "latest";
Expand All @@ -88,7 +88,7 @@ public void shouldPullDockerImageIfForcePullIsEnabled() throws Throwable {

@Test(dataProvider = "throwableProvider")
public void shouldIgnoreExceptionsOnDockerImagePullingIfForcePullIsEnabled(Throwable throwable) throws Throwable {
final Object[] arguments = {dockerfile, lineConsumer, "string", Boolean.TRUE};
final Object[] arguments = {dockerfile, lineConsumer, "string", Boolean.TRUE, 0L, 0L};
when(methodInvocation.getArguments()).thenReturn(arguments);
when(dockerfile.getImages()).thenReturn(Collections.singletonList(dockerImage));
final String tag = "latest";
Expand All @@ -104,6 +104,24 @@ public void shouldIgnoreExceptionsOnDockerImagePullingIfForcePullIsEnabled(Throw
verify(methodInvocation).proceed();
}

@Test
public void shouldPullLatestIfNoTagFoundInDockerfile() throws Throwable {
final Object[] arguments = {dockerfile, lineConsumer, "string", Boolean.TRUE, 0L, 0L};
when(methodInvocation.getArguments()).thenReturn(arguments);
when(dockerfile.getImages()).thenReturn(Collections.singletonList(dockerImage));
final String repo = "my_repo/my_image";
when(dockerImage.getFrom()).thenReturn(repo);


interceptor.invoke(methodInvocation);


assertFalse((Boolean)arguments[3]);
verify(methodInvocation).proceed();
verify(dockerfile).getImages();
verify(dockerConnector).pull(eq(repo), eq("latest"), eq(null), any(ProgressMonitor.class));
}

@DataProvider(name = "throwableProvider")
public static Object[][] throwableProvider() {
return new Object[][] {{new IOException("test_exception")},
Expand Down

0 comments on commit 8fc806c

Please sign in to comment.