Add dockerfile for MDG's

- Added option to installer to use specfic docker build tag

Change-Id: Ia6cf6316c6fb84a18ecdbaf98747a95c20ce2f0b
Signed-off-by: Mike Marchetti <mmarchetti@sandvine.com>
diff --git a/docker/mk/Makefile.include b/docker/mk/Makefile.include
new file mode 100644
index 0000000..ceaacaa
--- /dev/null
+++ b/docker/mk/Makefile.include
@@ -0,0 +1,51 @@
+TOPDIR=$(shell readlink -f .|sed -e 's/\/docker\/.*//')
+MKINCLUDE=$(TOPDIR)/docker/mk
+MKBUILD=$(TOPDIR)/docker/build
+
+all: build
+
+TAG ?= latest
+
+REPOSITORY_BASE ?= http://osm-download.etsi.org/repository/osm/debian
+RELEASE         ?= ReleaseFOUR-daily
+REPOSITORY_KEY  ?= OSM%20ETSI%20Release%20Key.gpg
+REPOSITORY      ?= testing
+NO_CACHE        ?= --no-cache
+
+LOWER_MDG = $(shell echo $(MDG) | tr '[:upper:]' '[:lower:]')
+
+CMD_DOCKER_ARGS ?= -q
+DOCKER_ARGS     = $(CMD_DOCKER_ARGS)
+
+DEPS := MON IM LCM RO common osmclient devops NBI
+
+DEPS_TARGETS = $(addprefix $(MKBUILD)/.dep_, $(DEPS))
+
+Q=@
+
+$(MKBUILD):
+	$Qmkdir -p $(MKBUILD)
+
+$(MKBUILD)/.dep_%:
+	$Q$(MKINCLUDE)/get_version.sh -m $* > $@
+
+build: $(MKBUILD) $(DEPS_TARGETS)
+	$Qdocker build -t osm/$(LOWER_MDG):$(TAG) \
+                   --build-arg RELEASE=$(RELEASE) \
+                   --build-arg REPOSITORY=$(REPOSITORY) \
+                   --build-arg REPOSITORY_KEY=$(REPOSITORY_KEY) \
+                   --build-arg REPOSITORY_BASE=$(REPOSITORY_BASE) \
+                   --build-arg MON_VERSION==$(shell cat $(MKBUILD)/.dep_MON) \
+                   --build-arg IM_VERSION==$(shell cat $(MKBUILD)/.dep_IM) \
+                   --build-arg RO_VERSION==$(shell cat $(MKBUILD)/.dep_RO) \
+                   --build-arg LCM_VERSION==$(shell cat $(MKBUILD)/.dep_LCM) \
+                   --build-arg COMMON_VERSION==$(shell cat $(MKBUILD)/.dep_common) \
+                   --build-arg OSMCLIENT_VERSION==$(shell cat $(MKBUILD)/.dep_osmclient) \
+                   --build-arg NBI_VERSION==$(shell cat $(MKBUILD)/.dep_NBI) \
+                   $(DOCKER_ARGS) .
+
+clean:
+	rm -f $(MKBUILD)/.dep*
+
+tag:
+	docker tag osm/$(LOWER_MDG) osm/$(LOWER_MDG):$(TAG)
diff --git a/docker/mk/dirs.mk b/docker/mk/dirs.mk
new file mode 100644
index 0000000..53846cc
--- /dev/null
+++ b/docker/mk/dirs.mk
@@ -0,0 +1,47 @@
+#
+#   Copyright 2017 Sandvine
+#
+#   Licensed under the Apache License, Version 2.0 (the "License");
+#   you may not use this file except in compliance with the License.
+#   You may obtain a copy of the License at
+#
+#       http://www.apache.org/licenses/LICENSE-2.0
+#
+#   Unless required by applicable law or agreed to in writing, software
+#   distributed under the License is distributed on an "AS IS" BASIS,
+#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#   See the License for the specific language governing permissions and
+#   limitations under the License.
+#
+
+TOPDIR=$(shell readlink -f .|sed -e 's/\/descriptor-packages\/.*//')
+TOOLS_DIR := $(TOPDIR)/tools
+
+SUBDIRS_CLEAN = $(addsuffix .clean, $(SUBDIRS))
+SUBDIRS_TEST = $(addsuffix .test, $(SUBDIRS))
+SUBDIRS_TAG = $(addsuffix .tag, $(SUBDIRS))
+
+.PHONY: $(SUBDIRS) $(SUBDIRS_CLEAN) clean test tag
+
+all: $(SUBDIRS)
+
+clean: $(SUBDIRS_CLEAN)
+
+test: $(SUBDIRS_TEST)
+
+tag: $(SUBDIRS_TAG)
+
+$(SUBDIRS_CLEAN): %.clean:
+	@$(MAKE) --no-print-directory -C $* clean
+
+$(SUBDIRS_TEST): %.test:
+	@$(MAKE) --no-print-directory -C $* test
+
+$(SUBDIRS_TAG): %.tag:
+	@$(MAKE) --no-print-directory -C $* tag 
+
+$(SUBDIRS):
+	@$(MAKE) --no-print-directory -C $@
+
+test:
+	$(TOOLS_DIR)/launch_tests.sh
diff --git a/docker/mk/get_version.sh b/docker/mk/get_version.sh
new file mode 100755
index 0000000..8b6e1cd
--- /dev/null
+++ b/docker/mk/get_version.sh
@@ -0,0 +1,49 @@
+#!/bin/sh
+
+RELEASE="ReleaseFOUR-daily"
+REPOSITORY_KEY="OSM%20ETSI%20Release%20Key.gpg"
+REPOSITORY="testing"
+REPOSITORY_BASE="http://osm-download.etsi.org/repository/osm/debian"
+DEBUG=
+
+while getopts ":r:k:u:R:b:-:dm:" o; do
+    case "${o}" in
+        r)
+            REPOSITORY=${OPTARG}
+            ;;
+        R)
+            RELEASE=${OPTARG}
+            ;;
+        k)
+            REPOSITORY_KEY=${OPTARG}
+            ;;
+        u)
+            REPOSITORY_BASE=${OPTARG}
+            ;;
+        d)
+            DEBUG=y
+            ;;
+        m)
+            MDG=${OPTARG}
+            ;;
+        -)
+            ;;
+    esac
+done
+
+if [ -z "$MDG" ]; then
+    echo "missing MDG"
+fi
+
+if [ -n "$DEBUG" ]; then
+    echo curl $REPOSITORY_BASE/$RELEASE/dists/$REPOSITORY/$MDG/binary-amd64/Packages
+fi
+
+curl $REPOSITORY_BASE/$RELEASE/dists/$REPOSITORY/$MDG/binary-amd64/Packages 2>/dev/null | awk -v mdg=$MDG '{
+    if ( /Package:/ && match($2,tolower(mdg)) ) {
+        package=1;
+    } else if (package==1 && match($1,"Version:")) { 
+        package=0; 
+        printf("%s\n", $2);
+    }
+}' | head -1