<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.openecomp.so</groupId>
		<artifactId>packages</artifactId>
		<version>1.1.0-SNAPSHOT</version>
	</parent>

	<packaging>pom</packaging>
	<groupId>org.openecomp.so</groupId>
	<artifactId>docker</artifactId>

	<name>MSO Docker Deliveries</name>
	<description>OpenECOMP MSO Docker Deliveries</description>

	<properties>
		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
		<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
		<!-- If the maven profile "docker" is specified the parameter -Dmso.git.url=<MsoGitRepo> must be provided
		     i.e: mvn clean install -P docker -Dmso.git.url=https://gerrit.openecomp.org/r-->
		<mso.chef.git.url.prefix>${env.GIT_NO_PROJECT}</mso.chef.git.url.prefix>
		<mso.chef.git.branchname>master</mso.chef.git.branchname>
		<mso.chef.git.url.suffix.chef.repo>so/chef-repo</mso.chef.git.url.suffix.chef.repo>
		<mso.chef.git.url.suffix.chef.config>so/so-config</mso.chef.git.url.suffix.chef.config>
		<mso.project.version>${project.version}</mso.project.version>
	</properties>

	<build>
		<finalName>${project.artifactId}-${project.version}</finalName>
		<plugins>
		    <plugin>
                <groupId>org.codehaus.groovy.maven</groupId>
                <artifactId>gmaven-plugin</artifactId>
                <executions>
                  <execution>
                    <phase>validate</phase>
                    <goals>
                      <goal>execute</goal>
                    </goals>
                    <configuration>
                      <source>
                        println project.properties['mso.project.version'];
                        def versionArray;
                        if ( project.properties['mso.project.version'] != null ) {
                            versionArray = project.properties['mso.project.version'].split('\\.');
                        }

                        if ( project.properties['mso.project.version'].endsWith("-SNAPSHOT") ) {
                            project.properties['project.docker.latesttag.version']=versionArray[0] + '.' + versionArray[1] + "-SNAPSHOT-latest";
                        } else {
                            project.properties['project.docker.latesttag.version']=versionArray[0] + '.' + versionArray[1] + "-STAGING-latest";
                        }

                        println 'New Tag for docker:' + project.properties['project.docker.latesttag.version'];
                      </source>
                    </configuration>
                  </execution>
              </executions>
            </plugin>

			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-scm-plugin</artifactId>
				<version>1.9.5</version>
				<executions>
					<execution>
						<id>chef-repo-checkout</id>
						<goals>
							<goal>checkout</goal>
						</goals>
						<phase>initialize</phase>
						<configuration>
							<connectionUrl>scm:git:${mso.chef.git.url.prefix}/${mso.chef.git.url.suffix.chef.repo}</connectionUrl>
							<checkoutDirectory>src/main/docker/docker-files/chef-configs/chef-repo</checkoutDirectory>
							<scmVersion>${mso.chef.git.branchname}</scmVersion>
							<scmVersionType>branch</scmVersionType>
							<skipCheckoutIfExists>true</skipCheckoutIfExists>
							<pushChanges>false</pushChanges>
						</configuration>
					</execution>
					<execution>
						<id>mso-config-checkout</id>
						<goals>
							<goal>checkout</goal>
						</goals>
						<phase>initialize</phase>
						<configuration>
							<connectionUrl>scm:git:${mso.chef.git.url.prefix}/${mso.chef.git.url.suffix.chef.config}</connectionUrl>
							<checkoutDirectory>src/main/docker/docker-files/chef-configs/mso-config</checkoutDirectory>
							<scmVersion>${mso.chef.git.branchname}</scmVersion>
							<scmVersionType>branch</scmVersionType>
							<skipCheckoutIfExists>true</skipCheckoutIfExists>
							<pushChanges>false</pushChanges>
						</configuration>
					</execution>
				</executions>
			</plugin>
			<plugin>
				<groupId>io.fabric8</groupId>
				<artifactId>docker-maven-plugin</artifactId>
				<version>0.16.5</version>

				<configuration>
					<verbose>true</verbose>
					<apiVersion>1.23</apiVersion>

					<images>
						<image>
							<name>openecomp/jacoco:1.0</name>
							<alias>jacoco</alias>
							<build>
								<cleanup>try</cleanup>
								<dockerFileDir>docker-files</dockerFileDir>
								<dockerFile>docker-files/Dockerfile.jacoco</dockerFile>

							</build>
						</image>
						<image>
							<name>openecomp/ubuntu-update:1.0</name>
							<alias>ubuntu-update</alias>
							<build>

								<cleanup>try</cleanup>
								<dockerFileDir>docker-files</dockerFileDir>
								<dockerFile>docker-files/Dockerfile.ubuntu-16.04-update</dockerFile>

							</build>
						</image>
						<image>
							<name>openecomp/wildfly:1.0</name>
							<alias>wildfly</alias>
							<build>

								<cleanup>try</cleanup>
								<dockerFileDir>docker-files</dockerFileDir>
								<dockerFile>docker-files/Dockerfile.wildfly-10</dockerFile>

							</build>
						</image>
						<image>
							<name>openecomp/mso-arquillian:%l</name>
							<alias>mso-arquillian</alias>
							<build>
								<tags>
								    <tag>${project.docker.latesttag.version}</tag>
									<tag>${project.version}-STAGING-${maven.build.timestamp}</tag>
								</tags>
								<cleanup>try</cleanup>
								<dockerFileDir>docker-files</dockerFileDir>
								<dockerFile>docker-files/Dockerfile.mso-arquillian</dockerFile>

							</build>
						</image>
						<image>
							<name>openecomp/mso:%l</name>
							<alias>mso</alias>
							<build>
								<tags>
									<tag>${project.version}-STAGING-${maven.build.timestamp}</tag>
									<tag>${project.docker.latesttag.version}</tag>
								</tags>
								<cleanup>try</cleanup>
								<dockerFileDir>docker-files</dockerFileDir>
								<dockerFile>docker-files/Dockerfile.mso-chef-final</dockerFile>
								<assembly>
									<basedir>/</basedir>

									<user>jboss:jboss:jboss</user>
									<basedir>/opt/jboss/wildfly/standalone/deployments</basedir>
									<descriptor>../../../../deliveries/src/main/assembly/war-pack/mso-wars.xml</descriptor>
								</assembly>
							</build>
						</image>

					</images>
				</configuration>
				<executions>
					<execution>
						<id>clean-images</id>
						<phase>pre-clean</phase>
						<goals>
							<goal>remove</goal>
						</goals>
						<configuration>
							<removeAll>true</removeAll>
							<image>openecomp/mso-arquillian:%l,openecomp/mso:%l</image>
						</configuration>
					</execution>

					<execution>
						<id>generate-images</id>
						<phase>generate-sources</phase>
						<goals>
							<goal>build</goal>
						</goals>
					</execution>

					<execution>
						<id>push-images</id>
						<phase>deploy</phase>
						<goals>
							<goal>build</goal>
							<goal>push</goal>
						</goals>
						<configuration>
							<image>openecomp/mso-arquillian:%l,openecomp/mso:%l,openecomp/jacoco:1.0</image>
						</configuration>
					</execution>
				</executions>

			</plugin>

			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-deploy-plugin</artifactId>
				<version>2.8</version>
				<configuration>
					<skip>true</skip>
				</configuration>
			</plugin>
		</plugins>
	</build>

</project>