Dockerize the service 80/114680/4
authorClaudio David Gasparini <claudio.gasparini@pantheon.tech>
Sun, 8 Nov 2020 21:18:36 +0000 (22:18 +0100)
committerClaudio David Gasparini <claudio.gasparini@pantheon.tech>
Tue, 10 Nov 2020 11:54:44 +0000 (11:54 +0000)
- automatically generate docker image
- provide docker-compose to start the service
  together with dockerized postgres db

Issue-ID: CPS-22
Signed-off-by: Claudio David Gasparini <claudio.gasparini@pantheon.tech>
Change-Id: I846d14e87de50bfb1411e0c9b49e9f6c6cc8ebda

Dockerfile [deleted file]
cps-parent/pom.xml
cps-rest/pom.xml
docker-compose/README.md [new file with mode: 0644]
docker-compose/docker-compose.yml [new file with mode: 0644]

diff --git a/Dockerfile b/Dockerfile
deleted file mode 100644 (file)
index 81fdf16..0000000
+++ /dev/null
@@ -1 +0,0 @@
-FROM openjdk:11-jre-slim
\ No newline at end of file
index 0fe2e10..ea9c98a 100644 (file)
     <packaging>pom</packaging>
 
     <properties>
+        <app>org.onap.cps.Application</app>
+        <base.image>openjdk:11-jre-slim</base.image>
         <java.version>11</java.version>
+        <jib-maven-plugin.version>2.6.0</jib-maven-plugin.version>
         <oparent.version>3.1.0</oparent.version>
+        <repository.name>nexus3.onap.org:10001/onap/cps-service</repository.name>
         <spring-boot-maven-plugin.version>2.3.3.RELEASE</spring-boot-maven-plugin.version>
         <swagger-codegen-maven-plugin.version>3.0.18</swagger-codegen-maven-plugin.version>
+        <tag.version>${project.version}</tag.version>
     </properties>
 
     <dependencyManagement>
                     </includes>
                 </configuration>
             </plugin>
+            <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>
+                        <image>${repository.name}</image>
+                        <tags>
+                            <tag>${tag.version}</tag>
+                        </tags>
+                    </to>
+                </configuration>
+                <executions>
+                    <execution>
+                        <phase>package</phase>
+                        <id>build</id>
+                        <goals>
+                            <goal>dockerBuild</goal>
+                        </goals>
+                    </execution>
+                    <!-- FIXME Enable this once migrated to onap,
+                    <execution>
+                        <phase>deploy</phase>
+                        <id>buildAndPush</id>
+                        <goals>
+                            <goal>build</goal>
+                        </goals>
+                    </execution>-->
+                </executions>
+            </plugin>
         </plugins>
     </build>
 </project>
\ No newline at end of file
index 3c92a4e..fc3e632 100644 (file)
                 <groupId>org.springframework.boot</groupId>\r
                 <artifactId>spring-boot-maven-plugin</artifactId>\r
             </plugin>\r
+            <plugin>\r
+                <groupId>com.google.cloud.tools</groupId>\r
+                <artifactId>jib-maven-plugin</artifactId>\r
+            </plugin>\r
             <!-- Swagger code generation. -->\r
             <plugin>\r
                 <groupId>io.swagger.codegen.v3</groupId>\r
diff --git a/docker-compose/README.md b/docker-compose/README.md
new file mode 100644 (file)
index 0000000..d23f033
--- /dev/null
@@ -0,0 +1,3 @@
+```bash
+VERSION=0.0.1-SNAPSHOT DB_HOST=localhost DB_USERNAME=cps DB_PASSWORD=cps docker-compose up
+```
\ No newline at end of file
diff --git a/docker-compose/docker-compose.yml b/docker-compose/docker-compose.yml
new file mode 100644 (file)
index 0000000..6894d3f
--- /dev/null
@@ -0,0 +1,26 @@
+version: "3.7"
+
+services:
+  cps:
+    restart: unless-stopped
+    image: nexus3.onap.org:10001/onap/cps-service:${VERSION}
+    container_name: cps-service
+    environment:
+      DB_HOST: ${DB_HOST}
+      DB_USERNAME: ${DB_USERNAME}
+      DB_PASSWORD: ${DB_PASSWORD}
+    ports:
+      - "8080:8080"
+    network_mode: "host
+    depends_on:
+      - dbpostgresql
+
+  dbpostgresql:
+    container_name: dbpostgresql
+    image: postgres
+    ports:
+      - '5432:5432'
+    environment:
+      DB_NAME: cpsdb
+      DB_USERNAME: ${DB_USERNAME}
+      DB_PASSWORD: ${DB_PASSWORD}
\ No newline at end of file