From: Eduardo Ramos Testillano (eramedu) Date: Wed, 13 May 2020 23:21:21 +0000 (+0200) Subject: Allow passing arguments to ADML-HTTP docker image entrypoint X-Git-Url: https://git.teslayout.com/public/public/public/?a=commitdiff_plain;h=26c27c2b83f99e6df420addc90010eb0d4a7724e;p=anna.git Allow passing arguments to ADML-HTTP docker image entrypoint Modify entrypoint/cmd on adml-http image to allow provide extra arguments to the entrypoint. Also, the starter script will forward de arguments $@ towards ADML start.sh script, so parameters like 'ft' or 'st' are now possible to specify on docker run statement (ft by default). Allow parametrize the build variant in ct.sh script. In this way we could test Release or Debug variant. The ADML start.sh argument is set to 'st' to avoid trace generation and traffic log. Rebuild question is now 'n' by default. Docker tag will be suffixed with '-debug' for Debug, and unchanged for Release. In the same way, the container name is changed to to know easily what is being deployed. Anyway, nginx port will collide and then both cannot be started expect if 8074 port is changed in any of them. When configuring services in ct.sh script, we will parse the response to know the success state (true/false) in order to interrupt the component test procedure in case of fail. Also, in this script, a bug is fixed: pgrep is not being escaped, and the $(pgrep ADML) is going to be evaluated on host. --- diff --git a/INSTALL_ADML_HTTP.md b/INSTALL_ADML_HTTP.md index e4f9320..e3aa9ae 100644 --- a/INSTALL_ADML_HTTP.md +++ b/INSTALL_ADML_HTTP.md @@ -14,7 +14,9 @@ To build the docker image, execute this script: ## Running docker image -> docker run --rm -d -p 8074:8074 --name anna-adml-http anna-adml-http: +> docker run --rm -d -p 8074:8074 --name anna-adml-http anna-adml-http: [entrypoint arguments: <[ft]|st>] + +Entrypoint arguments are passed to ADML start script (`/opt/adml/start.sh` inside the container), and are mainly preconfigured variants for `ADML` command-line arguments. So, `ft` stands for `function test` (debug traces, traffic logs in real time, etc.) and `st` is `system test` (warning level for traces, no traffic logs dumped, etc.). Service port is **8074**. diff --git a/docker-images/anna-adml-http/Dockerfile b/docker-images/anna-adml-http/Dockerfile index 68b3467..c08c1e1 100644 --- a/docker-images/anna-adml-http/Dockerfile +++ b/docker-images/anna-adml-http/Dockerfile @@ -11,4 +11,5 @@ COPY starter.sh /var/starter.sh EXPOSE 8074 WORKDIR /opt/adml -CMD ["sh", "/var/starter.sh"] +ENTRYPOINT ["sh", "/var/starter.sh"] +CMD [] diff --git a/docker-images/anna-adml-http/starter.sh b/docker-images/anna-adml-http/starter.sh index c5c64ab..cd4c629 100644 --- a/docker-images/anna-adml-http/starter.sh +++ b/docker-images/anna-adml-http/starter.sh @@ -2,7 +2,7 @@ # Start ADML agent: cd /opt/adml -./start.sh +./start.sh $@ # Execute nginx server: exec $(which nginx) -c /etc/nginx/nginx.conf -g "daemon off;" diff --git a/example/diameter/launcher/resources/rest_api/ct/ct.sh b/example/diameter/launcher/resources/rest_api/ct/ct.sh index 3fe561d..f51f0d1 100755 --- a/example/diameter/launcher/resources/rest_api/ct/ct.sh +++ b/example/diameter/launcher/resources/rest_api/ct/ct.sh @@ -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