Fix dockerfile to reflect common image naming 22/94022/1
authorDmitry Puzikov <dmitry.puzikov@tieto.com>
Tue, 9 Jul 2019 14:06:02 +0000 (16:06 +0200)
committerDmitry Puzikov <dmitry.puzikov@tieto.com>
Wed, 21 Aug 2019 07:36:44 +0000 (09:36 +0200)
FROM section changed to reflerct new
aai-common image naming scheme.

Added explicit aai-common version parameter.

Change-Id: Ifc1187384ce757f1a2bf852a670dd9d706a4c782
Issue-ID: INT-1141
Signed-off-by: Dmitry Puzikov <dmitry.puzikov@tieto.com>
pom.xml
src/main/assembly/descriptor.xml [new file with mode: 0644]
src/main/docker/Dockerfile
src/test/java/org/onap/crud/event/response/GraphEventResponseHandlerTest.java

diff --git a/pom.xml b/pom.xml
index e60005b..698de2c 100644 (file)
--- a/pom.xml
+++ b/pom.xml
@@ -19,14 +19,14 @@ limitations under the License.
 ============LICENSE_END=========================================================
 -->
 <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">
+         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.onap.oparent</groupId>
         <artifactId>oparent</artifactId>
         <version>2.0.0</version>
-        <relativePath />
+        <relativePath/>
     </parent>
 
     <groupId>org.onap.aai.gizmo</groupId>
@@ -45,6 +45,14 @@ limitations under the License.
          coverage caused by new changes. Note that this figure cannot be lower than the ONAP requirement of 0.55 -->
         <jacoco.line.coverage.limit>0.60</jacoco.line.coverage.limit>
         <jacoco.report.directory>${project.build.directory}/code-coverage</jacoco.report.directory>
+        <!-- docker related properties -->
+        <docker.fabric.version>0.28.0</docker.fabric.version>
+        <aai.docker.version>1.0.0</aai.docker.version>
+        <aai.build.directory>${project.build.directory}/${project.artifactId}-build/
+        </aai.build.directory>
+        <aai.docker.namespace>onap</aai.docker.namespace>
+        <aai.base.image>alpine</aai.base.image>
+        <aai.base.image.version>1.6.0</aai.base.image.version>
     </properties>
 
     <dependencyManagement>
@@ -116,21 +124,21 @@ limitations under the License.
         </dependency>
 
 
-     <dependency>
-         <groupId>io.swagger</groupId>
-         <artifactId>swagger-jersey2-jaxrs</artifactId>
-         <version>1.5.8</version>
-      </dependency>
-      <dependency>
-         <groupId>io.springfox</groupId>
-         <artifactId>springfox-swagger2</artifactId>
-         <version>2.9.2</version>
-      </dependency>
-            <dependency>
-         <groupId>io.springfox</groupId>
-         <artifactId>springfox-swagger-ui</artifactId>
-         <version>2.9.2</version>
-      </dependency>
+        <dependency>
+            <groupId>io.swagger</groupId>
+            <artifactId>swagger-jersey2-jaxrs</artifactId>
+            <version>1.5.8</version>
+        </dependency>
+        <dependency>
+            <groupId>io.springfox</groupId>
+            <artifactId>springfox-swagger2</artifactId>
+            <version>2.9.2</version>
+        </dependency>
+        <dependency>
+            <groupId>io.springfox</groupId>
+            <artifactId>springfox-swagger-ui</artifactId>
+            <version>2.9.2</version>
+        </dependency>
 
 
         <!-- ONAP AAI-COMMON (incl. model) -->
@@ -145,8 +153,8 @@ limitations under the License.
             <version>${version.org.onap.aai.aai-schema-ingest}</version>
             <exclusions>
                 <exclusion>
-                  <groupId>org.powermock</groupId>
-                  <artifactId>*</artifactId>
+                    <groupId>org.powermock</groupId>
+                    <artifactId>*</artifactId>
                 </exclusion>
             </exclusions>
         </dependency>
@@ -165,7 +173,7 @@ limitations under the License.
         <dependency>
             <groupId>org.onap.aai.event-client</groupId>
             <artifactId>event-client-dmaap</artifactId>
-           <version>${event.client.version}</version>
+            <version>${event.client.version}</version>
             <exclusions>
                 <exclusion>
                     <groupId>org.slf4j</groupId>
