Search in sources :

Example 46 with BuildImageConfiguration

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

the class ContainerHandlerTest method getContainersWithAliasTest.

@Test
public void getContainersWithAliasTest() {
    project.setArtifactId("test-artifact");
    project.setGroupId("test-group");
    ports.add("8080");
    ports.add("9090");
    tags.add("latest");
    tags.add("test");
    ContainerHandler handler = new ContainerHandler(project, envVarHandler, probeHandler);
    // container name with alias
    BuildImageConfiguration buildImageConfiguration = new BuildImageConfiguration.Builder().ports(ports).from("fabric8/maven:latest").cleanup("try").tags(tags).compression("gzip").build();
    ImageConfiguration imageConfiguration = new ImageConfiguration.Builder().name("test").alias("test-app").buildConfig(buildImageConfiguration).registry("docker.io").build();
    images.clear();
    images.add(imageConfiguration);
    containers = handler.getContainers(config, images);
    assertNotNull(containers);
    assertEquals("test-app", containers.get(0).getName());
    assertEquals("docker.io/test", containers.get(0).getImage());
    assertEquals("IfNotPresent", containers.get(0).getImagePullPolicy());
}
Also used : BuildImageConfiguration(io.fabric8.maven.docker.config.BuildImageConfiguration) ImageConfiguration(io.fabric8.maven.docker.config.ImageConfiguration) BuildImageConfiguration(io.fabric8.maven.docker.config.BuildImageConfiguration) Test(org.junit.Test)

Example 47 with BuildImageConfiguration

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

the class DeploymentHandlerTest method before.

@Before
public void before() {
    // volume config with name and multiple mount
    mounts.add("/path/system");
    mounts.add("/path/sys");
    ports.add("8080");
    ports.add("9090");
    tags.add("latest");
    tags.add("test");
    VolumeConfig volumeConfig1 = new VolumeConfig.Builder().name("test").mounts(mounts).type("hostPath").path("/test/path").build();
    volumes1.add(volumeConfig1);
    // container name with alias
    BuildImageConfiguration buildImageConfiguration = new BuildImageConfiguration.Builder().ports(ports).from("fabric8/maven:latest").cleanup("try").tags(tags).compression("gzip").build();
    ImageConfiguration imageConfiguration = new ImageConfiguration.Builder().name("test").alias("test-app").buildConfig(buildImageConfiguration).registry("docker.io").build();
    images.add(imageConfiguration);
}
Also used : BuildImageConfiguration(io.fabric8.maven.docker.config.BuildImageConfiguration) ImageConfiguration(io.fabric8.maven.docker.config.ImageConfiguration) VolumeConfig(io.fabric8.maven.core.config.VolumeConfig) BuildImageConfiguration(io.fabric8.maven.docker.config.BuildImageConfiguration) Before(org.junit.Before)

Example 48 with BuildImageConfiguration

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

the class ContainerHandler method getContainerPorts.

private List<ContainerPort> getContainerPorts(ImageConfiguration imageConfig) {
    BuildImageConfiguration buildConfig = imageConfig.getBuildConfiguration();
    List<String> ports = buildConfig.getPorts();
    if (!ports.isEmpty()) {
        List<ContainerPort> ret = new ArrayList<>();
        PortMapping portMapping = new PortMapping(ports, project.getProperties());
        JSONArray portSpecs = portMapping.toJson();
        for (int i = 0; i < portSpecs.length(); i++) {
            JSONObject portSpec = portSpecs.getJSONObject(i);
            ret.add(extractContainerPort(portSpec));
        }
        return ret;
    } else {
        return null;
    }
}
Also used : JSONObject(org.json.JSONObject) ContainerPort(io.fabric8.kubernetes.api.model.ContainerPort) ArrayList(java.util.ArrayList) JSONArray(org.json.JSONArray) PortMapping(io.fabric8.maven.docker.access.PortMapping) BuildImageConfiguration(io.fabric8.maven.docker.config.BuildImageConfiguration)

Example 49 with BuildImageConfiguration

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

the class PrometheusEnricherTest method testDetectPrometheusPort.

