Add missing libmd0 library to POL dockerfile
[osm/devops.git] / tools / local-build.sh
index 9f872d2..cbaa87a 100755 (executable)
 
 APT_PROXY=""
 DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
-HTTPDDIR="$( cd "${HOME}/snap/qhttp/common" &> /dev/null && pwd )"
+HTTPDDIR="${HOME}/.osm/httpd"
 HTTPPORT=8000
 KUBECFG="~/.osm/microk8s-config.yaml"
 NO_CACHE=""
 OPENSTACKRC="/var/snap/microstack/common/etc/microstack.rc"
 REGISTRY="localhost:32000"
 ROOTDIR="$( cd "${DIR}/../../" &> /dev/null && pwd)"
+DEVEL_TAG="devel"
 OSM_TESTS_IMAGE_TAG="devel"
 
 function check_arguments(){
@@ -32,11 +33,13 @@ function check_arguments(){
         case $1 in
             --debug) set -x ;;
             --apt-proxy) APT_PROXY="$2" && shift ;;
+            --devel-tag) DEVEL_TAG="$2" && shift ;;
             --help | -h) show_help && exit 0 ;;
-            --httpddir) HTTPDIR="$2" && shift;;
+            --httpddir) HTTPDDIR="$2" && shift;;
             --install-local-registry) 'install_local_registry' ;;
             --install-microstack) 'install_microstack' ;;
             --install-qhttpd) INSTALL_HTTPD='install_qhttpd' ;;
+            --run-httpserver) INSTALL_HTTPD='run_httpserver' ;;
             --kubecfg) KUBECFG="$2" && shift ;;
             --module) TARGET_MODULE="$2" && shift;;
             --no-cache) NO_CACHE="--no-cache" ;;
@@ -73,7 +76,8 @@ OPTIONS:
   --debug                       enable set -x for this script
   --install-local-registry      install and enable Microk8s local registry on port 32000
   --install-microstack          install Microstack and configure to run robot tests
-  --install-qhttpd              install QHTTPD as an HTTP server on port ${HTTPPORT}
+  --install-qhttpd              (deprecated, use --run-httpserver instead) install QHTTPD as an HTTP server on port ${HTTPPORT}
+  --run-httpserver              run HTTP server on port ${HTTPPORT}
   --kubecfg                     path to kubecfg.yaml (uses Charmed OSM by default)
   --no-cache                    do not use any cache when building docker images
   --module                      only build this comma delimited list of modules
@@ -102,9 +106,9 @@ Let's assume that we have different repos cloned in the folder workspace:
   git clone "https://osm.etsi.org/gerrit/osm/IM
   git clone "https://osm.etsi.org/gerrit/osm/N2VC
 
-First we install a light HTTP server to serve the artifacts:
+First we run a light HTTP server to serve the artifacts:
 
-  devops/tools/local-build.sh --install-qhttpd
+  devops/tools/local-build.sh --run-httpserver
 
 Then we generate the artifacts (debian packages) for the different repos: common, IM, N2VC, RO, LCM, NBI
 
@@ -166,13 +170,33 @@ function install_microstack() {
          --disk-format=qcow2 ubuntu20.04
 }
 
