Use io.fabric8:docker-maven-plugin to build and push docker images 14/90014/3
authorRashmi Pujar <rashmi.pujar@bell.ca>
Mon, 17 Jun 2019 14:34:49 +0000 (10:34 -0400)
committerRashmi Pujar <rashmi.pujar@bell.ca>
Wed, 19 Jun 2019 10:22:16 +0000 (06:22 -0400)
Issue-ID: POLICY-969
Signed-off-by: Rashmi Pujar <rashmi.pujar@bell.ca>
Change-Id: Ia3c7c2d6b77d87848c344f212f4a0266db90426e

packages/apex-pdp-docker/pom.xml
packages/apex-pdp-docker/src/main/docker/Dockerfile
packages/apex-pdp-package-full/pom.xml
packages/pom.xml

index 272cc1b..dbba47a 100644 (file)
@@ -1,6 +1,7 @@
 <!--
   ============LICENSE_START=======================================================
    Copyright (C) 2018 Ericsson. All rights reserved.
+   Modifications Copyright (C) 2019 Bell Canada.
   ================================================================================
   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
     <name>Policy APEX PDP - Docker build</name>
     <description>ONAP Policy APEX PDP Docker Build</description>
 
+    <properties>
+        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
+        <dist.project.version>${project.version}</dist.project.version>
+        <docker.skip>false</docker.skip>
+        <docker.skip.build>false</docker.skip.build>
+        <docker.skip.push>false</docker.skip.push>
+        <docker.pull.registry>nexus3.onap.org:10001</docker.pull.registry>
+        <docker.push.registry>nexus3.onap.org:10003</docker.push.registry>
+        <maven.build.timestamp.format>yyyyMMdd'T'HHmm</maven.build.timestamp.format>
+    </properties>
+
     <build>
+        <finalName>${project.artifactId}-${project.version}</finalName>
         <plugins>
             <plugin>
-                <groupId>org.apache.maven.plugins</groupId>
-                <artifactId>maven-dependency-plugin</artifactId>
+                <groupId>org.codehaus.groovy.maven</groupId>
+                <artifactId>gmaven-plugin</artifactId>
+                <version>1.0</version>
                 <executions>
                     <execution>
-                        <id>copy-apex-tarball</id>
-                        <phase>prepare-package</phase>
+                        <phase>validate</phase>
                         <goals>
-                            <goal>copy</goal>
+                            <goal>execute</goal>
                         </goals>
                         <configuration>
-                            <outputDirectory>${project.build.directory}/policy-apex-pdp</outputDirectory>
-                            <overWriteReleases>false</overWriteReleases>
-                            <overWriteSnapshots>true</overWriteSnapshots>
-                            <artifactItems>
-                                <artifactItem>
-                                    <groupId>org.onap.policy.apex-pdp.packages</groupId>
-                                    <artifactId>apex-pdp-package-full</artifactId>
-                                    <version>${project.version}</version>
-                                    <classifier>tarball</classifier>
-                                    <type>tar.gz</type>
-                                    <destFileName>apex-pdp-package-full.tar.gz</destFileName>
-                                </artifactItem>
-                            </artifactItems>
+                            <source>
+                                println 'Project version: ' + project.properties['dist.project.version']
+                                if (project.properties['dist.project.version'] != null) {
+                                    def versionArray = project.properties['dist.project.version'].split('-')
+                                    def minMaxVersionArray = versionArray[0].tokenize('.')
+                                    if (project.properties['dist.project.version'].endsWith("-SNAPSHOT")) {
+                                        project.properties['project.docker.latest.minmax.tag.version'] =
+                                            minMaxVersionArray[0] + "." + minMaxVersionArray[1] + "-SNAPSHOT-latest"
+                                    } else {
+                                        project.properties['project.docker.latest.minmax.tag.version'] =
+                                            minMaxVersionArray[0] + "." + minMaxVersionArray[1] + "-STAGING-latest"
+                                    }
+                                    println 'New tag for docker: ' + properties['project.docker.latest.minmax.tag.version']
+                                }
+                            </source>
                         </configuration>
                     </execution>
                 </executions>
             </plugin>
             <plugin>
