Search in sources :

Example 1 with ImagePullManager

use of io.fabric8.maven.docker.service.ImagePullManager 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 registryConfig registry configuration
 *
 * @throws DockerAccessException
 * @throws MojoExecutionException
 */
public void pullImageWithPolicy(String image, ImagePullManager pullManager, RegistryConfig registryConfig, boolean hasImage) 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(hasImage, pullManager.getImagePullPolicy(), image)) {
        return;
    }
    ImageName imageName = new ImageName(image);
    long time = System.currentTimeMillis();
    String actualRegistry = EnvUtil.fistRegistryOf(imageName.getRegistry(), registryConfig.getRegistry());
    docker.pullImage(imageName.getFullName(), createAuthConfig(false, null, actualRegistry, registryConfig), actualRegistry);
    log.info("Pulled %s in %s", imageName.getFullName(), EnvUtil.formatDurationTill(time));
    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)

Example 2 with ImagePullManager

use of io.fabric8.maven.docker.service.ImagePullManager in project docker-maven-plugin by fabric8io.

the class BuildService method autoPullBaseImage.

private void autoPullBaseImage(ImageConfiguration imageConfig, ImagePullManager imagePullManager, BuildContext buildContext) throws DockerAccessException, MojoExecutionException {
    BuildImageConfiguration buildConfig = imageConfig.getBuildConfiguration();
    if (buildConfig.getDockerArchive() != null) {
        // No auto pull needed in archive mode
        return;
    }
    String fromImage;
    if (buildConfig.isDockerFileMode()) {
        fromImage = extractBaseFromDockerfile(buildConfig, buildContext);
    } else {
        fromImage = extractBaseFromConfiguration(buildConfig);
    }
    if (fromImage != null && !DockerAssemblyManager.SCRATCH_IMAGE.equals(fromImage)) {
        registryService.pullImageWithPolicy(fromImage, imagePullManager, buildContext.getRegistryConfig(), queryService.hasImage(fromImage));
    }
}
Also used : BuildImageConfiguration(io.fabric8.maven.docker.config.BuildImageConfiguration)

Example 3 with ImagePullManager

use of io.fabric8.maven.docker.service.ImagePullManager in project docker-maven-plugin by fabric8io.

the class BuildMojo method buildAndTag.

protected void buildAndTag(ServiceHub hub, ImageConfiguration imageConfig) throws MojoExecutionException, DockerAccessException {
    EnvUtil.storeTimestamp(getBuildTimestampFile(), getBuildTimestamp());
    BuildService.BuildContext buildContext = getBuildContext();
    ImagePullManager pullManager = getImagePullManager(determinePullPolicy(imageConfig.getBuildConfiguration()), autoPull);
    BuildService buildService = hub.getBuildService();
    buildService.buildImage(imageConfig, pullManager, buildContext);
    if (!skipTag) {
        buildService.tagImage(imageConfig.getName(), imageConfig);
    }
}
Also used : BuildService(io.fabric8.maven.docker.service.BuildService) ImagePullManager(io.fabric8.maven.docker.service.ImagePullManager)

Aggregations

BuildImageConfiguration (io.fabric8.maven.docker.config.BuildImageConfiguration)1 BuildService (io.fabric8.maven.docker.service.BuildService)1 ImagePullManager (io.fabric8.maven.docker.service.ImagePullManager)1 ImageName (io.fabric8.maven.docker.util.ImageName)1