@Test
public void testDetectPrometheusPort() throws Exception {
    final ProcessorConfig config = new ProcessorConfig(null, null, Collections.singletonMap(PrometheusEnricher.ENRICHER_NAME, new TreeMap()));
    final BuildImageConfiguration imageConfig = new BuildImageConfiguration.Builder().ports(Arrays.asList(PrometheusEnricher.PROMETHEUS_PORT)).build();
    // Setup mock behaviour
    new Expectations() {

        {
            context.getConfig();
            result = config;
            imageConfiguration.getBuildConfiguration();
            result = imageConfig;
            context.getImages();
            result = Arrays.asList(imageConfiguration);
        }
    };
    PrometheusEnricher enricher = new PrometheusEnricher(context);
    Map<String, String> annotations = enricher.getAnnotations(Kind.SERVICE);
    assertEquals(2, annotations.size());
    assertEquals("9779", annotations.get(Annotations.Management.PROMETHEUS_PORT));
    assertEquals("true", annotations.get(Annotations.Management.PROMETHEUS_SCRAPE));
}
Also used : Expectations(mockit.Expectations) TreeMap(java.util.TreeMap) ProcessorConfig(io.fabric8.maven.core.config.ProcessorConfig) BuildImageConfiguration(io.fabric8.maven.docker.config.BuildImageConfiguration) Test(org.junit.Test)

Example 50 with BuildImageConfiguration

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

the class DockerAssemblyManagerTest method testArchiveCreationDockerfileWithArchiveAssembly.

@Test
public void testArchiveCreationDockerfileWithArchiveAssembly(@Injectable final TarArchiver tarArchiver, @Injectable final Logger logger) throws MojoExecutionException, NoSuchArchiverException {
    MojoParameters mojoParams = mockMojoParams(mockMavenProject());
    BuildImageConfiguration buildImageConfiguration = new BuildImageConfiguration.Builder().dockerFile(DockerAssemblyManagerTest.class.getResource("/docker/Dockerfile.test").getPath()).assembly(new AssemblyConfiguration.Builder().mode(AssemblyMode.tar.name()).assemblyDef(new Assembly()).build()).build();
    buildImageConfiguration.initAndValidate(logger);
    File tarArchive = assemblyManager.createDockerTarArchive("test_image", mojoParams, buildImageConfiguration, logger, null);
    assertNotNull(tarArchive);
    new Verifications() {

        {
            archiverManager.getArchiver("tar");
            times = 1;
            List<FileSet> fileSets = new ArrayList<>();
            tarArchiver.addFileSet(withCapture(fileSets));
            assertEquals(1, fileSets.size());
            assertArrayEquals(new String[] { "target/**", "Dockerfile.test" }, fileSets.get(0).getExcludes());
            assertNull(fileSets.get(0).getIncludes());
            tarArchiver.addFile(new File("target/test_image/build/Dockerfile.test"), "Dockerfile.test");
            List<ArchivedFileSet> archivedFileSets = new ArrayList<>();
            tarArchiver.addArchivedFileSet(withCapture(archivedFileSets));
            assertEquals(1, archivedFileSets.size());
            assertEquals(new File("target/test_image/build/maven.tar"), archivedFileSets.get(0).getArchive());
            assertEquals("maven/", archivedFileSets.get(0).getPrefix());
        }
    };
}
Also used : FileSet(org.codehaus.plexus.archiver.FileSet) ArchivedFileSet(org.codehaus.plexus.archiver.ArchivedFileSet) ArrayList(java.util.ArrayList) ArchivedFileSet(org.codehaus.plexus.archiver.ArchivedFileSet) Verifications(mockit.Verifications) BuildImageConfiguration(io.fabric8.maven.docker.config.BuildImageConfiguration) AssemblyConfiguration(io.fabric8.maven.docker.config.AssemblyConfiguration) MojoParameters(io.fabric8.maven.docker.util.MojoParameters) File(java.io.File) Assembly(org.apache.maven.plugins.assembly.model.Assembly) Test(org.junit.Test)

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