<?xml version="1.0" encoding="UTF-8"?>
<!--
  ~ Licensed to the Apache Software Foundation (ASF) under one or more
  ~ contributor license agreements.  See the NOTICE file distributed with
  ~ this work for additional information regarding copyright ownership.
  ~ The ASF 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>org.apache.unomi</groupId>
        <artifactId>unomi-root</artifactId>
        <version>1.5.4</version>
    </parent>

    <artifactId>unomi-docker</artifactId>
    <name>Apache Unomi :: Docker Image</name>
    <description>Maven project to generate Docker image</description>

    <dependencies>
        <dependency>
            <groupId>org.apache.unomi</groupId>
            <artifactId>unomi</artifactId>
            <version>${project.version}</version>
            <type>tar.gz</type>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <version>3.1.2</version>
                <executions>
                    <execution>
                        <id>copy</id>
                        <phase>process-resources</phase>
                        <goals>
                            <goal>copy</goal>
                        </goals>
                        <configuration>
                            <stripVersion>true</stripVersion>
                            <outputDirectory>${project.build.directory}/filtered-docker</outputDirectory>
                            <artifactItems>
                                <artifactItem>
                                    <groupId>org.apache.unomi</groupId>
                                    <artifactId>unomi</artifactId>
                                    <version>${project.version}</version>
                                    <type>tar.gz</type>
                                </artifactItem>
                            </artifactItems>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-resources-plugin</artifactId>
                <executions>
                    <execution>
                        <id>filter-dockerfiles</id>
                        <phase>process-resources</phase>
                        <goals>
                            <goal>copy-resources</goal>
                        </goals>
                        <configuration>
                            <resources>
                                <!-- # Filtered Resources -->
                                <resource>
                                    <directory>${project.basedir}/src/main/docker</directory>
                                    <filtering>true</filtering>
                                    <includes>
                                        <include>docker-compose.yml</include>
                                        <include>docker-compose-build.yml</include>
                                    </includes>
                                </resource>
                                <!-- # Unfiltered Resources -->
                                <resource>
                                    <directory>${project.basedir}/src/main/docker</directory>
                                    <filtering>false</filtering>
                                    <excludes>
                                        <exclude>docker-compose.yml</exclude>
                                        <include>docker-compose-build.yml</include>
                                    </excludes>
                                </resource>
                            </resources>
                            <outputDirectory>${project.build.directory}/filtered-docker</outputDirectory>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>io.fabric8</groupId>
                <artifactId>docker-maven-plugin</artifactId>
                <version>0.33.0</version>
                <configuration>
                    <images>
                        <image>
                            <alias>unomi</alias>
                            <name>apache/unomi:${project.version}</name>
                            <external>
                                <type>compose</type>
                                <basedir>${project.build.directory}/filtered-docker</basedir>
                                <composeFile>${project.build.directory}/filtered-docker/docker-compose-build.yml</composeFile>
                            </external>
                        </image>
                    </images>
                </configuration>
                <executions>
                    <execution>
                        <id>docker-build</id>
                        <goals>
                            <goal>build</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>build-helper-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <id>attach-artifacts</id>
                        <phase>package</phase>
                        <goals>
                            <goal>attach-artifact</goal>
                        </goals>
                        <configuration>
                            <artifacts>
                                <artifact>
                                    <file>
                                        ${project.build.directory}/filtered-docker/docker-compose.yml
                                    </file>
                                    <type>yml</type>
                                    <classifier>docker-compose</classifier>
                                </artifact>
                            </artifacts>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

</project>