-                <artifactId>maven-resources-plugin</artifactId>
+                <groupId>io.fabric8</groupId>
+                <artifactId>docker-maven-plugin</artifactId>
+                <version>0.30.0</version> <!-- Extract this as a property from the policy-parent -->
+                <configuration>
+                    <verbose>true</verbose>
+                    <apiVersion>1.23</apiVersion>
+                    <pullRegistry>${docker.pull.registry}</pullRegistry>
+                    <pushRegistry>${docker.push.registry}</pushRegistry>
+                    <images>
+                        <image>
+                            <name>onap/policy-apex-pdp</name>
+                            <build>
+                                <cleanup>try</cleanup>
+                                <dockerFile>Dockerfile</dockerFile>
+                                <tags>
+                                    <tag>${project.version}</tag>
+                                    <tag>${project.version}-${maven.build.timestamp}</tag>
+                                    <tag>${project.docker.latest.minmax.tag.version}</tag>
+                                </tags>
+                                <assembly>
+                                    <inline>
+                                        <dependencySets>
+                                            <dependencySet>
+                                                <includes>
+                                                    <include>org.onap.policy.apex-pdp.packages:apex-pdp-package-full</include>
+                                                </includes>
+                                                <outputDirectory>.</outputDirectory>
+                                                <outputFileNameMapping>apex-pdp-package-full.tar.gz</outputFileNameMapping>
+                                            </dependencySet>
+                                        </dependencySets>
+                                    </inline>
+                                </assembly>
+                            </build>
+                        </image>
+                    </images>
+                </configuration>
                 <executions>
                     <execution>
-                        <id>copy-resources</id>
-                        <phase>prepare-package</phase>
+                        <id>clean-images</id>
+                        <phase>pre-clean</phase>
                         <goals>
-                            <goal>copy-resources</goal>
+                            <goal>remove</goal>
                         </goals>
                         <configuration>
-                            <outputDirectory>${project.build.directory}/policy-apex-pdp</outputDirectory>
-                            <resources>
-                                <resource>
-                                    <directory>src/main/docker</directory>
-                                </resource>
-                            </resources>
+                            <removeAll>true</removeAll>
                         </configuration>
                     </execution>
-                </executions>
-            </plugin>
-
-            <plugin>
-                <groupId>org.codehaus.mojo</groupId>
-                <artifactId>exec-maven-plugin</artifactId>
-                <executions>
                     <execution>
-                        <id>get-target-version</id>
-                        <phase>prepare-package</phase>
+                        <id>generate-images</id>
+                        <phase>generate-sources</phase>
                         <goals>
-                            <goal>exec</goal>
+                            <goal>build</goal>
                         </goals>
                     </execution>
+                    <execution>
+                        <id>push-images</id>
+                        <phase>deploy</phase>
+                        <goals>
+                            <goal>build</goal>
+                            <goal>push</goal>
+                        </goals>
+                        <configuration>
+                            <image>onap/policy-apex-pdp</image>
+                        </configuration>
+                    </execution>
                 </executions>
+            </plugin>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-deploy-plugin</artifactId>
                 <configuration>
-                    <executable>echo</executable>
-                    <workingDirectory>${project.build.directory}</workingDirectory>
-                    <arguments>
-                        <argument>${project.version}</argument>
-                    </arguments>
-                    <outputFile>${project.build.directory}/version</outputFile>
+                    <skip>true</skip>
                 </configuration>
             </plugin>
         </plugins>
     </build>
-
+    <dependencies>
+        <dependency>
+            <groupId>${project.groupId}</groupId>
+            <artifactId>apex-pdp-package-full</artifactId>
+            <version>${project.version}</version>
+            <type>tar.gz</type>
+        </dependency>
+    </dependencies>
     <profiles>
         <profile>
             <id>apexSite</id>
             </distributionManagement>
         </profile>
     </profiles>
-</project>
\ No newline at end of file
+</project>
index d8ad557..5ae7a7c 100644 (file)
@@ -5,12 +5,9 @@ FROM onap/policy-base-alpine:1.4.0
 
 LABEL maintainer="Policy Team"
 
-ARG BUILD_VERSION=${BUILD_VERSION}
 ARG POLICY_LOGS=/var/log/onap/policy/apex-pdp
