add docker build 79/1579/1
authorGennadiy Dubina <gennadiy.dubina@dataart.com>
Mon, 3 Apr 2017 17:46:16 +0000 (20:46 +0300)
committergarciadeblas <gerardo.garciadeblas@telefonica.com>
Tue, 18 Apr 2017 08:36:13 +0000 (10:36 +0200)
Signed-off-by: Gennadiy Dubina <gennadiy.dubina@dataart.com>
Makefile
docker/Dockerfile-local [new file with mode: 0644]
docker/openmano-compose.yml [new file with mode: 0644]
docker/scripts/configure.sh [new file with mode: 0755]
docker/scripts/start.sh [new file with mode: 0755]
docker/scripts/wait_db.sh [new file with mode: 0755]
requirements.txt

index 2c7255b..226bcb4 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -2,6 +2,8 @@ SHELL := /bin/bash
 all: pip deb
 
 prepare:
+       pip install setuptools
+       #pip install -r requirements.txt
        mkdir -p build/
        cp MANIFEST.in build/
        cp requirements.txt build/
@@ -52,6 +54,15 @@ sync:
 test:
        ./test/basictest.sh --force --insert-bashrc --install-openvim --init-openvim
 
+build-docker-from-source:
+       docker build -t osm/openmano -f docker/Dockerfile-local .
+
+run-docker:
+       docker-compose -f docker/openmano-compose.yml up
+
+stop-docker:
+       docker-compose -f docker/openmano-compose.yml down
+
 clean:
        rm -rf build
        #find build -name '*.pyc' -delete
