Removing temporal from LCM
[osm/devops.git] / tools / local-build.sh
index f471e03..ab4b147 100755 (executable)
 # limitations under the License.
 #######################################################################################
 
+APT_PROXY=""
 DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
 HTTPDDIR="$( cd "${HOME}/snap/qhttp/common" &> /dev/null && pwd )"
-HTTPPORT=11480
+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(){
     while [ $# -gt 0 ] ; do
         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;;
             --install-local-registry) 'install_local_registry' ;;
@@ -67,8 +71,9 @@ same process as Jenkins.
 
 OPTIONS:
   --help                        display this help message
+  --apt-proxy                   provide an apt proxy to docker build steps
   --debug                       enable set -x for this script
-  --install-local-registry     install and enable Microk8s local registry on port 32000
+  --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}
   --kubecfg                     path to kubecfg.yaml (uses Charmed OSM by default)
@@ -85,6 +90,34 @@ OPTIONS:
   install-osm                   perform full installation of Charmed OSM from registry
   start-robot                   start the Robot test container and leave you at prompt
   update-install                update Charmed OSM with new module container
+
+A typical use could be the following:
+
+Let's assume that we have different repos cloned in the folder workspace:
+
+  cd workspace
+  git clone https://osm.etsi.org/gerrit/osm/devops
+  git clone https://osm.etsi.org/gerrit/osm/NBI
+  git clone https://osm.etsi.org/gerrit/osm/LCM
+  git clone "https://osm.etsi.org/gerrit/osm/RO
+  git clone "https://osm.etsi.org/gerrit/osm/common
+  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:
+
+  devops/tools/local-build.sh --install-qhttpd
+
+Then we generate the artifacts (debian packages) for the different repos: common, IM, N2VC, RO, LCM, NBI
+
+  devops/tools/local-build.sh --module common,IM,N2VC,RO,LCM,NBI stage-2
+
+Then new docker images are generated locally with the tag "devel" (e.g.: opensourcemano/lcm:devel):
+
+  devops/tools/local-build.sh --module RO,LCM,NBI stage-3
+
+Finally, the deployment of OSM will have to be updated to use the new docker images.
+
 EOF
 }
 
@@ -137,16 +170,16 @@ function install_microstack() {
 
 function install_qhttpd() {
     sudo snap install qhttp
-    EXISTING_PID=$(ps auxw | grep "http.server 11480" | grep -v grep | awk '{print $2}')
+    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 stage_2() {
     print_section "Performing Stage 2"
-    MODULES="common devops IM LCM MON N2VC NBI NG-UI osmclient PLA POL RO tests"
+    MODULES="common devops IM LCM MON N2VC NBI NG-UI NG-SA osmclient PLA POL RO tests"
     if [ ! -z ${1} ] ; then
         POSSIBLE_MODULES=$(echo ${1} | sed "s/,/ /g")
         for MODULE in ${POSSIBLE_MODULES}; do
@@ -171,14 +204,19 @@ function stage_2() {
         print_section "Building ${MODULE}"
         cd ${MODULE}
         find . -name '*.deb' -exec rm -v {} \;
-        docker build ${NO_CACHE} -t ${MODULE,,}-stage2 .
+
+        BUILD_ARGS=""
+        if [ ! -z $APT_PROXY ] ; then
+            BUILD_ARGS="${BUILD_ARGS}--build-arg APT_PROXY=${APT_PROXY} "
+        fi
+        docker build ${NO_CACHE} ${BUILD_ARGS} -t ${MODULE,,}-stage2 .
 
         STAGES="stage-build.sh"
         if [ ! -z $TESTS ] ; then
             STAGES="stage-test.sh ${STAGES}"
         fi
         for STAGE in $STAGES ; do
-            docker run -ti \
+            docker run -i \
                 -v "$(pwd):/build" \
                 -w /build \
                 ${MODULE,,}-stage2 \
@@ -190,8 +228,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
 }
 
@@ -217,10 +259,14 @@ function stage_3() {
     print_section "Performing Stage 3"
     MODULES=$(_find_module_dockerfile $1)
     BUILD_ARGS=""
+    if [ ! -z $APT_PROXY ] ; then
+        BUILD_ARGS="${BUILD_ARGS}--build-arg APT_PROXY=${APT_PROXY} "
+    fi
+
     HOSTIP=$(ip -4 addr show docker0 | grep -Po 'inet \K[\d.]+')
     for file in ~/snap/qhttp/common/*.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
@@ -229,13 +275,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
@@ -261,8 +307,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
 }
 
@@ -272,7 +318,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() {
@@ -359,7 +405,8 @@ EOF
         -v "$(pwd)/robot.etc.hosts":/etc/hosts \
         -v ~/.osm/microk8s-config.yaml:/root/.kube/config \
         -v "$(pwd)/clouds.yaml":/etc/openstack/clouds.yaml \
-        -v "$(pwd)/reports:"/robot-systest/reports \
+        -v "${HOME}/snap/qhttp/common"/robot-systest/reports \
+        -v "${HOME}/snap/qhttp/common:"/robot-systest/conformance-tests/reports \
         -v "${ROOTDIR}/tests/robot-systest/lib":${LOCAL_MOUNT_1} \
         -v "${ROOTDIR}/tests/robot-systest/resources":${LOCAL_MOUNT_2} \
         -v "${ROOTDIR}/tests/robot-systest/testsuite":${LOCAL_MOUNT_3} \
@@ -371,7 +418,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
 }