-
-ENV BUILD_VERSION ${BUILD_VERSION}
 ENV POLICY_HOME=/opt/app/policy/apex-pdp
-ENV POLICY_LOGS=${POLICY_LOGS}
+ENV POLICY_LOGS=$POLICY_LOGS
 
 RUN apk add --no-cache \
     vim \
@@ -20,27 +17,26 @@ RUN apk add --no-cache \
 # Create apex user and group
 RUN addgroup -S apexuser && adduser -S apexuser -G apexuser
 
-
 # Add Apex-specific directories and set ownership as the Apex admin user
-RUN mkdir -p ${POLICY_HOME} \
-    && mkdir -p ${POLICY_LOGS} \
-    && chown -R apexuser:apexuser ${POLICY_LOGS}
+RUN mkdir -p $POLICY_HOME \
+    && mkdir -p $POLICY_LOGS \
+    && chown -R apexuser:apexuser $POLICY_LOGS
 
 # Unpack the tarball
 RUN mkdir /packages
-COPY apex-pdp-package-full.tar.gz /packages
-RUN tar xvfz /packages/apex-pdp-package-full.tar.gz --directory ${POLICY_HOME} \
+COPY /maven/apex-pdp-package-full.tar.gz /packages
+RUN tar xvfz /packages/apex-pdp-package-full.tar.gz --directory $POLICY_HOME \
     && rm /packages/apex-pdp-package-full.tar.gz
 
 # Ensure everything has the correct permissions
 RUN find /opt/app -type d -perm 755 \
     && find /opt/app -type f -perm 644 \
-    && chmod 755 ${POLICY_HOME}/bin/*
+    && chmod 755 $POLICY_HOME/bin/*
 
 # Copy examples to Apex user area
-RUN cp -pr ${POLICY_HOME}/examples /home/apexuser \
+RUN cp -pr $POLICY_HOME/examples /home/apexuser \
     && chown -R apexuser:apexuser /home/apexuser/*
 
 USER apexuser
-ENV PATH ${POLICY_HOME}/bin:$PATH
+ENV PATH $POLICY_HOME/bin:$PATH
 WORKDIR /home/apexuser
index d0a2c15..a3b6d3f 100644 (file)
@@ -2,6 +2,7 @@
   ============LICENSE_START=======================================================
    Copyright (C) 2018 Ericsson. All rights reserved.
    Modifications Copyright (C) 2019 Nordix Foundation
+   Modifications Copyright (C) 2019 Bell Canada.
   ================================================================================
   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
                                 <descriptor>src/main/package/tarball/assembly.xml</descriptor>
                             </descriptors>
                             <finalName>${project.artifactId}-${project.version}</finalName>
+                            <appendAssemblyId>false</appendAssemblyId>
                         </configuration>
                     </execution>
                 </executions>
                         <configuration>
                             <tasks>
                                 <untar
-                                    src="${project.build.directory}/${project.artifactId}-${project.version}-tarball.tar.gz"
+                                    src="${project.build.directory}/${project.artifactId}-${project.version}.tar.gz"
                                     dest="${project.build.directory}/install_hierarchy" compression="gzip" />
                             </tasks>
                         </configuration>
index 9a5c41a..2fbf5ad 100644 (file)
@@ -1,6 +1,7 @@
 <!--
   ============LICENSE_START=======================================================
    Copyright (C) 2018 Ericsson. All rights reserved.
+   Modifications Copyright (C) 2019 Bell Canada.
   ================================================================================
   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
     <name>${project.artifactId}</name>
     <description>[${project.parent.artifactId}] packaging</description>
 
-    <modules>
-        <module>apex-pdp-package-full</module>
-        <module>apex-pdp-docker</module>
-    </modules>
-
     <profiles>
         <profile>
             <id>apexSite</id>
                 </site>
             </distributionManagement>
         </profile>
+        <profile>
+            <id>default</id>
+            <activation>
+                <activeByDefault>true</activeByDefault>
+            </activation>
+        </profile>
+        <profile>
+            <id>docker</id>
+            <modules>
+                <module>apex-pdp-package-full</module>
+                <module>apex-pdp-docker</module>
+            </modules>
+            <properties>
+                <docker.skip.push>false</docker.skip.push>
+            </properties>
+        </profile>
+
     </profiles>
 </project>