<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>org.eclipse.hono</groupId>
    <artifactId>hono-services</artifactId>
    <version>0.5-M6</version>
  </parent>
  <artifactId>hono-service-device-registry</artifactId>
  <name>Hono Device Registry</name>
  <description>A default device registry for Hono implementing the device registration and credentials API.</description>

  <dependencies>
    <dependency>
      <groupId>io.vertx</groupId>
      <artifactId>vertx-unit</artifactId>
      <scope>test</scope>
    </dependency>
  </dependencies>

  <build>
    <plugins>
      <plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-dependency-plugin</artifactId>
      </plugin>
    </plugins>
  </build>

  <profiles>
    <profile>
      <id>build-docker-image</id>
      <activation>
        <property>
          <name>docker.host</name>
        </property>
      </activation>
      <build>
        <plugins>
          <plugin>
            <groupId>io.fabric8</groupId>
            <artifactId>fabric8-maven-plugin</artifactId>
            <configuration>
              <images>
                <image>
                  <build>
                    <from>${java-base-image.name}</from>
                    <ports>
                      <port>5671</port>
                      <port>5672</port>
                    </ports>
                    <runCmds>
                      <runCmd>adduser -S -D hono nogroup &amp;&amp; mkdir /home/hono/device-registry &amp;&amp; chown -R hono /home/hono</runCmd>
                    </runCmds>
                    <user>hono</user>
                    <workdir>/home/hono</workdir>
                    <volumes>
                      <volume>/home/hono/device-registry</volume>
                    </volumes>
                    <cmd>
                      <exec>
                        <arg>java</arg>
                        <arg>-Dvertx.cacheDirBase=/tmp</arg>
                        <arg>-jar</arg>
                        <arg>/opt/hono/${project.artifactId}-${project.version}-${classifier.spring.boot.artifact}.jar</arg>
                      </exec>
                    </cmd>
                    <assembly>
                      <mode>dir</mode>
                      <basedir>/</basedir>
                      <inline>
                        <fileSets>
                          <fileSet>
                            <directory>${project.build.directory}/certs</directory>
                            <outputDirectory>etc/hono/certs</outputDirectory>
                            <includes>
                              <include>device-registry-*.pem</include>
                              <include>auth-server-cert.pem</include>
                              <include>trusted-certs.pem</include>
                            </includes>
                          </fileSet>
                          <fileSet>
                            <directory>${project.build.directory}</directory>
                            <outputDirectory>opt/hono</outputDirectory>
                            <includes>
                              <include>${project.artifactId}-${project.version}-${classifier.spring.boot.artifact}.jar</include>
                            </includes>
                          </fileSet>
                        </fileSets>
                      </inline>
                    </assembly>
                  </build>
                </image>
              </images>
              <resources>
                <env>
                  <HONO_AUTH_HOST>${hono.auth.host}</HONO_AUTH_HOST>
                  <HONO_AUTH_PORT>5671</HONO_AUTH_PORT>
                  <HONO_AUTH_NAME>${project.name}</HONO_AUTH_NAME>
                  <HONO_AUTH_VALIDATION_CERT_PATH>${hono.auth.validation.certPath}</HONO_AUTH_VALIDATION_CERT_PATH>
                  <HONO_AUTH_TRUST_STORE_PATH>${hono.trustStore.path}</HONO_AUTH_TRUST_STORE_PATH>
                  <HONO_DEVICE_REGISTRY_KEY_PATH>/etc/hono/certs/device-registry-key.pem</HONO_DEVICE_REGISTRY_KEY_PATH>
                  <HONO_DEVICE_REGISTRY_CERT_PATH>/etc/hono/certs/device-registry-cert.pem</HONO_DEVICE_REGISTRY_CERT_PATH>
                  <HONO_DEVICE_REGISTRY_BIND_ADDRESS>0.0.0.0</HONO_DEVICE_REGISTRY_BIND_ADDRESS>
                  <HONO_DEVICE_REGISTRY_INSECURE_PORT_BIND_ADDRESS>0.0.0.0</HONO_DEVICE_REGISTRY_INSECURE_PORT_BIND_ADDRESS>
                  <HONO_DEVICE_REGISTRY_INSECURE_PORT_ENABLED>true</HONO_DEVICE_REGISTRY_INSECURE_PORT_ENABLED>
                  <HONO_DEVICE_REGISTRY_SIGNING_SHARED_SECRET>${hono.regAssertion.sharedSecret}</HONO_DEVICE_REGISTRY_SIGNING_SHARED_SECRET>
                  <HONO_DEVICE_REGISTRY_MAX_INSTANCES>1</HONO_DEVICE_REGISTRY_MAX_INSTANCES>
                  <SPRING_PROFILES_ACTIVE>dev</SPRING_PROFILES_ACTIVE>
                </env>
              </resources>
            </configuration>
          </plugin>
        </plugins>
      </build>
    </profile>
  </profiles>

</project>
