Search in sources :

Example 1 with CreateImageOptions

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);
    }
}
Also used : ImageName(org.eclipse.jkube.kit.config.image.ImageName) CreateImageOptions(org.eclipse.jkube.kit.build.service.docker.access.CreateImageOptions)

Example 2 with CreateImageOptions

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");
}
Also used : CreateImageOptions(org.eclipse.jkube.kit.build.service.docker.access.CreateImageOptions) DockerAccessException(org.eclipse.jkube.kit.build.service.docker.access.DockerAccessException) IOException(java.io.IOException) Map(java.util.Map) Test(org.junit.Test)

Example 3 with CreateImageOptions

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));
}
Also used : CreateImageOptions(org.eclipse.jkube.kit.build.service.docker.access.CreateImageOptions) Map(java.util.Map) Test(org.junit.Test)

Example 4 with CreateImageOptions

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());
}
Also used : BuildConfiguration(org.eclipse.jkube.kit.config.image.build.BuildConfiguration) CreateImageOptions(org.eclipse.jkube.kit.build.service.docker.access.CreateImageOptions) Properties(java.util.Properties) Test(org.junit.Test)

Example 5 with CreateImageOptions

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());
}
Also used : BuildConfiguration(org.eclipse.jkube.kit.config.image.build.BuildConfiguration) CreateImageOptions(org.eclipse.jkube.kit.build.service.docker.access.CreateImageOptions) Properties(java.util.Properties) Test(org.junit.Test)

Aggregations

CreateImageOptions (org.eclipse.jkube.kit.build.service.docker.access.CreateImageOptions)5 Test (org.junit.Test)4 Map (java.util.Map)2 Properties (java.util.Properties)2 BuildConfiguration (org.eclipse.jkube.kit.config.image.build.BuildConfiguration)2 IOException (java.io.IOException)1 DockerAccessException (org.eclipse.jkube.kit.build.service.docker.access.DockerAccessException)1 ImageName (org.eclipse.jkube.kit.config.image.ImageName)1