<?xml version="1.0" encoding="UTF-8"?>
<!--
 * This program is free software: you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or (at your
 * option) any later version.
 * 
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
 * more details.
 * 
 * You should have received a copy of the GNU General Public License along
 * with this program.  If not, see <https://www.gnu.org/licenses/>.
 *
-->
<project xmlns="http://tiles.bluetrainsoftware.com/maven/tiles/1.1.0"
		xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
		xsi:schemaLocation="http://tiles.bluetrainsoftware.com/maven/tiles/1.1.0 https://git.inteligr8.com/inteligr8/maven-tiles/raw/xsd/src/main/resources/maven-tiles.xsd">

	<build>
		<plugins>
			<!-- This plugin copies the Dockerfile and resources to the base build directory -->
			<!-- Dockerfile ADD/COPY commands can only use files inside the build directory -->
			<plugin>
				<groupId>org.codehaus.mojo</groupId>
				<artifactId>build-helper-maven-plugin</artifactId>
				<version>3.2.0</version>
				<executions>
					<execution>
						<id>copy-and-filter-docker-resources</id>
						<phase>generate-resources</phase>
						<goals>
							<goal>add-resource</goal>
						</goals>
						<configuration>
							<resources>
								<resource>
									<directory>${docker.source.directory}</directory>
									<filtering>true</filtering>
									<targetPath>${project.build.directory}</targetPath>
								</resource>
							</resources>
						</configuration>
					</execution>
				</executions>
			</plugin>
			<!-- This plugin downloads the Platform JAR-based extension modules and runtime/test dependencies -->
			<plugin>
				<artifactId>maven-dependency-plugin</artifactId>
				<version>3.6.1</version>
				<executions>
					<!-- This execution downloads the dependency JARs, including JAR modules -->
					<execution>
						<id>download-jars</id>
						<phase>prepare-package</phase>
						<goals><goal>copy-dependencies</goal></goals>
						<configuration>
							<excludeScope>provided</excludeScope>
							<includeTypes>jar</includeTypes>
							<outputDirectory>${project.build.extDirectory}</outputDirectory>
						</configuration>
					</execution>
				</executions>
			</plugin>
			<!-- This plugin configures the building and pushing of a Docker image -->
			<plugin>
				<groupId>com.spotify</groupId>
				<artifactId>dockerfile-maven-plugin</artifactId>
				<version>1.4.13</version>
				<configuration>
					<contextDirectory>${project.build.directory}</contextDirectory>
					<repository>${docker.image.registry}/${docker.image.name}</repository>
					<tag>${docker.image.tag}</tag>
					<useMavenSettingsForAuth>true</useMavenSettingsForAuth>
				</configuration>
				<executions>
					<execution>
						<id>docker-build</id>
						<phase>package</phase>
						<goals><goal>build</goal></goals>
						<configuration>
							<repository>${docker.image.name}</repository>
						</configuration>
					</execution>
					<execution>
						<id>docker-tag-registry</id>
						<phase>install</phase>
						<goals><goal>tag</goal></goals>
					</execution>
					<execution>
						<id>docker-push</id>
						<phase>deploy</phase>
						<goals><goal>push</goal></goals>
					</execution>
				</executions>
			</plugin>
		</plugins>
	</build>

	<profiles>
		<profile>
			<id>default-props</id>
			<activation>
				<property>
					<name>!some-prop-that-never-exists</name>
				</property>
			</activation>
			<properties>
				<!-- configurable -->
				<project.build.extDirectory>${project.build.directory}/ext/platform</project.build.extDirectory>
				<docker.source.directory>${basedir}/src/main/docker</docker.source.directory>
				<docker.image.tag>${project.version}</docker.image.tag>
				
				<!-- skip deployment of spring boot app -->
				<beedk.deploy.dockerImageOnly>true</beedk.deploy.dockerImageOnly>
				<maven.deploy.skip>${beedk.deploy.dockerImageOnly}</maven.deploy.skip>
			</properties>
		</profile>
	</profiles>

</project>