Search in sources :

Example 6 with CleanupMode

use of io.fabric8.maven.docker.config.CleanupMode in project docker-maven-plugin by fabric8io.

the class BuildService method tagImage.

public void tagImage(String imageName, String tag, String repo, CleanupMode cleanupMode) throws DockerAccessException {
    if (tag != null) {
        String fullImageName = new ImageName(imageName, tag).getNameWithOptionalRepository(repo);
        String oldImageId = null;
        if (cleanupMode.isRemove()) {
            oldImageId = queryService.getImageId(fullImageName);
        }
        docker.tag(imageName, fullImageName, true);
        log.info("Tagging image %s successful!", fullImageName);
        String newImageId = queryService.getImageId(fullImageName);
        removeDanglingImage(fullImageName, oldImageId, newImageId, cleanupMode, false);
    }
}
Also used : ImageName(io.fabric8.maven.docker.util.ImageName)

Example 7 with CleanupMode

use of io.fabric8.maven.docker.config.CleanupMode 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();
    CleanupMode cleanupMode = buildConfig.cleanupMode();
    if (buildConfig.getDockerArchive() != null) {
        // No auto pull needed in archive mode
        return;
    }
    List<String> fromImages;
    if (buildConfig.isDockerFileMode()) {
        fromImages = extractBaseFromDockerfile(buildConfig, buildContext);
    } else {
        fromImages = new LinkedList<>();
        String baseImage = extractBaseFromConfiguration(buildConfig);
        if (baseImage != null) {
            fromImages.add(extractBaseFromConfiguration(buildConfig));
        }
    }
    for (String fromImage : fromImages) {
        if (fromImage != null && !DockerAssemblyManager.SCRATCH_IMAGE.equals(fromImage)) {
            String oldImageId = null;
            if (cleanupMode.isRemove()) {
                oldImageId = queryService.getImageId(fromImage);
            }
            registryService.pullImageWithPolicy(fromImage, imagePullManager, buildContext.getRegistryConfig(), buildConfig);
            String newImageId = queryService.getImageId(fromImage);
            removeDanglingImage(fromImage, oldImageId, newImageId, cleanupMode, false);
        }
    }
}
Also used : CleanupMode(io.fabric8.maven.docker.config.CleanupMode) BuildImageConfiguration(io.fabric8.maven.docker.config.BuildImageConfiguration)

Example 8 with CleanupMode

use of io.fabric8.maven.docker.config.CleanupMode in project docker-maven-plugin by fabric8io.

the class BuildService method autoPullCacheFromImage.

private void autoPullCacheFromImage(ImageConfiguration imageConfig, ImagePullManager imagePullManager, BuildContext buildContext) throws DockerAccessException, MojoExecutionException {
    if (imageConfig.getBuildConfiguration().getCacheFrom() == null) {
        return;
    }
    BuildImageConfiguration buildConfig = imageConfig.getBuildConfiguration();
    CleanupMode cleanupMode = buildConfig.cleanupMode();
    for (String cacheFromImage : buildConfig.getCacheFrom()) {
        String oldImageId = null;
        if (cleanupMode.isRemove()) {
            oldImageId = queryService.getImageId(cacheFromImage);
        }
        try {
            registryService.pullImageWithPolicy(cacheFromImage, imagePullManager, buildContext.getRegistryConfig(), buildConfig);
        } catch (DockerAccessException e) {
            log.warn("Could not pull cacheFrom image: '%s'. Reason: %s", cacheFromImage, e.getMessage());
        }
        String newImageId = queryService.getImageId(cacheFromImage);
        removeDanglingImage(cacheFromImage, oldImageId, newImageId, cleanupMode, false);
    }
}
Also used : DockerAccessException(io.fabric8.maven.docker.access.DockerAccessException) CleanupMode(io.fabric8.maven.docker.config.CleanupMode) BuildImageConfiguration(io.fabric8.maven.docker.config.BuildImageConfiguration)

Aggregations

BuildImageConfiguration (io.fabric8.maven.docker.config.BuildImageConfiguration)7 CleanupMode (io.fabric8.maven.docker.config.CleanupMode)5 ImageConfiguration (io.fabric8.maven.docker.config.ImageConfiguration)3 RunImageConfiguration (io.fabric8.maven.docker.config.RunImageConfiguration)3 AbstractConfigHandlerTest (io.fabric8.maven.docker.config.handler.AbstractConfigHandlerTest)3 Test (org.junit.Test)3 BuildOptions (io.fabric8.maven.docker.access.BuildOptions)2 DockerAccessException (io.fabric8.maven.docker.access.DockerAccessException)2 File (java.io.File)2 ImageName (io.fabric8.maven.docker.util.ImageName)1