Search in sources :

Example 1 with CreateImageOptions

use of io.fabric8.maven.docker.access.CreateImageOptions in project docker-maven-plugin by fabric8io.

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 which is required to be pulled
 * @param pullManager image pull manager
 * @param registryConfig registry configuration
 * @param buildImageConfiguration image build configuration
 * @throws DockerAccessException in case of error in contacting docker daemon
 * @throws MojoExecutionException in case of any other misc failure
 */
public void pullImageWithPolicy(String image, ImagePullManager pullManager, RegistryConfig registryConfig, BuildImageConfiguration buildImageConfiguration) throws DockerAccessException, MojoExecutionException {
    // 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(buildImageConfiguration != null ? buildImageConfiguration.getCreateImageOptions() : Collections.emptyMap()).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(io.fabric8.maven.docker.util.ImageName) CreateImageOptions(io.fabric8.maven.docker.access.CreateImageOptions)

Example 2 with CreateImageOptions

use of io.fabric8.maven.docker.access.CreateImageOptions in project docker-maven-plugin by fabric8io.

the class RegistryServiceTest method pullImageWithPolicy_pullPolicyAlwaysAndBuildConfiguration_shouldPull.

@Test
public void pullImageWithPolicy_pullPolicyAlwaysAndBuildConfiguration_shouldPull() throws DockerAccessException {
    BuildImageConfiguration buildImageConfiguration = new BuildImageConfiguration.Builder().createImageOptions(Collections.singletonMap("platform", "linux/amd64")).build();
    imageConfiguration = new ImageConfiguration.Builder().name("myregistry.com/user/app:1.0.1").buildConfig(buildImageConfiguration).build();
    givenAnImage("myregistry.com/user/test:1.0.1");
    givenHasImage(false);
    givenPreviousPulled(false);
    givenRegistry("anotherRegistry.com");
    givenImagePullPolicy(ImagePullPolicy.Always);
    whenAutoPullImage();
    new Verifications() {

        {
            String pulledImage;
            CreateImageOptions createImageOptions;
            docker.pullImage(pulledImage = withCapture(), (AuthConfig) any, anyString, createImageOptions = withCapture());
            times = 1;
            assertEquals("myregistry.com/user/test:1.0.1", pulledImage);
            assertNotNull(createImageOptions);
            assertEquals(3, createImageOptions.getOptions().size());
            assertEquals("linux/amd64", createImageOptions.getOptions().get("platform"));
            assertEquals("1.0.1", createImageOptions.getOptions().get("tag"));
            assertEquals("myregistry.com/user/test", createImageOptions.getOptions().get("fromImage"));
        }
    };
}
Also used : CreateImageOptions(io.fabric8.maven.docker.access.CreateImageOptions) Verifications(mockit.Verifications) BuildImageConfiguration(io.fabric8.maven.docker.config.BuildImageConfiguration) Test(org.junit.Test)

Example 3 with CreateImageOptions

use of io.fabric8.maven.docker.access.CreateImageOptions in project docker-maven-plugin by fabric8io.

the class UrlBuilderTest method pullImage.

@Test
public void pullImage() throws URISyntaxException {
    UrlBuilder builder = new UrlBuilder("", "1.0");
    assertEquals(new URI("/1.0/images/create?fromImage=reg%2Ft1&tag=latest"), new URI(builder.pullImage(new CreateImageOptions().fromImage("reg/t1").tag("latest"))));
    assertEquals(new URI("/1.0/images/create?fromImage=reg%2Ft1&tag=latest"), new URI(builder.pullImage(new CreateImageOptions().fromImage("reg/t1").tag("latest"))));
}
Also used : CreateImageOptions(io.fabric8.maven.docker.access.CreateImageOptions) UrlBuilder(io.fabric8.maven.docker.access.UrlBuilder) Test(org.junit.Test)

Aggregations

CreateImageOptions (io.fabric8.maven.docker.access.CreateImageOptions)3 Test (org.junit.Test)2 UrlBuilder (io.fabric8.maven.docker.access.UrlBuilder)1 BuildImageConfiguration (io.fabric8.maven.docker.config.BuildImageConfiguration)1 ImageName (io.fabric8.maven.docker.util.ImageName)1 Verifications (mockit.Verifications)1