Provide docker compose for temporal service 77/121077/4
authorRishi.Chail <rishi.chail@est.tech>
Tue, 4 May 2021 15:34:09 +0000 (16:34 +0100)
committerRishi.Chail <rishi.chail@est.tech>
Thu, 6 May 2021 14:00:20 +0000 (15:00 +0100)
Added docker image (200Mb)
Added docker compose to start with timescale db

Issue-ID: CPS-359

Signed-off-by: Rishi.Chail <rishi.chail@est.tech>
Change-Id: I47120edcea78730405086eca393fbc08a41e0745

.gitignore [changed mode: 0644->0755]
README.md [changed mode: 0644->0755]
docker-compose.yml [new file with mode: 0755]
pom.xml [changed mode: 0644->0755]
src/main/resources/application.yml [changed mode: 0644->0755]

old mode 100644 (file)
new mode 100755 (executable)
index 6609c05..cd944e3
@@ -29,4 +29,12 @@ build/
 .vscode/
 
 ### MAC OS ###
-.DS_Store
\ No newline at end of file
+.DS_Store
+
+### Eclipse ###
+.settings/
+bin/
+tmp/
+.metadata
+*.tmp
+.checkstyle
\ No newline at end of file
old mode 100644 (file)
new mode 100755 (executable)
index 45ebd4e..d7d200e
--- a/README.md
+++ b/README.md
@@ -1,8 +1,34 @@
-# CPS Temporal Service
+# Building and running CPS Temporal locally
 
-For now, this repo contains a very minimalist skeleton of the application.
+## Building Java Archive only
 
-## Local DB setup
+Following command builds Java executable jar to `target/cps-temporal-x.y.z-SNAPSHOT` JAR file
+without generating any docker images:
+
+```bash
+mvn clean install
+```
+
+## Building Java Archive and local Docker image
+
+Following command builds the JAR file and also generates the Docker image:
+
+```bash
+mvn clean install -Pcps-temporal-docker -Ddocker.repository.push=
+```
+
+## Running via Docker Compose
+
+`docker-compose.yml` file is provided to be run with `docker-compose` tool and local image previously built.
+It starts both Postgres Timescale database and CPS Temporal service.
+
+Execute following command from project root folder:
+
+```bash
+docker-compose up -d
+```
+
+## Alternative local db setup
 
 A Postgres instance with Timescale extension can be started by running the following command:
 
diff --git a/docker-compose.yml b/docker-compose.yml
new file mode 100755 (executable)
index 0000000..fae1cbc
--- /dev/null
@@ -0,0 +1,43 @@
+# ============LICENSE_START=======================================================
+# Copyright (C) 2021 Nordix Foundation.
+# ================================================================================
+# 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.
+# ============LICENSE_END=========================================================
+
+version: "3.7"
+
+services:
+
+  cps-temporal:
+    container_name: cps-temporal
+    image: onap/cps-temporal:latest
+    ports:
+      - '8082:8080'
+    environment:
+      DB_HOST: timescaledb
+      DB_PORT: 5432
+      DB_USERNAME: cpstemporal
+      DB_PASSWORD: cpstemporal
+    restart: unless-stopped
+    depends_on:
+      - timescaledb
+
+  timescaledb:
+    container_name: timescaledb
+    image: timescale/timescaledb:2.1.1-pg13
+    ports:
+      - '5432:5432'
+    environment:
+      POSTGRES_DB: cpstemporaldb
+      POSTGRES_USER: ${DB_USERNAME}
+      POSTGRES_PASSWORD: ${DB_PASSWORD}
diff --git a/pom.xml b/pom.xml
old mode 100644 (file)
new mode 100755 (executable)
index 49dce9f..5579823
--- a/pom.xml
+++ b/pom.xml
@@ -2,6 +2,7 @@
 <!--
   ============LICENSE_START=======================================================
   Copyright (c) 2021 Bell Canada.
+  Modifications Copyright (C) 2021 Nordix Foundation.
   ================================================================================
   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
     <description>CPS Temporal Service</description>
 
     <properties>
+        <app>org.onap.cps.temporal.Application</app>
+        <docker.repository.pull>nexus3.onap.org:10001/</docker.repository.pull>
+        <docker.repository.push>nexus3.onap.org:10003/</docker.repository.push>
+        <image.base>${docker.repository.pull}onap/integration-java11:8.0.0</image.base>
+        <image.name>${docker.repository.push}onap/cps-temporal</image.name>
         <java.version>11</java.version>
         <minimum-coverage>0.8</minimum-coverage>
         <cps.checkstyle.version>1.0.1</cps.checkstyle.version>
         <cps.spotbugs.version>1.0.1</cps.spotbugs.version>
+        <jib-maven-plugin.version>3.0.0</jib-maven-plugin.version>
+        <maven.build.timestamp.format>yyyyMMdd'T'HHmmss'Z'</maven.build.timestamp.format>
         <oparent.version>3.2.0</oparent.version>
         <spotbugs-maven-plugin.version>4.1.3</spotbugs-maven-plugin.version>
         <spotbugs.slf4j.version>1.8.0-beta4</spotbugs.slf4j.version>
                 </executions>
             </plugin>
         </plugins>
+
+       <pluginManagement>
+            <plugins>
+                <plugin>
+                    <groupId>com.google.cloud.tools</groupId>
+                    <artifactId>jib-maven-plugin</artifactId>
+                    <version>${jib-maven-plugin.version}</version>
+                    <configuration>
+                        <container>
+                            <mainClass>${app}</mainClass>
+                            <creationTime>USE_CURRENT_TIMESTAMP</creationTime>
+                        </container>
+                        <from>
+                            <image>${base.image}</image>
+                        </from>
+                        <to>
+                            <tags>
+                                <tag>latest</tag>
+                            </tags>
+                            <image>${image.name}:${project.version}-${maven.build.timestamp}</image>
+                        </to>
+                    </configuration>
+                    <executions>
+                        <execution>
+                            <phase>package</phase>
+                            <id>build</id>
+                            <goals>
+                                <goal>dockerBuild</goal>
+                            </goals>
+                        </execution>
+                        <execution>
+                            <phase>deploy</phase>
+                            <id>buildAndPush</id>
+                            <goals>
+                                <goal>build</goal>
+                            </goals>
+                        </execution>
+                    </executions>
+                </plugin>
+            </plugins>
+        </pluginManagement>
     </build>
+
+    <profiles>
+        <profile>
+            <id>cps-temporal-docker</id>
+            <build>
+                <plugins>
+                    <plugin>
+                        <groupId>com.google.cloud.tools</groupId>
+                        <artifactId>jib-maven-plugin</artifactId>
+                    </plugin>
+                </plugins>
+            </build>
+        </profile>
+    </profiles>
 </project>
old mode 100644 (file)
new mode 100755 (executable)
index 0db1792..ff70e46
@@ -1,5 +1,6 @@
 # ============LICENSE_START=======================================================
 # Copyright (c) 2021 Bell Canada.
+# Modifications Copyright (C) 2021 Nordix Foundation.
 # ================================================================================
 # Licensed under the Apache License, Version 2.0 (the "License");
 # you may not use this file except in compliance with the License.
@@ -16,7 +17,7 @@
 
 spring:
     datasource:
-        url: jdbc:postgresql://${DB_HOST}:${DB_PORT}/${DB_NAME}
+        url: jdbc:postgresql://${DB_HOST}:${DB_PORT}/cpstemporaldb
         username: ${DB_USERNAME}
         password: ${DB_PASSWORD}
     liquibase: