Allow passing arguments to ADML-HTTP docker image entrypoint
[anna.git] / example / diameter / launcher / resources / rest_api / ct / ct.sh
index 3fe561d..f51f0d1 100755 (executable)
@@ -11,10 +11,21 @@ SERVICES=${REPO_DIR}/example/diameter/launcher/resources/rest_api/ct/resources/s
 ENDPOINT=http://localhost:8074
 PORT=$(echo ${ENDPOINT} | cut -d: -f3)
 C_NAME=anna-adml-http
+# Entrypoint arguments (ft/st):
+EXTRA_ARGUMENTS= # default is ft (function test: debug traces and traffic logs)
+EXTRA_ARGUMENTS=st
+
+VARIANT=${1:-Release}
 
 #############
 # EXECUTION #
 #############
+
+echo
+echo "Variant: ${VARIANT}"
+echo "Remember usage: $0 [variant: <[Release]|Debug]>"
+echo
+
 cd $(dirname $0)
 
 # Basic requirement:
@@ -23,28 +34,41 @@ nghttp --version 2>/dev/null
 echo "Requirement found !"
 
 echo
-echo "Rebuild ADML HTTP service image (y/n) [y]:"
+echo "Rebuild ADML HTTP service image (y/n) [n]:"
 read opt
-[ -z "${opt}" ] && opt=y
-[ "${opt}" = "y" ] && ${REPO_DIR}/tools/build-anna-adml-http
+[ -z "${opt}" ] && opt=n
+if [ "${opt}" = "y" ]
+then
+  ${REPO_DIR}/tools/build-anna-adml-http ${VARIANT}
+fi
 
 version=$(${REPO_DIR}/tools/version)
+[ "${VARIANT}" = "Debug" ] && { version=${version}-debug ; C_NAME=${C_NAME}-debug ; }
 echo "Restart ADML HTTP service image (version '${version}') ..."
-docker kill ${C_NAME} >/dev/null
-cid=$(docker run --rm -d -p ${PORT}:${PORT} --name ${C_NAME} anna-adml-http:${version})
+docker kill ${C_NAME} &>/dev/null
+cid=$(docker run --rm -d -p ${PORT}:${PORT} --name ${C_NAME} anna-adml-http:${version} ${EXTRA_ARGUMENTS} >/dev/null)
+[ $? -ne 0 ] && exit 1
+
 echo "Container id: ${cid} (deployed as '${C_NAME}')"
 
 echo
 echo "Configuring services (${SERVICES}) ..."
 sleep 4 # wait for docker running
-nghttp -H ":method: POST" -d ${SERVICES} ${ENDPOINT}/services
-echo
+nghttp -H ":method: POST" -d ${SERVICES} ${ENDPOINT}/services | tee .response.json | jq '.'
+result=$(cat .response.json | jq -r '.["success"]')
+rm .response.json
+if [ "${result}" = "false" ]
+then
+  echo
+  echo "Check if another ADML HTTP service (anna-adml-http*) has been started (port ${PORT} busy ?)"
+  exit 1
+fi
 
 echo
 echo -n "Waiting for server-client connection ..."
 while true
 do
-  docker exec -it ${C_NAME} bash -c "netstat -p $(pgrep ADML) --numeric-ports | grep -w 3868 | grep -w ESTABLISHED" >/dev/null
+  docker exec -it ${C_NAME} bash -c "netstat -p \$(pgrep ADML) --numeric-ports | grep -w 3868 | grep -w ESTABLISHED" >/dev/null
   [ $? -eq 0 ] && break
   echo -n .
   sleep 1