<?xml version="1.0" encoding="UTF-8"?>
<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/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <parent>
    <groupId>de.schmizzolin.maven.poms</groupId>
    <artifactId>parent</artifactId>
    <version>1.6.0</version>
    <relativePath />
  </parent>

  <name>Hello</name>
  <description>Servlet to print hello world. And diagnostic information</description>
  <groupId>de.schmizzolin</groupId>
  <artifactId>hello</artifactId>
  <version>2.0.0</version>

  <scm>
    <connection>scm:git:ssh://git@github.com/mlhartme/hello.git</connection>
    <developerConnection>scm:git:ssh://git@github.com/mlhartme/hello.git</developerConnection>
    <url>https://github.com/mlhartme/hello</url>
    <tag>hello-2.0.0</tag>
  </scm>

  <properties>
    <springboot.version>2.7.4</springboot.version>
    <maven.build.timestamp.format>yyyyMMdd-HHmmss</maven.build.timestamp.format>
  </properties>

  <developers>
    <developer>
      <id>mhm</id>
      <name>Michael Hartmeier</name>
      <roles>
        <role>lead</role>
      </roles>
    </developer>
  </developers>

  <dependencies>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-web</artifactId>
      <version>${springboot.version}</version>
    </dependency>
  </dependencies>

  <build>
    <resources>
      <resource>
        <directory>src/main/filtered-resources</directory>
        <filtering>true</filtering>
      </resource>
    </resources>
    <plugins>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>build-helper-maven-plugin</artifactId>
        <version>3.2.0</version>
        <executions>
          <execution>
            <id>regex-property</id>
            <goals>
              <goal>regex-property</goal>
            </goals>
            <configuration>
              <name>image.version</name>
              <value>${project.version}</value>
              <regex>-SNAPSHOT</regex>
              <replacement>-${maven.build.timestamp}</replacement>
              <failIfNoMatch>false</failIfNoMatch>
            </configuration>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
        <version>${springboot.version}</version>
        <configuration>
          <jvmArguments>-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5005</jvmArguments>
        </configuration>
        <executions>
          <execution>
            <id>repackage</id>
            <goals>
              <goal>repackage</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>com.mycila</groupId>
        <artifactId>license-maven-plugin</artifactId>
        <version>3.0</version>
        <configuration>
          <header>${basedir}/src/license-header.txt</header>
        </configuration>
      </plugin>
    </plugins>
  </build>
  <profiles>
    <profile>
      <id>kubernetes</id>
      <build>
        <plugins>
          <plugin>
            <artifactId>maven-resources-plugin</artifactId>
            <executions>
              <execution>
                <id>copy-resources</id>
                <phase>package</phase>
                <goals>
                  <goal>copy-resources</goal>
                </goals>
                <configuration>
                  <outputDirectory>${basedir}/target/chart</outputDirectory>
                  <resources>
                    <resource>
                      <directory>src/chart</directory>
                      <filtering>true</filtering>
                    </resource>
                  </resources>
                </configuration>
              </execution>
            </executions>
          </plugin>
          <plugin>
            <groupId>io.fabric8</groupId>
            <artifactId>docker-maven-plugin</artifactId>
            <version>0.40.2</version>
            <configuration>
              <images>
                <image>
                  <name>ghcr.io/mlhartme/hello:${image.version}</name>
                  <build>
                    <dockerFile>${basedir}/src/docker/Dockerfile</dockerFile>
                    <assembly><descriptorRef>artifact</descriptorRef></assembly>
                  </build>
                </image>
              </images>
            </configuration>
            <executions>
              <execution>
                <id>build-image</id>
                <phase>package</phase>
                <goals>
                  <goal>build</goal>
                </goals>
              </execution>
              <execution>
                <id>deploy-image</id>
                <phase>deploy</phase>
                <goals>
                  <goal>push</goal>
                </goals>
              </execution>
            </executions>
          </plugin>
          <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>exec-maven-plugin</artifactId>
            <version>3.1.0</version>
            <executions>
              <execution>
                <id>package-chart</id>
                <phase>package</phase>
                <goals>
                  <goal>exec</goal>
                </goals>
                <configuration>
                  <executable>helm</executable>
                  <workingDirectory>${project.build.directory}</workingDirectory>
                  <arguments>
                    <argument>package</argument>
                    <argument>chart</argument>
                  </arguments>
                </configuration>
              </execution>
              <execution>
                <id>push-chart</id>
                <phase>deploy</phase>
                <goals>
                  <goal>exec</goal>
                </goals>
                <configuration>
                  <executable>helm</executable>
                  <workingDirectory>${project.build.directory}</workingDirectory>
                  <arguments>
                    <argument>push</argument>
                    <argument>hello-${image.version}.tgz</argument>
                    <argument>oci://ghcr.io/mlhartme/charts</argument>
                  </arguments>
                </configuration>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
    </profile>
  </profiles>
</project>
