Updated pom and docker to generate a stable image 35/87635/1
authorJegadeesh Babu <jegabab1@in.ibm.com>
Tue, 14 May 2019 08:12:46 +0000 (13:42 +0530)
committerJegadeesh Babu <jegabab1@in.ibm.com>
Tue, 14 May 2019 08:15:12 +0000 (13:45 +0530)
Modified files to produce stable image

Issue-ID: DCAEGEN2-1482
Change-Id: I3aeff6dd2fd208e51b9d6d52c6518d004bbecef8
Signed-off-by: Jegadeesh Babu <jegabab1@in.ibm.com>
dcae-analytics/dcae-analytics-tca-web/Dockerfile
dcae-analytics/dcae-analytics-tca-web/pom.xml

index 0e2a6e8..c573ae9 100644 (file)
@@ -7,13 +7,21 @@ FROM openjdk:8-jre-alpine
 
 MAINTAINER Rajiv Singla <rs153v@att.com>
 
-VOLUME /tmp
-ADD logback.xml logback.xml
-EXPOSE 9091
+ARG PROJECT_BUILD_DIR_NAME
+ARG FINAL_JAR
+ARG DEPENDENCIES_DIR
+ARG DOCKER_ARTIFACT_DIR
 
-ENTRYPOINT ["java", \
-            "-Djava.security.egd=file:/dev/./urandom", \
-            "-Dlogging.config=logback.xml", \
-            "-Dlogging.file=logs/${project.artifactId}.log", \
-            "-Dspring.profiles.active=dev", \
-            "-jar", "${project.build.finalName}.jar"]
+#Add a new user and group to allow container to be run as non-root
+RUN addgroup -S tca-gen2 && adduser -S -G tca-gen2 tca-gen2
+
+#Copy dependencies and executable jar
+WORKDIR ${DOCKER_ARTIFACT_DIR}
+COPY ${PROJECT_BUILD_DIR_NAME}/${FINAL_JAR} .
+#Overcome Docker limitation to put ARG inside ENTRYPOINT
+RUN ln -s ${FINAL_JAR} tca-gen2.jar
+
+EXPOSE 8100
+
+USER tca-gen2:tca-gen2
+ENTRYPOINT ["java", "-jar", "tca-gen2.jar"]
index a878a0f..f511100 100644 (file)
@@ -3,6 +3,8 @@
   ~ ================================================================================
   ~ Copyright (c) 2018-2019 AT&T Intellectual Property. All rights reserved.
   ~ ================================================================================
+  ~ Modifications Copyright (C) 2019 IBM
+  ~ ================================================================================
   ~ 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
@@ -39,6 +41,7 @@
 
     <properties>
         <main.basedir>${project.parent.basedir}</main.basedir>
+        <docker.image.name>onap/${project.groupId}.${project.artifactId}</docker.image.name>
     </properties>
 
     <dependencies>
             </plugin>
             <!-- DOCKER PLUGIN -->
             <plugin>
-                <groupId>com.spotify</groupId>
-                <artifactId>docker-maven-plugin</artifactId>
-                <configuration>
-                        <skipDocker>false</skipDocker>
-                        <imageName>${docker.repository}/onap/${project.groupId}.${project.artifactId}</imageName>
-                        <dockerDirectory>${project.basedir}</dockerDirectory>
-                        <resources>
-                               <resource>
-                                     <targetPath>${project.basedir}</targetPath>
-                                     <directory>${project.build.directory}</directory>
-                                     <include>${project.build.finalName}.jar</include>
-                              </resource>
-                        </resources>
-                        <imageTags>
-                                     <imageTag>${project.version}</imageTag>
-                                     <imageTag>latest</imageTag>
-                        </imageTags>
-                </configuration>
-            </plugin>
+                  <groupId>com.spotify</groupId>
+                  <artifactId>dockerfile-maven-plugin</artifactId>
+                  <version>1.4.3</version>
+                    <configuration>
+                         <contextDirectory>${project.basedir}</contextDirectory>
+                         <repository>${docker.repository}/${docker.image.name}</repository>
+                         <imageTags>
+                                <tag>${project.version}</tag>
+                                <tag>latest</tag>
+                                <tag>${project.version}-${maven.build.timestamp}Z</tag>
+                         </imageTags>
+                         <useMavenSettingsForAuth>true</useMavenSettingsForAuth>
+                      <buildArgs>
+                            <PROJECT_BUILD_DIR_NAME>target</PROJECT_BUILD_DIR_NAME>
+                            <DEPENDENCIES_DIR>${dependency.dir.name}</DEPENDENCIES_DIR>
+                            <DOCKER_ARTIFACT_DIR>/opt</DOCKER_ARTIFACT_DIR>
+                            <FINAL_JAR>${project.build.finalName}.jar</FINAL_JAR>
+                      </buildArgs>
+                </configuration>
+                <executions>
+                       <execution>
+                              <id>default</id>
+                              <phase>install</phase>
+                              <goals>
+                                     <goal>build</goal>
+                                     <goal>push</goal>
+                              </goals>
+                      </execution>
+               </executions>
+
+           </plugin>
         </plugins>
     </build>
 </project>