+function create_httpddir() {
+    mkdir -p ${HTTPDDIR}
+}
+
 function install_qhttpd() {
     sudo snap install qhttp
     EXISTING_PID=$(ps auxw | grep "http.server $HTTPPORT" | grep -v grep | awk '{print $2}')
     if [ ! -z $EXISTING_PID ] ; then
         kill $EXISTING_PID
     fi
-    qhttp -p ${HTTPPORT} &
+    nohup qhttp -p ${HTTPPORT} &
+}
+
+function run_httpserver() {
+    EXISTING_PID=$(ps auxw | grep "http.server $HTTPPORT" | grep -v grep | awk '{print $2}')
+    if [ ! -z $EXISTING_PID ] ; then
+        kill $EXISTING_PID
+    fi
+    nohup python3 -m http.server ${HTTPPORT} --directory "${HTTPDDIR}" &>/dev/null &
+}
+
+function run_httpserver() {
+    EXISTING_PID=$(ps auxw | grep "http.server $HTTPPORT" | grep -v grep | awk '{print $2}')
+    if [ ! -z $EXISTING_PID ] ; then
+        kill $EXISTING_PID
+    fi
+    nohup python3 -m http.server ${HTTPPORT} --directory "${HTTPDDIR}" &>/dev/null &
 }
 
 function stage_2() {
@@ -214,7 +238,7 @@ function stage_2() {
             STAGES="stage-test.sh ${STAGES}"
         fi
         for STAGE in $STAGES ; do
-            docker run -ti \
+            docker run -i \
                 -v "$(pwd):/build" \
                 -w /build \
                 ${MODULE,,}-stage2 \
@@ -226,8 +250,12 @@ function stage_2() {
                 exit 1
             fi
         done
-
-        find . -name '*.deb' -exec mv -v {} ${HTTPDDIR}/ \;
+        for file in `find . -name '*.deb'` ; do
+            name=`basename ${file} | cut -d_ -f1`;
+            rm -v ~/snap/qhttp/common/${name}*
+            cp -v $file ~/snap/qhttp/common/${name}_$(date "+%H%M%S").deb
+            rm -v $file
+        done
     done
 }
 
@@ -258,9 +286,15 @@ function stage_3() {
     fi
 
     HOSTIP=$(ip -4 addr show docker0 | grep -Po 'inet \K[\d.]+')
-    for file in ~/snap/qhttp/common/*.deb ; do
+    [ -z "$DEFAULT_IF" ] && DEFAULT_IF=$(ip route list|awk '$1=="default" {print $5; exit}')
+    [ -z "$DEFAULT_IF" ] && DEFAULT_IF=$(route -n |awk '$1~/^0.0.0.0/ {print $8; exit}')
+    DEFAULT_IP=$(ip -o -4 a s ${DEFAULT_IF} |awk '{split($4,a,"/"); print a[1]; exit}')
+    HOSTIP=${HOSTIP:=${DEFAULT_IP}}
+    echo $HOSTIP
+
+    for file in ${HTTPDDIR}/*.deb ; do
         file=`basename ${file}`
-        name=`echo ${file} | cut -d_ -f1 | sed "s/-/_/g"`;
+        name=`echo ${file} | cut -d_ -f1 | sed "s/-/_/g" | sed "s/.deb//"`;
         name=${name^^}_URL
         BUILD_ARGS="${BUILD_ARGS}--build-arg ${name}=http://$HOSTIP:${HTTPPORT}/$file "
         echo Added ${name} as http://$HOSTIP:${HTTPPORT}/$file
@@ -269,13 +303,13 @@ function stage_3() {
     for MODULE in ${MODULES} ; do
         cd "${ROOTDIR}/devops/docker"
         if [ ! -d ${MODULE} ] ; then
-            echo "Directory ${ROOTDIR}/${MODULE} does not exist"
+            echo "Directory ${ROOTDIR}/devops/docker/${MODULE} does not exist"
             exit 1
         fi
         print_section "Building ${MODULE}"
         cd ${MODULE}
         MODULE=${MODULE,,}
-        docker build ${NO_CACHE} -t opensourcemano/${MODULE}:devel ${BUILD_ARGS} .
+        docker build ${NO_CACHE} -t opensourcemano/${MODULE}:${DEVEL_TAG} ${BUILD_ARGS} .
         if [ $? -ne 0 ] ; then
         print_section "Failed to build ${MODULE}"
             exit 1
@@ -301,8 +335,8 @@ function local_registry_push() {
     fi
     for MODULE in ${MODULES} ; do
         MODULE=${MODULE,,}
-        docker tag opensourcemano/${MODULE}:devel ${REGISTRY}/opensourcemano/${MODULE}:devel
-        docker push ${REGISTRY}/opensourcemano/${MODULE}:devel
+        docker tag opensourcemano/${MODULE}:${DEVEL_TAG} ${REGISTRY}/opensourcemano/${MODULE}:${DEVEL_TAG}
+        docker push ${REGISTRY}/opensourcemano/${MODULE}:${DEVEL_TAG}
     done
 }
 
@@ -312,7 +346,7 @@ function install_osm() {
     if juju controllers 2>/dev/null| grep osm-vca ; then
         VCA="--vca osm-vca"
     fi
-    ./charmed_install.sh --registry localhost:32000  --tag devel ${VCA}
+    ./charmed_install.sh --registry localhost:32000  --tag ${DEVEL_TAG} ${VCA}
 }
 
 function start_robot() {
@@ -412,7 +446,7 @@ function update_osm_module() {
     for MODULE in ${MODULES} ; do
         MODULE=${MODULE,,}
         echo "Updating ${MODULE}"
-        juju attach-resource ${MODULE} image=localhost:32000/opensourcemano/${MODULE}:devel
+        juju attach-resource ${MODULE} ${MODULE}-image=localhost:32000/opensourcemano/${MODULE}:${DEVEL_TAG}
     done
 }
 
@@ -430,6 +464,7 @@ if [ "$0" != "$BASH_SOURCE" ]; then
 else
     check_arguments $@
 
+    create_httpddir
     eval "${INSTALL_HTTPD}"
     eval "${INSTALL_LOCAL_REGISTRY}"
     eval "${INSTALL_MICROSTACK}"