@@ -176,7 +184,7 @@ limitations under the License.
         <dependency>
             <groupId>org.onap.aai.event-client</groupId>
             <artifactId>event-client-kafka</artifactId>
-           <version>${event.client.version}</version>
+            <version>${event.client.version}</version>
             <exclusions>
                 <exclusion>
                     <groupId>org.slf4j</groupId>
@@ -186,9 +194,9 @@ limitations under the License.
         </dependency>
 
         <dependency>
-           <groupId>org.onap.aai.event-client</groupId>
-           <artifactId>event-client-rabbitmq</artifactId>
-           <version>${event.client.version}</version>
+            <groupId>org.onap.aai.event-client</groupId>
+            <artifactId>event-client-rabbitmq</artifactId>
+            <version>${event.client.version}</version>
             <exclusions>
                 <exclusion>
                     <groupId>org.slf4j</groupId>
@@ -363,6 +371,103 @@ limitations under the License.
         </dependency>
     </dependencies>
 
+    <profiles>
+        <!-- Docker profile to be used for building docker image and pushing to nexus -->
+        <profile>
+            <id>docker</id>
+            <build>
+                <plugins>
+                    <plugin>
+                        <groupId>org.codehaus.groovy.maven</groupId>
+                        <artifactId>gmaven-plugin</artifactId>
+                        <version>1.0</version>
+                        <executions>
+                            <execution>
+                                <phase>prepare-package</phase>
+                                <goals>
+                                    <goal>execute</goal>
+                                </goals>
+                                <configuration>
+                                    <source>
+                                        def userAaiBaseImage = session.userProperties['aai.base.image']
+                                        def userAaiCommonVersion = session.userProperties['aai.base.image.version']
+                                        if (userAaiCommonVersion != null) {
+                                            project.properties['aai.base.image.version'] = userAaiCommonVersion
+                                        }
+                                        if (userAaiBaseImage != null) {
+                                            project.properties['aai.base.image'] = userAaiBaseImage
+                                        }
+                                        log.info 'Base image flavour: ' + project.properties['aai.base.image']
+                                        log.info 'Base image version: ' + project.properties['aai.base.image.version']
+                                    </source>
+                                </configuration>
+                            </execution>
+                        </executions>
+                    </plugin>
+                    <plugin>
+                        <groupId>io.fabric8</groupId>
+                        <artifactId>docker-maven-plugin</artifactId>
+                        <version>${docker.fabric.version}</version>
+                        <configuration>
+                            <verbose>true</verbose>
+                            <apiVersion>1.23</apiVersion>
+                            <images>
+                                <image>
+                                    <name>${docker.push.registry}/${aai.docker.namespace}/${project.artifactId}:%l
+                                    </name>
+                                    <build>
+                                        <filter>@</filter>
+                                        <tags>
+                                            <tag>latest</tag>
+                                        </tags>
+                                        <cleanup>try</cleanup>
+                                        <dockerFileDir>${project.basedir}/src/main/docker</dockerFileDir>
+                                        <assembly>
+                                            <inline>
+                                                <fileSets>
+                                                    <fileSet>
+                                                        <directory>${aai.build.directory}</directory>
+                                                        <outputDirectory>/${project.artifactId}</outputDirectory>
+                                                    </fileSet>
+                                                </fileSets>
+                                            </inline>
+                                        </assembly>
+                                    </build>
+                                </image>
+                            </images>
+                        </configuration>
+                        <executions>
+                            <execution>
+                                <id>clean-images</id>
+                                <phase>pre-clean</phase>
+                                <goals>
+                                    <goal>remove</goal>
+                                </goals>
+                                <configuration>
+                                    <removeAll>true</removeAll>
+                                </configuration>
+                            </execution>
+                            <execution>
+                                <id>generate-images</id>
+                                <phase>package</phase>
+                                <goals>
+                                    <goal>build</goal>
+                                </goals>
+                            </execution>
+                            <execution>
+                                <id>push-images</id>
+                                <phase>deploy</phase>
+                                <goals>
+                                    <goal>push</goal>
+                                </goals>
+                            </execution>
+                        </executions>
+                    </plugin>
+                </plugins>
+            </build>
+        </profile>
+    </profiles>
+
     <build>
         <finalName>${project.artifactId}</finalName>
         <plugins>