diff --git a/docker/Dockerfile-local b/docker/Dockerfile-local
new file mode 100644 (file)
index 0000000..3eaa281
--- /dev/null
@@ -0,0 +1,50 @@
+from ubuntu:xenial
+
+MAINTAINER Gennadiy Dubina <gennadiy.dubina@dataat.com>
+
+# script uses it
+ENV USER=root
+
+#avoid extra information from packages
+RUN echo 'path-exclude /usr/share/doc/*\n\
+path-include /usr/share/doc/*/copyright\n\
+path-exclude /usr/share/man/*\n\
+path-exclude /usr/share/groff/*\n\
+path-exclude /usr/share/info/*\n\
+path-exclude /usr/share/lintian/*\n\
+path-exclude /usr/share/linda/*\n'\
+> /etc/dpkg/dpkg.cfg.d/01_nodoc && \
+    echo  'APT::Install-Recommends "false";\n\
+APT::AutoRemove::RecommendsImportant "false";\n\
+APT::AutoRemove::SuggestsImportant "false";\n'\
+> /etc/apt/apt.conf.d/99_norecommends
+
+#generate lsb_release stub
+RUN echo 'if [ "$1" == "-is" ]; then echo "Ubuntu"; else if [ "$1" == "-rs" ]; then echo "16.04"; fi fi' > /usr/bin/lsb_release && chmod +x /usr/bin/lsb_release
+
+COPY . /usr/local/src/openmano
+
+RUN apt update && \
+  DEBIAN_FRONTEND=noninteractive apt install -fqy software-properties-common make gcc git python python-dev python-pip sudo wget && \
+  pip install --upgrade pip && \
+  cd /usr/local/src/openmano && \
+  make build && \
+  cd build && \
+  ./scripts/install-openmano.sh -q --noclone --no-db && \
+  cd / && \
+  rm -rf /usr/local/src/openmano && \
+  rm -rf /usr/include/* && \
+  rm -rf /root/.cache && \
+  apt purge -y make gcc git curl wget python-dev python-pip && \
+  apt autoremove -y && \ 
+  apt clean && \
+  rm -rf /var/lib/apt/lists/*
+
+COPY docker/scripts/ /opt/openmano-docker
+
+VOLUME /opt/openmano/logs
+EXPOSE 9090
+
+env DB_USER='' DB_PSWD='' DB_HOST='' DB_PORT=3306 DB_NAME=mano_db
+
+CMD /opt/openmano-docker/start.sh
diff --git a/docker/openmano-compose.yml b/docker/openmano-compose.yml
new file mode 100644 (file)
index 0000000..253e957
--- /dev/null
@@ -0,0 +1,31 @@
+version: '2'
+services:
+  osm-ro-db:
+    image: mysql
+    container_name: osm-ro-db
+    restart: always
+    environment:
+      - MYSQL_RANDOM_ROOT_PASSWORD=true
+      - MYSQL_DATABASE=mano_db
+      - MYSQL_USER=mano
+      - MYSQL_PASSWORD=manopw
+  osm-ro:
+    build:
+      context: ../
+      dockerfile: docker/Dockerfile-local
+    image: osm/openmano
+    container_name: osm-ro
+    restart: always
+    environment:
+      - DB_USER=mano
+      - DB_PSWD=manopw
+      - DB_NAME=mano_db
+      - DB_HOST=osm-ro-db    
+    ports:
+      - "9090:9090"
+    volumes:
+      - /var/log/osm/openmano/logs:/opt/openmano/logs
+    depends_on:
+      - osm-ro-db
+    links:
+      - osm-ro-db
\ No newline at end of file
diff --git a/docker/scripts/configure.sh b/docker/scripts/configure.sh
new file mode 100755 (executable)
index 0000000..da7cbba
--- /dev/null
@@ -0,0 +1,12 @@
+#!/bin/bash
+
+#Database parameters
+#db_host:   localhost
+#db_user:   mano
+#db_passwd: manopw
+#db_name:   mano_db
+
+sed -i "s/^db_host:.*/db_host: $DB_HOST/" /opt/openmano/openmanod.cfg
+sed -i "s/^db_user:.*/db_user: $DB_USER/" /opt/openmano/openmanod.cfg
+sed -i "s/^db_passwd:.*/db_passwd: $DB_PSWD/" /opt/openmano/openmanod.cfg
+sed -i "s/^db_name:.*/db_name: $DB_NAME/" /opt/openmano/openmanod.cfg
\ No newline at end of file
diff --git a/docker/scripts/start.sh b/docker/scripts/start.sh
new file mode 100755 (executable)
index 0000000..3d70c3f
--- /dev/null
@@ -0,0 +1,46 @@
+#!/bin/bash
+
+function is_db_created() {
+    db_host=$1
+    db_port=$2
+    db_user=$3
+    db_pswd=$4
+    db_name=$5
+
+    RESULT=`mysqlshow -h"$db_host" -P"$db_port" -u"$db_user" -p"$db_pswd" | grep -v Wildcard | grep -o $db_name`
+    if [ "$RESULT" == "$db_name" ]; then
+
+        RESULT=`mysqlshow -h"$db_host" -P"$db_port" -u"$db_user" -p"$db_pswd" "$db_name" | grep -v Wildcard | grep schema_version`
+        #TODO validate version
+        if [ -n "$RESULT" ]; then
+            echo " DB $db_name exists and inited"
+            return 0
+        else
+            echo " DB $db_name exists BUT not inited"
+            return 1
+        fi
+    fi
+    echo " DB $db_name does not exist"
+    return 1
+}
+
+echo "1/4 Apply config"
+/opt/openmano-docker/configure.sh
+[ $? -ne 0 ] && exit 1
+echo "2/4 Wait for db"
+
+/opt/openmano-docker/wait_db.sh
+[ $? -ne 0 ] && exit 1
+
+echo "3/4 Init database" && \
+is_db_created "$DB_HOST" "$DB_PORT" "$DB_USER" "$DB_PSWD" "$DB_NAME"
+if [ $? -ne 0 ]; then
+    /opt/openmano/database_utils/init_mano_db.sh -u $DB_USER -p $DB_PSWD -h $DB_HOST -P $DB_PORT -d $DB_NAME
+    [ $? -ne 0 ] && exit 1
+else
+    echo "    migrage database version"
+    /opt/openmano/database_utils/migrate_mano_db.sh -u $DB_USER -p $DB_PSWD -h $DB_HOST -P $DB_PORT -d $DB_NAME
+fi
+
+echo "4/4 Try to start"
+/opt/openmano/openmanod.py -c /opt/openmano/openmanod.cfg --log-file=/opt/openmano/logs/openmano.log
\ No newline at end of file
diff --git a/docker/scripts/wait_db.sh b/docker/scripts/wait_db.sh
new file mode 100755 (executable)
index 0000000..f083d76
--- /dev/null
@@ -0,0 +1,14 @@
+#!/bin/bash
+
+attempt=0
+max_attempts=120
+while ! mysqladmin ping -h"$DB_HOST" -P"$DB_PORT" --silent; do
+       #wait 120 sec
+       if [ $attempt -ge $max_attempts ]; then
+               echo "Can not connect to database during $max_attempts sec"
+               exit 1
+       fi
+       attempt=$[$attempt+1]
+       echo "Wait for MySQL Server ${DB_HOST}:${DB_PORT} [attempt $attempt/$max_attempts]"
+    sleep 1
+done
\ No newline at end of file
index 38c055c..eb92478 100644 (file)
@@ -1,5 +1,3 @@
---index-url https://pypi.python.org/simple/
-
 PyYAML
 bottle
 MySQL-python