Search in sources :

Example 61 with BuildImageConfiguration

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

the class DockerAssemblyManager method createDockerFileBuilder.

// visible for testing
@SuppressWarnings("deprecation")
DockerFileBuilder createDockerFileBuilder(BuildImageConfiguration buildConfig, List<AssemblyConfiguration> assemblyConfigs) {
    DockerFileBuilder builder = new DockerFileBuilder().env(buildConfig.getEnv()).labels(buildConfig.getLabels()).expose(buildConfig.getPorts()).shell(buildConfig.getShell()).run(buildConfig.getRunCmds()).volumes(buildConfig.getVolumes()).user(buildConfig.getUser());
    if (buildConfig.getMaintainer() != null) {
        builder.maintainer(buildConfig.getMaintainer());
    }
    if (buildConfig.getWorkdir() != null) {
        builder.workdir(buildConfig.getWorkdir());
    }
    if (assemblyConfigs != null && !assemblyConfigs.isEmpty() && assemblyConfigs.stream().anyMatch(Objects::nonNull)) {
        for (AssemblyConfiguration assemblyConfig : assemblyConfigs) {
            if (assemblyConfig != null) {
                builder.add(assemblyConfig.getName(), "", assemblyConfig.getTargetDir(), assemblyConfig.getUser(), assemblyConfig.exportTargetDir()).basedir(assemblyConfig.getTargetDir()).assemblyUser(assemblyConfig.getUser()).exportTargetDir(assemblyConfig.exportTargetDir());
            }
        }
    } else {
        builder.exportTargetDir(false);
    }
    builder.baseImage(buildConfig.getFrom());
    if (buildConfig.getHealthCheck() != null) {
        builder.healthCheck(buildConfig.getHealthCheck());
    }
    if (buildConfig.getCmd() != null) {
        builder.cmd(buildConfig.getCmd());
    } else if (buildConfig.getCommand() != null) {
        Arguments args = Arguments.Builder.get().withShell(buildConfig.getCommand()).build();
        builder.cmd(args);
    }
    if (buildConfig.getEntryPoint() != null) {
        builder.entryPoint(buildConfig.getEntryPoint());
    }
    if (buildConfig.optimise()) {
        builder.optimise();
    }
    return builder;
}
Also used : AssemblyConfiguration(io.fabric8.maven.docker.config.AssemblyConfiguration) Arguments(io.fabric8.maven.docker.config.Arguments)

Example 62 with BuildImageConfiguration

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

the class JibServiceUtilTest method getSampleImageConfiguration.

private ImageConfiguration getSampleImageConfiguration() {
    Assembly assembly = new Assembly();
    FileItem fileItem = new FileItem();
    fileItem.setSource("${project.basedir}/foo");
    fileItem.setOutputDirectory("/deployments");
    assembly.addFile(fileItem);
    BuildImageConfiguration bc = new BuildImageConfiguration.Builder().from("quay.io/test/testimage:testtag").assembly(new AssemblyConfiguration.Builder().assemblyDef(assembly).build()).entryPoint(new Arguments.Builder().withParam("java").withParam("-jar").withParam("foo.jar").build()).labels(Collections.singletonMap("foo", "bar")).user("root").workdir("/home/foo").ports(Collections.singletonList("8080")).volumes(Collections.singletonList("/mnt/volume1")).build();
    return new ImageConfiguration.Builder().name("test/test-project").buildConfig(bc).build();
}
Also used : FileItem(org.apache.maven.plugins.assembly.model.FileItem) BuildImageConfiguration(io.fabric8.maven.docker.config.BuildImageConfiguration) ImageConfiguration(io.fabric8.maven.docker.config.ImageConfiguration) JibServiceUtil.containerFromImageConfiguration(io.fabric8.maven.docker.util.JibServiceUtil.containerFromImageConfiguration) JibContainerBuilder(com.google.cloud.tools.jib.api.JibContainerBuilder) Arguments(io.fabric8.maven.docker.config.Arguments) Assembly(org.apache.maven.plugins.assembly.model.Assembly) BuildImageConfiguration(io.fabric8.maven.docker.config.BuildImageConfiguration)

Example 63 with BuildImageConfiguration

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

the class JibServiceUtil method jibPush.

/**
 * Push Image to registry using JIB
 *
 * @param imageConfiguration ImageConfiguration
 * @param pushCredentials    push credentials
 * @param tarArchive         tar archive built during build goal
 * @param log                Logger
 */
public static void jibPush(ImageConfiguration imageConfiguration, Credential pushCredentials, File tarArchive, Logger log) {
    BuildImageConfiguration buildImageConfiguration = imageConfiguration.getBuildConfiguration();
    String imageName = getFullImageName(imageConfiguration, null);
    try {
        for (String tag : getAllImageTags(buildImageConfiguration.getTags(), imageName)) {
            String imageNameWithTag = getFullImageName(imageConfiguration, tag);
            log.info("Pushing image: %s", imageNameWithTag);
            pushImage(TarImage.at(tarArchive.toPath()), imageNameWithTag, pushCredentials, log);
        }
    } catch (IllegalStateException e) {
        log.error("Exception occurred while pushing the image: %s", imageConfiguration.getName());
        throw new IllegalStateException(e.getMessage(), e);
    } catch (InterruptedException e) {
        log.error("Thread interrupted", e);
        Thread.currentThread().interrupt();
    }
}
Also used : BuildImageConfiguration(io.fabric8.maven.docker.config.BuildImageConfiguration)

Example 64 with BuildImageConfiguration

use of io.fabric8.maven.docker.config.BuildImageConfiguration 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 65 with BuildImageConfiguration

use of io.fabric8.maven.docker.config.BuildImageConfiguration 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)68 Test (org.junit.Test)40 ImageConfiguration (io.fabric8.maven.docker.config.ImageConfiguration)34 File (java.io.File)19 Verifications (mockit.Verifications)15 RunImageConfiguration (io.fabric8.maven.docker.config.RunImageConfiguration)12 ArrayList (java.util.ArrayList)11 AssemblyConfiguration (io.fabric8.maven.docker.config.AssemblyConfiguration)10 AbstractConfigHandlerTest (io.fabric8.maven.docker.config.handler.AbstractConfigHandlerTest)10 Expectations (mockit.Expectations)9 MojoParameters (io.fabric8.maven.docker.util.MojoParameters)8 Properties (java.util.Properties)7 Before (org.junit.Before)7 VolumeConfig (io.fabric8.maven.core.config.VolumeConfig)6 ArchivedFileSet (org.codehaus.plexus.archiver.ArchivedFileSet)6 Assembly (org.apache.maven.plugins.assembly.model.Assembly)5 Arguments (io.fabric8.maven.docker.config.Arguments)4 CleanupMode (io.fabric8.maven.docker.config.CleanupMode)4 FileSet (org.codehaus.plexus.archiver.FileSet)4 ProcessorConfig (io.fabric8.maven.core.config.ProcessorConfig)3