<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-auth</artifactId>
  <name>Hono Auth</name>
  <description>A default identity provider for authenticating Hono components and consumers.</description>
  <dependencies>
    <dependency>
      <groupId>org.eclipse.hono</groupId>
      <artifactId>hono-service-base</artifactId>
    </dependency>
    <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>
                    <labels>
                      <project>Eclipse Hono</project>
                      <implemented.api.1>Authentication</implemented.api.1>
                    </labels>
                    <ports>
                      <port>5671</port>
                      <port>5672</port>
                    </ports>
                    <runCmds>
                      <runCmd>adduser -S -D hono nogroup</runCmd>
                    </runCmds>
                    <user>hono</user>
                    <workdir>/home/hono</workdir>
                    <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>auth-server-*.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_KEY_PATH>/etc/hono/certs/auth-server-key.pem</HONO_AUTH_KEY_PATH>
                  <HONO_AUTH_CERT_PATH>/etc/hono/certs/auth-server-cert.pem</HONO_AUTH_CERT_PATH>
                  <HONO_AUTH_MAX_INSTANCES>1</HONO_AUTH_MAX_INSTANCES>
                  <HONO_AUTH_BIND_ADDRESS>0.0.0.0</HONO_AUTH_BIND_ADDRESS>
                  <HONO_AUTH_INSECURE_PORT_BIND_ADDRESS>0.0.0.0</HONO_AUTH_INSECURE_PORT_BIND_ADDRESS>
                  <HONO_AUTH_INSECURE_PORT_ENABLED>true</HONO_AUTH_INSECURE_PORT_ENABLED>
                  <SPRING_PROFILES_ACTIVE>authentication-impl,dev</SPRING_PROFILES_ACTIVE>
                </env>
              </resources>
            </configuration>
            <executions>
              <execution>
                <phase>package</phase>
                <goals>
                  <goal>build</goal>
                  <goal>resource</goal>
                </goals>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
    </profile>
  </profiles>

</project>