Add automation for ADML HTTP image creation
authorEduardo Ramos Testillano (eramedu) <eduardo.ramos.testillano@ericsson.com>
Fri, 8 May 2020 23:20:52 +0000 (01:20 +0200)
committerEduardo Ramos Testillano (eramedu) <eduardo.ramos.testillano@ericsson.com>
Fri, 8 May 2020 23:20:52 +0000 (01:20 +0200)
Also improve stuff to centralize build image procedure
and fix the shift issue for parameters passing.

New INSTALL_ADML_HTTP.md help for ADML HTTP deployment and
image creation/running.

.gitignore
INSTALL_ADML_HTTP.md [new file with mode: 0644]
docker-images/anna-adml-http/Dockerfile [new file with mode: 0644]
docker-images/anna-adml-http/etc/nginx/conf.d/default.conf [new file with mode: 0644]
docker-images/anna-adml-http/etc/nginx/nginx.conf [new file with mode: 0644]
docker-images/anna-adml-http/starter.sh [new file with mode: 0644]
tools/build-adml-http [new file with mode: 0755]
tools/build-with-docker
tools/docker.src [new file with mode: 0755]

index d25c0b9..f6e986a 100644 (file)
@@ -31,3 +31,6 @@ Testing/
 install_manifest.txt
 CMakeDoxyfile.in
 CMakeDoxygenDefaults.cmake
