<?xml version="1.0" encoding="UTF-8"?>
<!--
  #%L
  Wildfly Camel Docker
  %%
  Copyright (C) 2013 - 2014 RedHat
  %%
  Licensed 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.
  #L%
  -->


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

    <parent>
        <groupId>org.wildfly.camel</groupId>
        <artifactId>wildfly-camel</artifactId>
        <version>10.2.0</version>
    </parent>

    <name>Wildfly Camel :: Docker</name>

    <artifactId>wildfly-camel-docker</artifactId>
    <packaging>pom</packaging>

    <!-- Properties -->
    <properties>
        <docker.image.name>wildflyext/wildfly-camel</docker.image.name>
        <docker.image.from>openshift/wildfly-160-centos7:latest</docker.image.from>
        <docker.image.maintainer>Thomas Diesler tdiesler@redhat.com</docker.image.maintainer>
        <docker.image.version>latest</docker.image.version>
        <docker.removeAll>true</docker.removeAll>
        <docker.skipPush>true</docker.skipPush>
        <server.config>standalone-camel.xml</server.config>
        <server.home>/wildfly</server.home>
    </properties>

    <!-- Dependencies -->
    <dependencies>
        <dependency>
            <groupId>org.wildfly.camel</groupId>
            <artifactId>wildfly-camel-patch</artifactId>
            <version>${project.version}</version>
            <scope>provided</scope>
            <type>tar.gz</type>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <executions>
                    <execution>
                        <id>unpack-distro</id>
                        <goals>
                            <goal>unpack</goal>
                        </goals>
                        <phase>generate-resources</phase>
                        <configuration>
                            <artifactItems>
                                <artifactItem>
                                    <groupId>org.wildfly.camel</groupId>
                                    <artifactId>wildfly-camel-patch</artifactId>
                                    <version>${project.version}</version>
                                    <type>tar.gz</type>
                                </artifactItem>
                            </artifactItems>
                            <excludes>**/standalone/configuration/**</excludes>
                            <outputDirectory>${project.build.directory}/${server.home}</outputDirectory>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>io.fabric8</groupId>
                <artifactId>docker-maven-plugin</artifactId>
                <configuration>
                    <autoPull>always</autoPull>
                    <images>
                        <image>
                            <name>${docker.image.name}</name>
                            <build>
                                <maintainer>${docker.image.maintainer}</maintainer>
                                <from>${docker.image.from}</from>
                                <tags>
                                    <tag>${docker.image.version}</tag>
                                    <tag>${project.version}</tag>
                                </tags>
                                <labels>
                                    <io.k8s.description>Platform for building and running Camel applications on WildFly ${version.wildfly}</io.k8s.description>
                                    <io.k8s.display-name>WildFly Camel ${project.version}</io.k8s.display-name>
                                    <io.openshift.tags>builder,wildfly,wildfly-camel,wildfly-camel-${project.version}</io.openshift.tags>
                                </labels>
                                <cmd>
                                    <exec>
                                        <args>/usr/libexec/s2i/run</args>
                                    </exec>
                                </cmd>
                                <env>
                                    <JBOSS_HOME>${server.home}</JBOSS_HOME>
                                    <LAUNCH_JBOSS_IN_BACKGROUND>true</LAUNCH_JBOSS_IN_BACKGROUND>
                                </env>
                                <assembly>
                                    <basedir>/</basedir>
                                    <descriptor>${project.basedir}/s2i/assembly-artifacts.xml</descriptor>
                                    <user>1001:0:1001</user>
                                </assembly>
                                <runCmds>
                                    <run>java -jar --add-modules java.se ${server.home}/jboss-modules.jar -mp ${server.home}/modules org.wildfly.extras.config --configs camel --enable</run>
                                    <run>chmod g=u -R ${server.home}</run>
                                </runCmds>
                                <optimise>true</optimise>
                            </build>
                        </image>
                    </images>
                </configuration>
                <executions>
                    <execution>
                        <id>remove-images</id>
                        <phase>clean</phase>
                        <goals>
                            <goal>remove</goal>
                        </goals>
                        <configuration>
                            <images>
                                <image>
                                    <name>${docker.image.name}:${docker.image.version}</name>
                                </image>
                                <image>
                                    <name>${docker.image.name}:${project.version}</name>
                                </image>
                            </images>
                        </configuration>
                    </execution>
                    <execution>
                        <id>build-docker-image</id>
                        <phase>package</phase>
                        <goals>
                            <goal>build</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>push-docker-image</id>
                        <goals>
                            <goal>push</goal>
                        </goals>
                        <phase>install</phase>
                        <configuration>
                            <skipPush>${docker.skipPush}</skipPush>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
    <profiles>
        <!-- Requires registry credentials: -Ddocker.username=myUserName -Ddocker.password=secret -->
        <profile>
            <id>docker.push</id>
            <activation>
                <property>
                    <name>docker.push</name>
                </property>
            </activation>
            <properties>
                <docker.skipPush>false</docker.skipPush>
            </properties>
        </profile>
        <!-- Enables useful experimental docker features -->
        <profile>
            <id>docker.experimental</id>
            <activation>
                <property>
                    <name>docker.experimental</name>
                </property>
            </activation>
            <build>
                <plugins>
                    <plugin>
                        <groupId>io.fabric8</groupId>
                        <artifactId>docker-maven-plugin</artifactId>
                        <configuration>
                            <images>
                                <image>
                                    <build>
                                        <buildOptions>
                                            <squash>true</squash>
                                        </buildOptions>
                                    </build>
                                </image>
                            </images>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>
</project>
