use of org.eclipse.jkube.kit.build.service.docker.access.CreateImageOptions in project jkube by eclipse.
the class RegistryService method pullImageWithPolicy.
/**
* Check an image, and, if <code>autoPull</code> is set to true, fetch it. Otherwise if the image
* is not existent, throw an error
*
* @param image image
* @param pullManager image pull manager
* @param registryConfig registry configuration
* @param buildConfiguration build configuration
* @throws IOException exception
*/
public void pullImageWithPolicy(String image, ImagePullManager pullManager, RegistryConfig registryConfig, BuildConfiguration buildConfiguration) throws IOException {
// Already pulled, so we don't need to take care
if (pullManager.hasAlreadyPulled(image)) {
return;
}
// Check if a pull is required
if (!imageRequiresPull(queryService.hasImage(image), pullManager.getImagePullPolicy(), image)) {
return;
}
final ImageName imageName = new ImageName(image);
final long pullStartTime = System.currentTimeMillis();
final String actualRegistry = EnvUtil.firstRegistryOf(imageName.getRegistry(), registryConfig.getRegistry());
final CreateImageOptions createImageOptions = new CreateImageOptions(buildConfiguration.getCreateImageOptions()).fromImage(imageName.getNameWithoutTag(actualRegistry)).tag(imageName.getDigest() != null ? imageName.getDigest() : imageName.getTag());
docker.pullImage(imageName.getFullName(), createAuthConfig(false, null, actualRegistry, registryConfig), actualRegistry, createImageOptions);
log.info("Pulled %s in %s", imageName.getFullName(), EnvUtil.formatDurationTill(pullStartTime));
pullManager.pulled(image);
if (actualRegistry != null && !imageName.hasRegistry()) {
// If coming from a registry which was not contained in the original name, add a tag from the
// full name with the registry to the short name with no-registry.
docker.tag(imageName.getFullName(actualRegistry), image, false);
}
}
use of org.eclipse.jkube.kit.build.service.docker.access.CreateImageOptions in project jkube by eclipse.
the class DockerAccessWithHcClientMockitoTest method pullImageThrowsException.
@Test
public void pullImageThrowsException() throws Exception {
// Given
when(mockDelegate.post(eq("tcp://1.2.3.4:2375/v1.18/images/create"), isNull(), any(Map.class), any(HcChunkedResponseHandlerWrapper.class), eq(200))).thenThrow(new IOException("Problem with images/create"));
// When
final DockerAccessException result = assertThrows(DockerAccessException.class, () -> client.pullImage("name", null, "registry", new CreateImageOptions()));
// Then
assertThat(result).hasMessageStartingWith("Unable to pull 'name' from registry 'registry'").hasMessageEndingWith("Problem with images/create");
}
use of org.eclipse.jkube.kit.build.service.docker.access.CreateImageOptions in project jkube by eclipse.
the class DockerAccessWithHcClientMockitoTest method pullImage.
@Test
public void pullImage() throws Exception {
// When
client.pullImage("name", null, "registry", new CreateImageOptions());
// Then
verify(mockDelegate, times(1)).post(eq("tcp://1.2.3.4:2375/v1.18/images/create"), isNull(), any(Map.class), any(HcChunkedResponseHandlerWrapper.class), eq(200));
}
use of org.eclipse.jkube.kit.build.service.docker.access.CreateImageOptions in project jkube by eclipse.
the class RegistryServiceTest method pullImageWithPolicy_pullPolicyAlwaysAndBuildConfiguration_shouldPull.
@Test
public void pullImageWithPolicy_pullPolicyAlwaysAndBuildConfiguration_shouldPull() throws Exception {
// Given
final BuildConfiguration bc = BuildConfiguration.builder().createImageOptions(Collections.singletonMap("platform", "linux/amd64")).build();
final ArgumentCaptor<CreateImageOptions> createImageOptionsCaptor = ArgumentCaptor.forClass(CreateImageOptions.class);
// When
registryService.pullImageWithPolicy("quay.io/organization/image:version", ImagePullManager.createImagePullManager("Always", "", new Properties()), RegistryConfig.builder().settings(Collections.emptyList()).build(), bc);
// Then
verify(dockerAccess, times(1)).pullImage(eq("quay.io/organization/image:version"), any(), eq("quay.io"), createImageOptionsCaptor.capture());
assertThat(createImageOptionsCaptor.getValue().getOptions()).containsExactlyInAnyOrderEntriesOf(new CreateImageOptions().fromImage("quay.io/organization/image").tag("version").platform("linux/amd64").getOptions());
}
use of org.eclipse.jkube.kit.build.service.docker.access.CreateImageOptions in project jkube by eclipse.
the class RegistryServiceTest method pullImageWithPolicy_pullPolicyAlways_shouldPull.
@Test
public void pullImageWithPolicy_pullPolicyAlways_shouldPull() throws Exception {
// Given
final ArgumentCaptor<CreateImageOptions> createImageOptionsCaptor = ArgumentCaptor.forClass(CreateImageOptions.class);
// When
registryService.pullImageWithPolicy("quay.io/organization/image:version", ImagePullManager.createImagePullManager("Always", "", new Properties()), RegistryConfig.builder().settings(Collections.emptyList()).build(), new BuildConfiguration());
// Then
verify(dockerAccess, times(1)).pullImage(eq("quay.io/organization/image:version"), any(), eq("quay.io"), createImageOptionsCaptor.capture());
assertThat(createImageOptionsCaptor.getValue().getOptions()).containsExactlyInAnyOrderEntriesOf(new CreateImageOptions().fromImage("quay.io/organization/image").tag("version").getOptions());
}
Aggregations