+
+# Deployments
+docker-images/anna-adml-http/opt/
diff --git a/INSTALL_ADML_HTTP.md b/INSTALL_ADML_HTTP.md
new file mode 100644 (file)
index 0000000..785c4dd
--- /dev/null
@@ -0,0 +1,21 @@
+# ADML with REST Interface (ADML-HTTP)
+
+## Deployment
+
+Execute 'example/diameter/launcher/deploy-adml-http.sh' and follow instructions.
+
+## Enabling HTTP2 Service
+
+This is done through nginx proxy configured as reverse proxy to translate `HTTP2` traffic coming to port *8074* towards *localhost* port *8000* where `ADML HTTP` is going to serve the *HTTP1.1* Rest Service.
+
+To build the docker image, execute this script:
+
+> tools/build-adml-http [variant: [Release]|Debug]
+
+## Running docker image
+
+> docker run --rm -d --network host --name adml-http anna-adml-http:<version>
+
+## Monitoring ADML traces
+
+> docker exec -it adml-http tail -F /opt/adml/launcher.trace
\ No newline at end of file
diff --git a/docker-images/anna-adml-http/Dockerfile b/docker-images/anna-adml-http/Dockerfile
new file mode 100644 (file)
index 0000000..fb75eb6
--- /dev/null
@@ -0,0 +1,7 @@
+FROM nginx
+COPY etc/ /etc
+COPY opt/adml/ /opt/adml
+
+COPY starter.sh /var/starter.sh
+
+CMD ["sh", "/var/starter.sh"]
diff --git a/docker-images/anna-adml-http/etc/nginx/conf.d/default.conf b/docker-images/anna-adml-http/etc/nginx/conf.d/default.conf
new file mode 100644 (file)
index 0000000..0471e4f
--- /dev/null
@@ -0,0 +1,14 @@
+server {
+  listen 8074 http2;
+  listen [::]:8075 http2;
+  #It is possible to enable another port for pure HTTP11:
+  #listen 8073;
+  #listen [::]:8073;
+
+  server_name localhost;
+
+  location / {
+      proxy_pass http://localhost:8000/;
+  }
+}
+
diff --git a/docker-images/anna-adml-http/etc/nginx/nginx.conf b/docker-images/anna-adml-http/etc/nginx/nginx.conf
new file mode 100644 (file)
index 0000000..baf4c19
--- /dev/null
@@ -0,0 +1,29 @@
+user  nginx;
+worker_processes auto;
+
+error_log  /var/log/nginx/error.log warn;
+pid        /var/run/nginx.pid;
+
+events {
+    worker_connections  1024;
+}
+
+http {
+    # https://stackoverflow.com/questions/13895933/nginx-emerg-could-not-build-the-server-names-hash-you-should-increase-server/50813859
+    server_names_hash_bucket_size 64; 
+
+    include       /etc/nginx/mime.types;
+    default_type  application/octet-stream;
+
+    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
+                      '$status $body_bytes_sent "$http_referer" '
+                      '"$http_user_agent" "$http_x_forwarded_for"';
+
+    access_log  /var/log/nginx/access.log  main;
+
+    sendfile        on;
+    #tcp_nopush     on;
+    #gzip  on;
+
+    include /etc/nginx/conf.d/*.conf;
+}
diff --git a/docker-images/anna-adml-http/starter.sh b/docker-images/anna-adml-http/starter.sh
new file mode 100644 (file)
index 0000000..c5c64ab
--- /dev/null
@@ -0,0 +1,8 @@
+#!/bin/sh
+
+# Start ADML agent:
+cd /opt/adml
+./start.sh
+
+# Execute nginx server:
+exec $(which nginx) -c /etc/nginx/nginx.conf -g "daemon off;"
diff --git a/tools/build-adml-http b/tools/build-adml-http
new file mode 100755 (executable)
index 0000000..5f635c2
--- /dev/null
@@ -0,0 +1,33 @@
+#!/bin/bash
+
+#############
+# VARIABLES #
+#############
+
+REPO_DIR="$(git rev-parse --show-toplevel 2>/dev/null)"
+[ -z "$REPO_DIR" ] && { echo "You must execute under a valid git repository !" ; exit 1 ; }
+
+IMAGEDIR=${REPO_DIR}/docker-images/anna-adml-http
+AD=${IMAGEDIR}/opt/adml
+
+#############
+# EXECUTION #
+#############
+
+TAG=$(${REPO_DIR}/tools/version)
+
+# Docker build functions
+source ${REPO_DIR}/tools/docker.src
+
+# Deploy Anna-ADML-HTTP:
+rm -rf ${AD}
+echo ${AD} | ${REPO_DIR}/example/diameter/launcher/deploy-adml-http.sh
+
+echo
+echo "Generate docker image ..."
+build_image ${IMAGEDIR} ${TAG} ${IMAGEDIR}
+
+echo
+echo "Done !"
+echo
+
index f649209..1fc7fdb 100755 (executable)
@@ -8,31 +8,7 @@ REPO_DIR="$(git rev-parse --show-toplevel 2>/dev/null)"
 [ -z "$REPO_DIR" ] && { echo "You must execute under a valid git repository !" ; exit 1 ; }
 
 VARIANT=${1:-Release}
-
-#############
-# FUNCTIONS #
-#############
-
-# $1: image directory
-build_image() {
-  local imgdir=$1
-
-  local imgname=$(basename ${imgdir})
-  local imgtag=${TAG}
-
-  echo "Building ${imgname}:${imgtag} ..."
-  cd ${imgdir}
-
-  # Dockerfile for other contexts:
-  local dck_opt=
-  local preferred=Dockerfile.$(arch)
-  [ -f ${preferred} ] && { dck_opt="-f ${preferred}" ; echo "Selected '${preferred}' for current architecture." ; }
-  [ -z "${dck_opt}" -a ! -f Dockerfile ] && { echo "No Dockerfile for this directory. Ignoring ..." ; cd - >/dev/null ; return 1 ; }
-
-  docker build -t ${imgname}:${imgtag} ${dck_opt} .
-  [ $? -ne 0 ] && { echo "An error ocurred. Aborting ..." ; cd - >/dev/null ; return 1 ; }
-  cd - >/dev/null
-}
+ENVS="-e VARIANT=${VARIANT}"
 
 #############
 # EXECUTION #
@@ -44,9 +20,12 @@ echo
 
 TAG=$(${REPO_DIR}/tools/version)
 
+# Docker build functions
+source ${REPO_DIR}/tools/docker.src
+
 # Build compilation image:
-build_image ${REPO_DIR}/docker-images/anna-build-nodb # this image has neither oracle nor mysql installed
+build_image ${REPO_DIR}/docker-images/anna-build-nodb ${TAG} # this image has neither oracle nor mysql installed
 
 # Build source with previous compilation image:
-docker run --rm -it -u $(id -u):$(id -g) -e VARIANT=${VARIANT} -v ${REPO_DIR}:/code -w /code anna-build-nodb:${TAG}
+docker run --rm -it -u $(id -u):$(id -g) ${ENVS} -v ${REPO_DIR}:/code -w /code anna-build-nodb:${TAG}
 
diff --git a/tools/docker.src b/tools/docker.src
new file mode 100755 (executable)
index 0000000..228c07f
--- /dev/null
@@ -0,0 +1,25 @@
+#!/bin/echo "source me !"
+
+# $1: image directory; $2: image tag; $3: Dockerfile parent dir ('.' by default); $4: build context ('.' by default); $5: extra arguments (quoted)
+build_image() {
+  local imgdir=$1
+  local imgtag=$2
+  local dckdir=${3:-.}
+  local ctxdir=${4:-.}
+  local xtra=$5
+
+  local imgname=$(basename ${imgdir})
+
+  echo "Building ${imgname}:${imgtag} ..."
+  cd ${imgdir}
+
+  # Dockerfile for other contexts:
+  local dck_opt="-f ${dckdir}/Dockerfile"
+  local preferred=${dckdir}/Dockerfile.$(arch)
+  [ -f ${preferred} ] && { dck_opt="-f ${preferred}" ; echo "Selected '${preferred}' for current architecture." ; }
+
+  docker build -t ${imgname}:${imgtag} ${xtra} ${dck_opt} ${ctxdir}
+  [ $? -ne 0 ] && { echo "An error ocurred. Aborting ..." ; cd - >/dev/null ; return 1 ; }
+  cd - >/dev/null
+}
+