@@ -374,87 +479,31 @@ limitations under the License.
             mvn formatter:format spotless:apply process-sources
             -->
             <plugin>
-                 <groupId>net.revelc.code.formatter</groupId>
-                 <artifactId>formatter-maven-plugin</artifactId>
-                 <version>2.8.1</version>
-                 <configuration>
+                <groupId>net.revelc.code.formatter</groupId>
+                <artifactId>formatter-maven-plugin</artifactId>
+                <version>2.8.1</version>
+                <configuration>
                     <configFile>${project.basedir}/onap-java-formatter.xml</configFile>
-                 </configuration>
-                 <!-- https://code.revelc.net/formatter-maven-plugin/
-                      use mvn formatter:format to rewrite source files
-                      use mvn formatter:validate to validate source files -->
-             </plugin>
-            <plugin>
-              <groupId>com.diffplug.spotless</groupId>
-              <artifactId>spotless-maven-plugin</artifactId>
-              <version>1.18.0</version>
-              <configuration>
-                <java>
-                 <importOrder>
-                   <order>com,java,javax,org</order>
-                 </importOrder>
-                </java>
-              </configuration>
-            <!-- https://github.com/diffplug/spotless/tree/master/plugin-maven
-                 use mvn spotless:apply to rewrite source files
-                 use mvn spotless:check to validate source files -->
-            </plugin>
-            <plugin>
-                <groupId>org.apache.maven.plugins</groupId>
-                <artifactId>maven-resources-plugin</artifactId>
-                <version>2.7</version>
-                <executions>
-                    <execution>
-                        <id>copy-docker-file</id>
-                        <phase>package</phase>
-                        <goals>
-                            <goal>copy-resources</goal>
-                        </goals>
-                        <configuration>
-                            <outputDirectory>target</outputDirectory>
-                            <overwrite>true</overwrite>
-                            <resources>
-                                <resource>
-                                    <directory>${basedir}/src/main/docker</directory>
-                                    <filtering>true</filtering>
-                                    <includes>
-                                        <include>**/*</include>
-                                    </includes>
-                                </resource>
-                                <resource>
-                                    <directory>${basedir}</directory>
-                                    <filtering>true</filtering>
-                                    <includes>
-                                        <include>bundleconfig-local/**</include>
-                                    </includes>
-                                </resource>
-                                <resource>
-                                    <directory>${basedir}/src/main/bin/</directory>
-                                </resource>
-                            </resources>
-                        </configuration>
-                    </execution>
-                </executions>
+                </configuration>
+                <!-- https://code.revelc.net/formatter-maven-plugin/
+                     use mvn formatter:format to rewrite source files
+                     use mvn formatter:validate to validate source files -->
             </plugin>
-
             <plugin>
-                <groupId>com.spotify</groupId>
-                <artifactId>docker-maven-plugin</artifactId>
-                <version>0.4.11</version>
+                <groupId>com.diffplug.spotless</groupId>
+                <artifactId>spotless-maven-plugin</artifactId>
+                <version>1.18.0</version>
                 <configuration>
-                    <verbose>true</verbose>
-                    <serverId>docker-hub</serverId>
-                    <imageName>${docker.push.registry}/onap/${project.artifactId}</imageName>
-                    <dockerDirectory>${docker.location}</dockerDirectory>
-                    <imageTags>
-                        <imageTag>latest</imageTag>
-                       <tag>${project.docker.latesttag.version}</tag>
-                       <tag>${parsedVersion.majorVersion}.${parsedVersion.minorVersion}-STAGING-${maven.build.timestamp}</tag>
-                    </imageTags>
-                    <forceTags>true</forceTags>
+                    <java>
+                        <importOrder>
+                            <order>com,java,javax,org</order>
+                        </importOrder>
+                    </java>
                 </configuration>
+                <!-- https://github.com/diffplug/spotless/tree/master/plugin-maven
+                     use mvn spotless:apply to rewrite source files
+                     use mvn spotless:check to validate source files -->
             </plugin>
-
             <!-- license plugin -->
             <!-- Uncomment this to add a license header to every source file -->
             <plugin>
@@ -518,6 +567,23 @@ limitations under the License.
                     </execution>
                 </executions>
             </plugin>
+            <plugin>
+                <artifactId>maven-assembly-plugin</artifactId>
+                <configuration>
+                    <descriptors>
+                        <descriptor>src/main/assembly/descriptor.xml</descriptor>
+                    </descriptors>
+                </configuration>
+                <executions>
+                    <execution>
+                        <id>make-assembly</id>
+                        <phase>package</phase>
+                        <goals>
+                            <goal>single</goal>
+                        </goals>
+                    </execution>
+                </executions>
+            </plugin>
             <plugin>
                 <groupId>org.apache.maven.plugins</groupId>
                 <artifactId>maven-dependency-plugin</artifactId>
@@ -536,7 +602,7 @@ limitations under the License.
                                     <version>${version.org.onap.aai.aai-schema}</version>
                                     <type>jar</type>
                                     <includes>onap/**/</includes>
