<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>
    <artifactId>share-docker</artifactId>
    <name>Alfresco Share Docker Image Builder</name>
    <packaging>pom</packaging>

    <parent>
        <groupId>org.alfresco</groupId>
        <artifactId>alfresco-share-packaging</artifactId>
        <version>20.6</version>
    </parent>

    <properties>
        <image.name>alfresco/alfresco-share-base</image.name>
    </properties>

    <build>
        <resources>
            <resource>
                <directory>src/main/resources</directory>
                <filtering>false</filtering>
            </resource>
        </resources>
        <plugins>
            <plugin>
                <artifactId>maven-resources-plugin</artifactId>
                <executions>
                    <execution>
                        <id>default-resources</id>
                        <goals>
                            <goal>resources</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>copy-resources</id>
                        <phase>process-resources</phase>
                        <goals>
                            <goal>copy-resources</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${project.build.directory}/licenses</outputDirectory>
                            <resources>
                                <resource>
                                    <directory>../licenses</directory>
                                    <filtering>true</filtering>
                                </resource>
                            </resources>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <executions>
                    <execution>
                        <id>unpack-resources</id>
                        <phase>process-resources</phase>
                        <goals>
                            <goal>unpack</goal>
                        </goals>
                        <configuration>
                            <artifactItems>
                                <artifactItem>
                                    <groupId>org.alfresco</groupId>
                                    <artifactId>share</artifactId>
                                    <version>${project.version}</version>
                                    <type>war</type>
                                    <overWrite>false</overWrite>
                                    <outputDirectory>${project.build.directory}/war/share</outputDirectory>
                                    <destFileName>share.war</destFileName>
                                </artifactItem>
                            </artifactItems>
                        </configuration>
                    </execution>
                    <execution>
                        <id>copy-resources</id>
                        <phase>process-resources</phase>
                        <goals>
                            <goal>copy</goal>
                        </goals>
                        <configuration>
                            <artifactItems>
                                <artifactItem>
                                    <groupId>org.alfresco</groupId>
                                    <artifactId>alfresco-mmt</artifactId>
                                    <type>jar</type>
                                    <overWrite>false</overWrite>
                                    <outputDirectory>${project.build.directory}/alfresco-mmt</outputDirectory>
                                </artifactItem>
                              <artifactItem>
                                    <groupId>org.alfresco.integrations</groupId>
                                    <artifactId>alfresco-googledrive-share</artifactId>
                                    <type>amp</type>
                                    <overWrite>false</overWrite>
                                    <outputDirectory>${project.build.directory}/amps_share</outputDirectory>
                                </artifactItem>
                            </artifactItems>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

    <profiles>
        <profile>
            <id>build-docker-images</id>
            <!-- builds "image:latest" locally -->
            <build>
                <plugins>
                    <plugin>
                        <groupId>io.fabric8</groupId>
                        <artifactId>docker-maven-plugin</artifactId>
                        <configuration>
                            <verbose>true</verbose>
                            <images>
                                <image>
                                    <name>${image.name}:${image.tag}</name>
                                </image>
                            </images>
                        </configuration>
                        <executions>
                            <execution>
                                <id>build-image</id>
                                <phase>package</phase>
                                <goals>
                                    <goal>build</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>

        <profile>
            <id>push-docker-images</id>
            <!-- publishes "image:latest" on Quay -->
            <build>
                <plugins>
                    <plugin>
                        <groupId>io.fabric8</groupId>
                        <artifactId>docker-maven-plugin</artifactId>
                        <configuration>
                            <verbose>true</verbose>
                            <images>
                                <!-- Quay image -->
                                <image>
                                    <name>${image.name}:${image.tag}</name>
                                    <registry>${image.registry}</registry>
                                </image>
                            </images>
                        </configuration>
                        <executions>
                            <execution>
                                <id>build-push-image</id>
                                <phase>install</phase>
                                <goals>
                                    <goal>build</goal>
                                    <goal>push</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>
</project>
