Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CHE-1037: fix pulling of docker images #1106

Merged
merged 2 commits into from
Apr 21, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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