<?xml version="1.0" encoding="UTF-8" standalone="no"?><!--

     Copyright 2005-2015 Red Hat, Inc.

     Red Hat licenses this file to you under the Apache License, version
     2.0 (the "License"); you may not use this file except in compliance
     with the License.  You may obtain a copy of the License at

        http://www.apache.org/licenses/LICENSE-2.0

     Unless required by applicable law or agreed to in writing, software
     distributed under the License is distributed on an "AS IS" BASIS,
     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
     implied.  See the License for the specific language governing
     permissions and limitations under the License.

-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

  <modelVersion>4.0.0</modelVersion>

  <parent>
    <groupId>io.fabric8.ipaas.apps</groupId>
    <artifactId>fabric8-ipaas</artifactId>
    <version>2.2.168</version>
  </parent>

  <artifactId>elasticsearch-v1</artifactId>

  <name>Elasticsearch-v1</name>
  <description>
    [elasticsearch](http://elasticsearch.com/) provides distributed RESTful search and analytics
  </description>

  <properties>
    <docker.image>${fabric8.dockerUser}${project.artifactId}:${project.version}</docker.image>
  </properties>

  <build>
    <resources>
      <resource>
        <directory>src/main/fabric8</directory>
        <filtering>true</filtering>
      </resource>
      <resource>
        <directory>src/main/resources-filtered</directory>
        <filtering>true</filtering>
      </resource>
    </resources>
    <plugins>
      <plugin>
        <groupId>io.fabric8</groupId>
        <artifactId>fabric8-maven-plugin</artifactId>
        <executions>
          <execution>
            <id>fmp</id>
            <goals>
              <goal>resource</goal>
              <goal>helm</goal>
              <goal>build</goal>
            </goals>
          </execution>
        </executions>
        <configuration>
          <image>${docker.image}</image>
          <images>
            <image>
              <name>${docker.image}</name>
              <build>
                <from>docker.io/${fabric8.dockerUser}elasticsearch-k8s:1.5.2</from>
                <assembly>
                  <basedir>/</basedir>
                  <inline xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
                          xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">
                    <id>${project.artifactId}</id>
                    <fileSets>
                      <fileSet>
                        <directory>${project.basedir}/src/main/resources</directory>
                        <outputDirectory>/</outputDirectory>
                        <includes>
                          <include>*</include>
                        </includes>
                      </fileSet>
                    </fileSets>
                  </inline>
                </assembly>
                <entryPoint>
                  <shell>/docker-entrypoint.sh elasticsearch ${elasticssl}</shell>
                </entryPoint>
                <!--
                                <runCmds>
                                  <runCmd>/put-template.sh</runCmd>
                                </runCmds>
                -->
              </build>
            </image>
          </images>
        </configuration>
      </plugin>
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <configuration>
          <fork>true</fork>
          <compilerArgs>
            <arg>-J-Dproject.version=${project.version}</arg>
          </compilerArgs>
        </configuration>
      </plugin>

    </plugins>
  </build>

  <dependencies>
    <dependency>
      <groupId>io.fabric8</groupId>
      <artifactId>kubernetes-api</artifactId>
    </dependency>

    <dependency>
      <groupId>io.fabric8</groupId>
      <artifactId>kubernetes-generator</artifactId>
    </dependency>

    <dependency>
      <groupId>org.jboss.arquillian.junit</groupId>
      <artifactId>arquillian-junit-container</artifactId>
      <scope>test</scope>
    </dependency>

    <dependency>
      <groupId>io.fabric8</groupId>
      <artifactId>fabric8-arquillian</artifactId>
      <scope>test</scope>
    </dependency>

    <dependency>
      <groupId>io.fabric8</groupId>
      <artifactId>kubernetes-assertions</artifactId>
      <scope>test</scope>
    </dependency>

    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <scope>test</scope>
    </dependency>
  </dependencies>

  <profiles>
    <!-- activate the ssl profile to start apiman with a selfsigned certificate -->
    <profile>
      <id>ssl</id>
      <properties>
        <docker.env.apiman.ssl>true</docker.env.apiman.ssl>
        <elasticssl>ssl</elasticssl>
        <keystore.password>supersecret</keystore.password>
        <fabric8.volume.keystore.secret>elasticsearch-v1-keystore</fabric8.volume.keystore.secret>
        <fabric8.volume.keystore.mountPath>/secret/elasticsearch-v1/</fabric8.volume.keystore.mountPath>
        <fabric8.annotations.service.api.service.kubernetes.io.scheme>https
        </fabric8.annotations.service.api.service.kubernetes.io.scheme>
        <fabric8.extra.json>${project.build.directory}/classes/route-tls-passthrough.json</fabric8.extra.json>
        <fabric8.readinessProbe.exec>/probe.sh https</fabric8.readinessProbe.exec>
      </properties>
      <build>
        <plugins>

          <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>keytool-maven-plugin</artifactId>
            <version>1.5</version>
            <executions>
              <execution>
                <id>self-signed-cert</id>
                <goals>
                  <goal>generateKeyPair</goal>
                </goals>
                <phase>generate-sources</phase>
              </execution>
              <execution>
                <id>export-public-key</id>
                <goals>
                  <goal>exportCertificate</goal>
                </goals>
                <phase>generate-resources</phase>
              </execution>
            </executions>
            <configuration>
              <keystore>${project.build.directory}/secret/${project.artifactId}/keystore</keystore>
              <storepass>${keystore.password}</storepass>
              <keypass>${keystore.password}</keypass>
              <alias>SSLforELASTIC</alias>
              <dname>CN=${project.artifactId}.default.svc.cluster.local, OU=Example, O=Fabric8 Inc.,
                L=Ipswich, S=Massachusetts, C=US
              </dname>
              <sigalg>SHA1withRSA</sigalg>
              <ext/>
              <validity>100</validity>
              <keyalg>RSA</keyalg>
              <keysize>2048</keysize>
              <rfc>true</rfc>
              <file>${project.build.directory}/secret/${project.artifactId}/public.key</file>
            </configuration>
          </plugin>
          <plugin>
            <artifactId>maven-resources-plugin</artifactId>
            <version>2.7</version>
            <executions>
              <execution>
                <id>copy-resources</id>
                <phase>validate</phase>
                <goals>
                  <goal>copy-resources</goal>
                </goals>
                <configuration>
                  <outputDirectory>${basedir}/target/secret/${project.artifactId}</outputDirectory>
                  <resources>
                    <resource>
                      <directory>${basedir}/ssl</directory>
                      <filtering>true</filtering>
                    </resource>
                  </resources>
                </configuration>
              </execution>
            </executions>
          </plugin>
          <plugin>
            <artifactId>exec-maven-plugin</artifactId>
            <groupId>org.codehaus.mojo</groupId>
            <executions>
              <execution>
                <id>Deploy Secret</id>
                <phase>package</phase>
                <goals>
                  <goal>exec</goal>
                </goals>
                <configuration>
                  <executable>${basedir}/ssl.sh</executable>
                </configuration>
              </execution>
            </executions>
          </plugin>

        </plugins>
      </build>
    </profile>

    <!--
      Default sample commands:

      mvn -Pf8-build         ... build Docker images and create OpenShift deployment configs
      mvn -Pf8-deploy        ... f8-build + push to Docker registry + applying deployment config to OpenShift
      mvn -Pf8-local-deploy ... deployment for a single node setup without pushing to a registry

      For individual goal usage please consult the fabric8 documentation
      -->
    <profile>
      <id>f8-build</id>
      <build>
        <defaultGoal>clean install docker:build fabric8:json</defaultGoal>
      </build>
    </profile>
    <profile>
      <id>f8-deploy</id>
      <properties>
        <fabric8.imagePullPolicySnapshot>Always</fabric8.imagePullPolicySnapshot>
        <fabric8.recreate>true</fabric8.recreate>
      </properties>
      <build>
        <defaultGoal>clean install docker:build docker:push fabric8:json fabric8:apply</defaultGoal>
      </build>
    </profile>
    <profile>
      <id>f8-local-deploy</id>
      <properties>
        <fabric8.recreate>true</fabric8.recreate>
      </properties>
      <build>
        <defaultGoal>clean install docker:build fabric8:json fabric8:apply</defaultGoal>
      </build>
    </profile>
  </profiles>
</project>