Improve docker compose setup 10/142310/14
authorFiete Ostkamp <fiete.ostkamp@telekom.de>
Thu, 23 Oct 2025 09:43:32 +0000 (11:43 +0200)
committerFiete Ostkamp <fiete.ostkamp@telekom.de>
Thu, 23 Oct 2025 12:49:38 +0000 (14:49 +0200)
- add start_period and check intervals to healthcheck in compose
- log error message when reading the config file fails

Issue-ID: MULTICLOUD-1522
Change-Id: I3ca1f4c33accba5a5b6329e7e84343fc4b6ac055
Signed-off-by: Fiete Ostkamp <fiete.ostkamp@telekom.de>
deployments/build.sh
deployments/docker-compose.yml
deployments/k8sconfig.json [new file with mode: 0644]
deployments/start.sh
kud/tests/_functions.sh
kud/tests/plugin.sh
src/k8splugin/internal/config/config.go

index 0ffd77c..3a228f8 100755 (executable)
@@ -19,7 +19,6 @@ export IMAGE_NAME="nexus3.onap.org:10003/onap/multicloud/k8s"
 
 function _compile_src {
     echo "Compiling source code"
-    ls
     pushd $k8s_path/src/k8splugin/
     pwd
     # mount directory and build in container (thus not relying on the state of the runner)
index af8c990..525c2ab 100644 (file)
@@ -9,56 +9,54 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-version: '3'
-
+# network_mode: host is necessary because
+# the multicloud-k8s needs to be able to access the
+# kubernetes cluster that is running on the host (in the pipeline)
 services:
+  mongo-service:
+    container_name: mongo-service
+    image: nexus3.onap.org:10001/mongo:5.0.28
+    healthcheck:
+      test: ["CMD", "mongosh", "--eval", "db.adminCommand('ping')"]
+      interval: 10s
+      timeout: 3s
+      retries: 3
+      start_period: 10s
+    network_mode: host
+    # ports:
+    #   - 27017:27017
+    restart: always
+  etcd-service:
+    container_name: etcd-service
+    image: nexus3.onap.org:10001/bitnami/etcd:3
+    environment:
+      - ALLOW_NONE_AUTHENTICATION=yes
+    volumes:
+      - etcd_data:/bitnami/etcd
+    network_mode: host
+    # ports:
+    #   - 2379:2379
+    #   - 2380:2380
   multicloud-k8s:
     image: ${IMAGE_NAME}
     build:
       context: ./
-      args:
-        - HTTP_PROXY=${HTTP_PROXY}
-        - HTTPS_PROXY=${HTTPS_PROXY}
-        - NO_PROXY=${NO_PROXY}
-    environment:
-      - HTTP_PROXY=${HTTP_PROXY}
-      - HTTPS_PROXY=${HTTPS_PROXY}
-      - NO_PROXY=${NO_PROXY},mongo
     depends_on:
-      mongo:
+      mongo-service:
         condition: service_healthy
+    # ports:
+    #   - 9015:9015
     network_mode: host
-    ports:
-      - 9015:9015
     volumes:
       - /opt/csar:/opt/csar
       - ${PWD}/k8sconfig.json:/opt/multicloud/k8splugin/k8sconfig.json:ro
     restart: always
     healthcheck:
       test: ["CMD", "curl", "http://localhost:9015/v1"]
-  mongo:
-    image: nexus3.onap.org:10001/mongo:5.0.28
-    environment:
-      - HTTP_PROXY=${HTTP_PROXY}
-      - HTTPS_PROXY=${HTTPS_PROXY}
-      - NO_PROXY=${NO_PROXY}
-    healthcheck:
-      test: ["CMD", "mongosh", "--eval", "db.adminCommand('ping')"]
-    ports:
-      - 27017:27017
-    restart: always
-  etcd:
-    image: nexus3.onap.org:10001/bitnami/etcd:3
-    environment:
-      - ALLOW_NONE_AUTHENTICATION=yes
-      - HTTP_PROXY=${HTTP_PROXY}
-      - HTTPS_PROXY=${HTTPS_PROXY}
-      - NO_PROXY=${NO_PROXY}
-    volumes:
-      - etcd_data:/bitnami/etcd
-    ports:
-      - 2379:2379
-      - 2380:2380
+      interval: 10s
+      timeout: 3s
+      retries: 3
+      start_period: 5s
 
 volumes:
   etcd_data:
diff --git a/deployments/k8sconfig.json b/deployments/k8sconfig.json
new file mode 100644 (file)
index 0000000..59db2a4
--- /dev/null
@@ -0,0 +1,9 @@
+{
+    "database-address": "localhost",
+    "database-ip": "localhost",
+    "etcd-ip": "localhost",
+    "database-type": "mongo",
+    "plugin-dir": "plugins",
+    "service-port": "9015"
+
+}
index 61af504..aca7d10 100755 (executable)
@@ -18,7 +18,5 @@ source _functions.sh
 # Start k8splugin from containers. build.sh should be run prior this script.
 #
 stop_all
-start_mongo
-generate_k8sconfig
 start_all
 wait_for_service
index 6d24602..9a01fcf 100755 (executable)
@@ -91,11 +91,16 @@ function call_api {
         return 2
     else
         echo "[INFO] Server replied with status: ${status}" >&2
-        cat "${curl_response_file}"
-        rm "${curl_response_file}"
         if [[ "${status:0:1}" =~ [45] ]]; then
+            echo $(cat "${curl_response_file}") >&2
+            echo $(docker compose logs -f $WORKSPACE/deployments/docker-compose.yml --tail=30 multicloud-k8s) >&2
+            # `cat` determines the return value on stdout for the caller here
+            cat "${curl_response_file}"
+            rm "${curl_response_file}"
             return 1
         else
+            cat "${curl_response_file}"
+            rm "${curl_response_file}"
             return 0
         fi
     fi
index 816a4d8..d1c2efc 100755 (executable)
@@ -86,10 +86,13 @@ print_msg "Upload Resource Bundle Definition Content"
 call_api --data-binary "@${CSAR_DIR}/${csar_id}/vault-consul-dev-0.0.0.tgz" "${base_url}/rb/definition/$rb_name/$rb_version/content"
 
 print_msg "Listing Resource Bundle Definitions"
+sleep 2
 rb_list=$(call_api "${base_url}/rb/definition/$rb_name")
 if [[ "$rb_list" != *"${rb_name}"* ]]; then
     echo $rb_list
     echo "Resource Bundle Definition not stored"
+    echo "Last container logs: "
+    echo $(docker compose -f $WORKSPACE/deployments/docker-compose.yml logs --tail=30 multicloud-k8s) >&2
     exit 1
 fi
 
index 89f2553..235732f 100644 (file)
@@ -48,6 +48,7 @@ var gConfig *Configuration
 func readConfigFile(file string) (*Configuration, error) {
        f, err := os.Open(file)
        if err != nil {
+               log.Printf("Error loading config file: %v. Using defaults.", err)
                return defaultConfiguration(), err
        }
        defer f.Close()
@@ -96,7 +97,7 @@ func GetConfiguration() *Configuration {
        if gConfig == nil {
                conf, err := readConfigFile("k8sconfig.json")
                if err != nil {
-                       log.Println("Error loading config file. Using defaults.")
+                       log.Printf("Error loading config file: %v", err)
                }
                gConfig = conf
        }