Search in sources :

Example 26 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();
    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 27 with BuildImageConfiguration

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

the class DockerAssemblyManagerTest method testNoAssembly.

@Test
public void testNoAssembly() {
    BuildImageConfiguration buildConfig = new BuildImageConfiguration();
    AssemblyConfiguration assemblyConfig = buildConfig.getAssemblyConfiguration();
    DockerFileBuilder builder = assemblyManager.createDockerFileBuilder(buildConfig, assemblyConfig);
    String content = builder.content();
    assertFalse(content.contains("COPY"));
    assertFalse(content.contains("VOLUME"));
}
Also used : AssemblyConfiguration(io.fabric8.maven.docker.config.AssemblyConfiguration) BuildImageConfiguration(io.fabric8.maven.docker.config.BuildImageConfiguration) Test(org.junit.Test)

Example 28 with BuildImageConfiguration

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

the class DockerAssemblyManagerTest method testCopyValidVerifyGivenDockerfile.

@Test
public void testCopyValidVerifyGivenDockerfile(@Injectable final Logger logger) throws IOException {
    BuildImageConfiguration buildConfig = createBuildConfig();
    assemblyManager.verifyGivenDockerfile(new File(getClass().getResource("/docker/Dockerfile_assembly_verify_copy_valid.test").getPath()), buildConfig, createInterpolator(buildConfig), logger);
    new Verifications() {

        {
            logger.warn(anyString, (Object[]) any);
            times = 0;
        }
    };
}
Also used : Verifications(mockit.Verifications) File(java.io.File) BuildImageConfiguration(io.fabric8.maven.docker.config.BuildImageConfiguration) Test(org.junit.Test)

Example 29 with BuildImageConfiguration

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

the class DockerAssemblyManagerTest method testCopyInvalidVerifyGivenDockerfile.

@Test
public void testCopyInvalidVerifyGivenDockerfile(@Injectable final Logger logger) throws IOException {
    BuildImageConfiguration buildConfig = createBuildConfig();
    assemblyManager.verifyGivenDockerfile(new File(getClass().getResource("/docker/Dockerfile_assembly_verify_copy_invalid.test").getPath()), buildConfig, createInterpolator(buildConfig), logger);
    new Verifications() {

        {
            logger.warn(anyString, (Object[]) any);
            times = 1;
        }
    };
}
Also used : Verifications(mockit.Verifications) File(java.io.File) BuildImageConfiguration(io.fabric8.maven.docker.config.BuildImageConfiguration) Test(org.junit.Test)

Example 30 with BuildImageConfiguration

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

the class SourceMojo method executeInternal.

@Override
protected void executeInternal(ServiceHub hub) throws DockerAccessException, MojoExecutionException {
    MojoParameters params = createMojoParameters();
    List<ImageConfiguration> imageConfigs = new ArrayList<>();
    for (ImageConfiguration imageConfig : getResolvedImages()) {
        BuildImageConfiguration buildConfig = imageConfig.getBuildConfiguration();
        if (buildConfig != null) {
            if (buildConfig.skip()) {
                log.info("%s: Skipped creating source", imageConfig.getDescription());
            } else {
                imageConfigs.add(imageConfig);
            }
        }
    }
    if (sourceMode == BuildImageSelectMode.first && imageConfigs.size() > 0) {
        ImageConfiguration imageConfig = imageConfigs.get(0);
        File dockerTar = hub.getArchiveService().createDockerBuildArchive(imageConfig, params);
        projectHelper.attachArtifact(project, getArchiveType(imageConfig), getClassifier(null), dockerTar);
    } else {
        for (ImageConfiguration imageConfig : imageConfigs) {
            File dockerTar = hub.getArchiveService().createDockerBuildArchive(imageConfig, params);
            String alias = imageConfig.getAlias();
            if (alias == null) {
                throw new IllegalArgumentException("Image " + imageConfig.getDescription() + " must have an 'alias' configured to be " + "used as a classifier for attaching a docker build tar as source to the maven build");
            }
            projectHelper.attachArtifact(project, getArchiveType(imageConfig), getClassifier(alias), dockerTar);
        }
    }
}
Also used : MojoParameters(io.fabric8.maven.docker.util.MojoParameters) BuildImageConfiguration(io.fabric8.maven.docker.config.BuildImageConfiguration) ImageConfiguration(io.fabric8.maven.docker.config.ImageConfiguration) ArrayList(java.util.ArrayList) File(java.io.File) BuildImageConfiguration(io.fabric8.maven.docker.config.BuildImageConfiguration)

Aggregations

BuildImageConfiguration (io.fabric8.maven.docker.config.BuildImageConfiguration)36 Test (org.junit.Test)16 ImageConfiguration (io.fabric8.maven.docker.config.ImageConfiguration)15 Before (org.junit.Before)7 VolumeConfig (io.fabric8.maven.core.config.VolumeConfig)6 File (java.io.File)6 AssemblyConfiguration (io.fabric8.maven.docker.config.AssemblyConfiguration)5 AbstractConfigHandlerTest (io.fabric8.maven.docker.config.handler.AbstractConfigHandlerTest)5 Expectations (mockit.Expectations)5 Properties (java.util.Properties)4 ProcessorConfig (io.fabric8.maven.core.config.ProcessorConfig)3 ArrayList (java.util.ArrayList)3 TreeMap (java.util.TreeMap)3 Verifications (mockit.Verifications)3 ContainerPort (io.fabric8.kubernetes.api.model.ContainerPort)1 KubernetesList (io.fabric8.kubernetes.api.model.KubernetesList)1 KubernetesListBuilder (io.fabric8.kubernetes.api.model.KubernetesListBuilder)1 AuthConfig (io.fabric8.maven.docker.access.AuthConfig)1 BuildOptions (io.fabric8.maven.docker.access.BuildOptions)1 DockerAccessException (io.fabric8.maven.docker.access.DockerAccessException)1