<?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/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <parent>
        <groupId>com.atlassian.bamboo</groupId>
        <artifactId>bamboo-it-parent</artifactId>
        <version>8.1.0-m069</version>
    </parent>

    <artifactId>kubernetes-tests</artifactId>

    <description>
        This module is responsible for testing that Bamboo can be deployed to Kubernetes.
    </description>

    <properties>
        <dockerImage.name>atlassian/bamboo-server</dockerImage.name>

        <!-- The base image to be used for the custom image we build -->
        <dockerImage.donor>${dockerImage.name}:7.1.2</dockerImage.donor>

        <!-- The Bamboo plan overrides this with the build key, so we get a unique tag for every image we build -->
        <dockerImage.version>${user.name}</dockerImage.version>

        <!-- If you're running a local registry (e.g. for local testing), you can set this property to point to that -->
        <dockerImage.custom.registry>docker.atl-paas.net</dockerImage.custom.registry>
    </properties>

    <profiles>
        <profile>
            <id>custom-docker-image</id>
            <!--
            This profile is responsible for building a new docker image, based on an existing one from
            docker hub, with that image's contents replaced with the current snapshot. This new image
            is then published to the Atlassian internal docker registry for use by e.g. Kubernetes.
            -->
            <dependencies>
                <dependency>
                    <groupId>com.atlassian.bamboo</groupId>
                    <artifactId>atlassian-bamboo-web-app</artifactId>
                    <version>${project.version}</version>
                    <type>war</type>
                </dependency>
            </dependencies>
            <build>
                <plugins>
                    <plugin>
                        <groupId>io.fabric8</groupId>
                        <artifactId>docker-maven-plugin</artifactId>
                        <version>0.36.0</version>
                        <configuration>
                            <verbose>true</verbose>
                            <images>
                                <image>
                                    <name>${dockerImage.custom.registry}/${dockerImage.name}:${dockerImage.version}</name>
                                    <build>
                                        <dockerFile>Dockerfile</dockerFile>
                                        <assembly>
                                            <inline>
                                                <dependencySets>
                                                    <dependencySet>
                                                        <!-- Unpack the snapshot of the distro, it'll be copied into the docker image by the Dockerfile -->
                                                        <outputDirectory>distribution</outputDirectory>
                                                        <includes>
                                                            <include>com.atlassian.bamboo:atlassian-bamboo-web-app:war:${project.version}</include>
                                                        </includes>
                                                        <unpack>true</unpack>
                                                    </dependencySet>
                                                </dependencySets>
                                            </inline>
                                        </assembly>
                                    </build>
                                </image>
                            </images>
                        </configuration>
                        <executions>
                            <execution>
                                <id>build-docker-image</id>
                                <goals>
                                    <goal>build</goal>
                                </goals>
                                <phase>package</phase>
                            </execution>
                            <execution>
                                <id>push-docker-image</id>
                                <goals>
                                    <goal>push</goal>
                                </goals>
                                <phase>install</phase>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>
</project>