-                                    <outputDirectory>${project.build.directory}/bundleconfig-local/etc</outputDirectory>
+                                    <outputDirectory>${aai.build.directory}/bundleconfig/etc</outputDirectory>
                                 </artifactItem>
                             </artifactItems>
                         </configuration>
@@ -571,7 +637,7 @@ limitations under the License.
                     </execution>
                 </executions>
             </plugin>
-           <plugin>
+        <plugin>
              <groupId>org.codehaus.mojo</groupId>
              <artifactId>build-helper-maven-plugin</artifactId>
               <version>3.0.0</version>
@@ -586,7 +652,7 @@ limitations under the License.
            </plugin>
        </plugins>
     </build>
-    
+
     <distributionManagement>
         <site>
             <id>ecomp-javadoc</id>
diff --git a/src/main/assembly/descriptor.xml b/src/main/assembly/descriptor.xml
new file mode 100644 (file)
index 0000000..2a1a2e7
--- /dev/null
@@ -0,0 +1,36 @@
+<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"\r
+          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"\r
+          xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">\r
+    <id>build</id>\r
+    <includeBaseDirectory>false</includeBaseDirectory>\r
+    <formats>\r
+        <format>dir</format>\r
+    </formats>\r
+    <fileSets>\r
+        <fileSet>\r
+            <directory>${project.basedir}/bundleconfig-local</directory>\r
+            <outputDirectory>/bundleconfig</outputDirectory>\r
+            <includes>\r
+                <include>**/*</include>\r
+            </includes>\r
+        </fileSet>\r
+        <fileSet>\r
+            <directory>${project.basedir}/src/main/bin</directory>\r
+            <outputDirectory>/bin</outputDirectory>\r
+            <includes>\r
+                <include>**/*</include>\r
+            </includes>\r
+        </fileSet>\r
+        <fileSet>\r
+            <directory>${project.build.directory}</directory>\r
+            <outputDirectory>/</outputDirectory>\r
+            <includes>\r
+                <include>*.jar</include>\r
+            </includes>\r
+            <excludes>\r
+                <exclude>Dockerfile</exclude>\r
+                <exclude>*.sh</exclude>\r
+            </excludes>\r
+        </fileSet>\r
+    </fileSets>\r
+</assembly>\r
index 343ed4d..35297e7 100644 (file)
@@ -1,45 +1,25 @@
-FROM ubuntu:14.04
+FROM @aai.docker.namespace@/aai-common-@aai.base.image@:@aai.base.image.version@
 
 ARG MICRO_HOME=/opt/app/crud-api
 ARG BIN_HOME=$MICRO_HOME/bin
+ARG USERS_HOME=/opt/aaihome
 
