Refactor the container startup process 70/141070/2
authorsourabh_sourabh <sourabh.sourabh@est.tech>
Tue, 3 Jun 2025 14:16:31 +0000 (15:16 +0100)
committersourabh_sourabh <sourabh.sourabh@est.tech>
Tue, 3 Jun 2025 14:35:49 +0000 (15:35 +0100)
- Echo build information of DMI container before proceeding.
- This enhances script efficiency and reduces unnecessary output, improving readability and maintainability.

Issue-ID: 2690
Change-Id: I3bda6433bd2126e180017db7d349fa1eeb33526a
Signed-off-by: sourabh_sourabh <sourabh.sourabh@est.tech>
k6-tests/setup.sh

index 3d486a9..6a233ce 100755 (executable)
 #
 
 testProfile=$1
-echo "Spinning off the CPS and NCMP containers for $testProfile testing..."
-
 ENV_FILE="../docker-compose/env/${testProfile}.env"
-docker-compose \
-  --file "../docker-compose/cps-base.yml" \
-  --env-file "$ENV_FILE" \
-  --project-name "$testProfile" \
-  up --quiet-pull --detach --wait || exit 1
-
-if [[ "$testProfile" == "kpi" ]]; then
-  ACTUATOR_PORT=8883
-elif [[ "$testProfile" == "endurance" ]]; then
-  ACTUATOR_PORT=8884
-fi
-
-echo "Build information:"
-curl --silent --show-error http://localhost:$ACTUATOR_PORT/actuator/info
+COMPOSE_FILE="../docker-compose/cps-base.yml"
+
+# Define a function to encapsulate docker-compose command
+compose() {
+  docker-compose \
+    --file "$COMPOSE_FILE" \
+    --env-file "$ENV_FILE" \
+    --project-name "$testProfile" "$@"
+}
+
+# Start the containers
 echo
+echo "Spinning off the following containers for '$testProfile'..."
+echo
+compose up --quiet-pull --detach --wait || { echo "Failed to start containers."; exit 1; }
+
+# Define port mappings based on the test profile
+declare -A CPS_PORTS=( ["kpi"]=8883 ["endurance"]=8884 )
+declare -A DMI_DEMO_STUB_PORTS=( ["kpi"]=8784 ["endurance"]=8787 )
+
+CPS_ACTUATOR_PORT="${CPS_PORTS[$testProfile]}"
+DMI_DEMO_STUB_ACTUATOR_PORT="${DMI_DEMO_STUB_PORTS[$testProfile]}"
+
+# Function to fetch and display build information
+fetch_build_info() {
+  local service_name="$1"
+  local port="$2"
+  local url="http://localhost:${port}/actuator/info"
+
+  echo -e "\n${service_name} Build Information:"
+  if curl --silent --show-error "$url"; then
+    echo
+  else
+    echo "Error: Unable to retrieve ${service_name} build information from ${url}"
+    exit 1
+  fi
+}
+
+# Fetch and display build information for CPS and DMI
+fetch_build_info "CPS and NCMP" "$CPS_ACTUATOR_PORT"
+fetch_build_info "DMI" "$DMI_DEMO_STUB_ACTUATOR_PORT"
+echo
\ No newline at end of file