-RUN apt-get update
-
-# Install and setup java8
-RUN apt-get update && apt-get install -y software-properties-common
-## sudo -E is required to preserve the environment. If you remove that line, it will most like freeze at this step
-RUN sudo -E add-apt-repository ppa:openjdk-r/ppa && apt-get update && apt-get install -y openjdk-8-jdk
-## Setup JAVA_HOME, this is useful for docker commandline
-ENV JAVA_HOME /usr/lib/jvm/java-8-openjdk-amd64
-RUN export JAVA_HOME
-
-# Build up the deployment folder structure
-RUN mkdir -p $MICRO_HOME
-RUN mkdir -p $MICRO_HOME/bundleconfig/etc
-COPY gizmo.jar $MICRO_HOME/
-RUN mkdir -p $BIN_HOME
-COPY *.sh $BIN_HOME
-COPY bundleconfig-local $MICRO_HOME/bundleconfig
-COPY bundleconfig-local/etc/logback.xml $MICRO_HOME/bundleconfig/etc
-RUN chmod 755 $BIN_HOME/*
-
-# Changes related to:AAI-2177
-# Change aai gizmo container processes to run as non-root on the host
+# AAI-2177: Change aai gizmo container processes to run as non-root on the host
 
 #Note:The group id and user id used below (492382 & 341790 respectively) are chosen arbitarily based on assumption that
 # these are not used elsewhere. Please see  https://jira.onap.org/browse/AAI-2172 for more background on this.
 
-RUN mkdir /opt/aaihome && \
-     groupadd -g 492382 aaiadmin && \
-     useradd -r -u 341790  -g 492382 -ms /bin/sh -d /opt/aaihome/aaiadmin aaiadmin && \
-     chown -R aaiadmin:aaiadmin $MICRO_HOME &&\
-     mkdir /logs && \
-     chown -R aaiadmin:aaiadmin  /logs
+RUN mkdir -p $MICRO_HOME $USERS_HOME /logs \
+    && groupadd -g 492382 aaiadmin \
+    && useradd -r -u 341790  -g 492382 -ms /bin/sh -d $USERS_HOME/aaiadmin aaiadmin
+WORKDIR $MICRO_HOME
+COPY /maven/gizmo/ .
+RUN chmod 755 $BIN_HOME/* \
+    && ln -snf /logs $MICRO_HOME/logs \
+    && chown -R aaiadmin:aaiadmin $MICRO_HOME /logs
 
 USER aaiadmin
 
-RUN ln -s /logs $MICRO_HOME/logs
-
 EXPOSE 9520 9520
 
 CMD ["/opt/app/crud-api/bin/start.sh"]
index b28ba3a..5cb8dc6 100644 (file)
  */
 package org.onap.crud.event.response;
 
-import static org.assertj.core.api.Assertions.assertThat;
-import org.junit.BeforeClass;
+import com.google.gson.Gson;
+import com.google.gson.JsonParser;
+import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
+import org.junit.runner.RunWith;
+import org.mockito.junit.MockitoJUnitRunner;
+import org.onap.crud.OXMModelLoaderSetup;
 import org.onap.crud.event.GraphEvent;
 import org.onap.crud.event.GraphEvent.GraphEventOperation;
 import org.onap.crud.event.envelope.GraphEventEnvelope;
@@ -32,29 +36,30 @@ import org.onap.crud.exception.CrudException;
 import org.onap.crud.util.TestUtil;
 import org.onap.schema.EdgeRulesLoader;
 import org.onap.schema.OxmModelLoader;
-import com.google.gson.Gson;
-import com.google.gson.JsonParser;
 
-import org.junit.runner.RunWith;
-import org.mockito.junit.MockitoJUnitRunner;
-import org.onap.crud.OXMModelLoaderSetup;
+import static org.assertj.core.api.Assertions.assertThat;
 
 @RunWith(MockitoJUnitRunner.Silent.class)
 public class GraphEventResponseHandlerTest extends OXMModelLoaderSetup {
+    private static boolean setUpIsNotDone = true;
+    
+    @Before
+    public void setUpOnce() throws CrudException {
+        if (setUpIsNotDone) {
+            System.setProperty("CONFIG_HOME", "src/test/resources");
+            System.setProperty("AJSC_HOME", ".");
+            System.setProperty("BUNDLECONFIG_DIR", "src/test/resources/bundleconfig-local");
+
+            OxmModelLoader.loadModels();
+            EdgeRulesLoader.loadModels();
+
+            setUpIsNotDone = false;
+        }
+    }
 
     @Rule
     public ExpectedException expectedException = ExpectedException.none();
 
-    @BeforeClass
-    public static void setUpBeforeClass() throws Exception {
-        System.setProperty("CONFIG_HOME", "src/test/resources");
-        System.setProperty("AJSC_HOME", ".");
-        System.setProperty("BUNDLECONFIG_DIR", "src/test/resources/bundleconfig-local");
-
-        OxmModelLoader.loadModels();
-        EdgeRulesLoader.loadModels();
-    }
-
     @Test
     public void testPolicyViolationsNotDetected() throws Exception {
         String expectedEnvelope = TestUtil.getFileAsString("event/event-envelope-sentinel-no-violations.json");