VOL-1554 Updated to use LOCAL_PROTOS for including protos. Also changed to a single base dockerfile.
Cleaned out some stuff that was used for building protos, that we no longer need

Change-Id: Ibfe88bba8e553e8d6c4d9d5b6a59a9860a6f2651
diff --git a/.gitignore b/.gitignore
index 5fd0857..4c5dacf 100644
--- a/.gitignore
+++ b/.gitignore
@@ -63,6 +63,4 @@
 python/cli/.voltha_cli_history
 
 # Development versions of locally built libraries
-python/pyvoltha
-python/voltha-protos
-
+python/local_imports
diff --git a/python/Makefile b/python/Makefile
index ec8b91d..a78ecda 100644
--- a/python/Makefile
+++ b/python/Makefile
@@ -43,6 +43,10 @@
 	 --rm --force-rm \
 	$(DOCKER_BUILD_EXTRA_ARGS)
 
+DOCKER_BUILD_EXTRA_ARGS = \
+	--build-arg LOCAL_PYVOLTHA=$(LOCAL_PYVOLTHA) \
+	--build-arg LOCAL_PROTOS=$(LOCAL_PROTOS)
+
 DOCKER_IMAGE_LIST = \
 	voltha-openonu-adapter-base \
 	voltha-openonu-adapter
@@ -75,15 +79,16 @@
 containers: base openonu_adapter
 
 base:
+	mkdir -p local_imports
 ifdef LOCAL_PYVOLTHA
-	mkdir -p pyvoltha/dist
-	cp ../../pyvoltha/dist/*.tar.gz pyvoltha/dist/
-	mkdir -p voltha-protos/dist
-	cp ../../voltha-protos/dist/*.tar.gz voltha-protos/dist/
-	docker build $(DOCKER_BUILD_ARGS) -t ${REGISTRY}${REPOSITORY}voltha-openonu-adapter-base:${TAG} -f docker/Dockerfile.base_local .
-else
-	docker build $(DOCKER_BUILD_ARGS) -t ${REGISTRY}${REPOSITORY}voltha-openonu-adapter-base:${TAG} -f docker/Dockerfile.base .
+	mkdir -p local_imports/pyvoltha/dist
+	cp ../../pyvoltha/dist/*.tar.gz local_imports/pyvoltha/dist/
 endif
+ifdef LOCAL_PROTOS
+	mkdir -p local_imports/voltha-protos/dist
+	cp ../../voltha-protos/dist/*.tar.gz local_imports/voltha-protos/dist/
+endif
+	docker build $(DOCKER_BUILD_ARGS) -t ${REGISTRY}${REPOSITORY}voltha-openonu-adapter-base:${TAG} -f docker/Dockerfile.base .
 
 openonu_adapter: base
 ifdef PYVOLTHA_BASE_IMAGE
@@ -108,8 +113,7 @@
 	docker pull ${REGISTRY}${REPOSITORY}voltha-$(subst .pull,,$@):${TAG}
 
 clean:
-	rm -rf pyvoltha
-	rm -rf voltha-protos
+	rm -rf local_imports
 	find . -name '*.pyc' | xargs rm -f
 
 distclean: clean
@@ -137,12 +141,15 @@
 	    fi
 
 ifdef LOCAL_PYVOLTHA
-	mkdir -p pyvoltha/dist
-	cp ../../pyvoltha/dist/*.tar.gz pyvoltha/dist/
-	mkdir -p voltha-protos/dist
-	cp ../../voltha-protos/dist/*.tar.gz voltha-protos/dist/
+	mkdir -p local_imports/pyvoltha/dist
+	cp ../../pyvoltha/dist/*.tar.gz local_imports/pyvoltha/dist/
 	. ${VENVDIR}/bin/activate && \
-	    pip install pyvoltha/dist/*.tar.gz && \
-	    pip install voltha-protos/dist/*.tar.gz
+	    pip install local_imports/pyvoltha/dist/*.tar.gz
+endif
+ifdef LOCAL_PROTOS
+	mkdir -p local_imports/voltha-protos/dist
+	cp ../../voltha-protos/dist/*.tar.gz local_imports/voltha-protos/dist/
+	. ${VENVDIR}/bin/activate && \
+	    pip install local_protos/voltha-protos/dist/*.tar.gz
 endif
 # end file
diff --git a/python/docker/Dockerfile.base b/python/docker/Dockerfile.base
index 898f7fa..bd38702 100644
--- a/python/docker/Dockerfile.base
+++ b/python/docker/Dockerfile.base
@@ -16,6 +16,9 @@
 
 MAINTAINER Voltha Community <info@opennetworking.org>
 
+ARG LOCAL_PYVOLTHA
+ARG LOCAL_PROTOS
+
 # Update to have latest images
 RUN apt-get update && \
     apt-get install -y python openssl iproute2 libpcap-dev wget build-essential git binutils python-dev libffi-dev libssl-dev 
@@ -28,3 +31,13 @@
 COPY requirements.txt /tmp/requirements.txt
 RUN pip install -r /tmp/requirements.txt
 
+#COPY POTENTIAL LOCAL IMPORTS
+COPY local_imports/ /local_imports/
+
+RUN if [ -n "$LOCAL_PYVOLTHA" ] ; then \
+    pip install /local_imports/pyvoltha/dist/*.tar.gz ; \
+fi
+
+RUN if [ -n "$LOCAL_PROTOS" ] ; then \
+    pip install /local_imports/voltha-protos/dist/*.tar.gz ; \
+fi
diff --git a/python/docker/Dockerfile.base_local b/python/docker/Dockerfile.base_local
deleted file mode 100644
index 6944d5c..0000000
--- a/python/docker/Dockerfile.base_local
+++ /dev/null
@@ -1,37 +0,0 @@
-# Copyright 2016 the original author or authors.
-#
-# 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.
-
-FROM ubuntu:xenial
-
-MAINTAINER Voltha Community <info@opennetworking.org>
-
-# Update to have latest images
-RUN apt-get update && \
-    apt-get install -y python openssl iproute2 libpcap-dev wget build-essential git binutils python-dev libffi-dev libssl-dev 
-
-# Install current version of pip rather than outdated pip from apt
-RUN wget -O /tmp/get-pip.py https://bootstrap.pypa.io/get-pip.py
-RUN python /tmp/get-pip.py
-
-# Install adapter requirements. 
-COPY requirements.txt /tmp/requirements.txt
-RUN pip install -r /tmp/requirements.txt
-
-# Install local pyvoltha
-COPY pyvoltha/dist /pyvoltha/dist
-RUN pip install /pyvoltha/dist/*.tar.gz
-
-COPY voltha-protos/dist /voltha-protos/dist
-RUN pip install /voltha-protos/dist/*.tar.gz
-
diff --git a/python/docker/Dockerfile.protoc b/python/docker/Dockerfile.protoc
deleted file mode 100644
index eef6f54..0000000
--- a/python/docker/Dockerfile.protoc
+++ /dev/null
@@ -1,39 +0,0 @@
-# Copyright 2018 the original author or authors.
-#
-# 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.
-
-ARG REGISTRY=
-ARG PROTOC_PREFIX=/usr/local
-ARG ROTOC_LIBDIR=${PROTOC_PREFIX}/lib
-ARG PROTOC=${PROTOC_PREFIX}/bin/protoc
-ARG PROTOC_VERSION=3.3.0
-
-FROM ${REGISTRY}debian:stretch-slim
-MAINTAINER Voltha Community <info@opennetworking.org>
-
-ENV PROTOC_PREFIX=/usr/local
-ENV ROTOC_LIBDIR=${PROTOC_PREFIX}/lib
-ENV PROTOC=${PROTOC_PREFIX}/bin/protoc
-ENV PROTOC_VERSION=3.3.0
-ENV PROTOC_DOWNLOAD_PREFIX=https://github.com/google/protobuf/releases/download
-ENV PROTOC_DIR=protobuf-${PROTOC_VERSION}
-ENV PROTOC_TARBALL=protobuf-python-${PROTOC_VERSION}.tar.gz
-ENV PROTOC_DOWNLOAD_URI=${PROTOC_DOWNLOAD_PREFIX}/v${PROTOC_VERSION}/${PROTOC_TARBALL}
-
-RUN apt-get update -y && apt-get install -y wget build-essential python-dev python-pip
-RUN pip install grpcio-tools==1.3.5
-WORKDIR /build
-RUN wget -q --no-check-certificate ${PROTOC_DOWNLOAD_URI}
-RUN tar --strip-components=1 -zxf ${PROTOC_TARBALL}
-RUN ./configure --prefix=${PROTOC_PREFIX}
-RUN make install
diff --git a/python/docker/Dockerfile.protos b/python/docker/Dockerfile.protos
deleted file mode 100644
index db70d13..0000000
--- a/python/docker/Dockerfile.protos
+++ /dev/null
@@ -1,36 +0,0 @@
-# Copyright 2018 the original author or authors.
-#
-# 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.
-
-ARG REGISTRY=
-ARG REPOSITORY=
-ARG TAG=latest
-
-FROM ${REGISTRY}${REPOSITORY}voltha-protoc:${TAG} as builder
-MAINTAINER Voltha Community <info@opennetworking.org>
-
-COPY protos/third_party/google/api/*.proto /protos/google/api/
-COPY docker/config/Makefile.protos /protos/google/api/Makefile.protos
-COPY protos/*.proto /protos/voltha/
-COPY docker/config/Makefile.protos /protos/voltha/Makefile.protos
-
-WORKDIR /protos
-RUN make -f google/api/Makefile.protos google_api
-RUN touch /protos/google/__init__.py /protos/google/api/__init__.py
-
-WORKDIR /protos/voltha
-RUN make -f Makefile.protos build
-
-# Copy the files to a scrach based container to minimize its size
-FROM ${REGISTRY}scratch
-COPY --from=builder /protos/ /protos/
diff --git a/python/docker/config/Makefile.protos b/python/docker/config/Makefile.protos
deleted file mode 100644
index 12ff9e3..0000000
--- a/python/docker/config/Makefile.protos
+++ /dev/null
@@ -1,59 +0,0 @@
-#
-# Copyright 2017 the original author or authors.
-#
-# 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.
-#
-
-# Makefile to build all protobuf and gRPC related artifacts
-
-default: build
-
-PROTO_FILES := $(wildcard *.proto)
-PROTO_ALL_FILES := $(PROTO_FILES) $(PROTO_GOOGLE_API)
-PROTO_PB2_FILES := $(foreach f,$(PROTO_FILES),$(subst .proto,_pb2.py,$(f)))
-PROTO_PB2_GOOGLE_API := $(foreach f,$(PROTO_GOOGLE_API),$(subst .proto,_pb2.py,$(f)))
-PROTO_All_PB2_C_FILES := $(foreach f,$(PROTO_ALL_FILES),$(subst .proto,_pb2.pyc,$(f)))
-PROTO_ALL_PB2_GPRC_FILES := $(foreach f,$(PROTO_ALL_FILES),$(subst .proto,_pb2_grpc.py,$(f)))
-PROTO_ALL_DESC_FILES := $(foreach f,$(PROTO_ALL_FILES),$(subst .proto,.desc,$(f)))
-
-# Google API needs to be built from within the third party directory
-#
-google_api:
-	python -m grpc.tools.protoc \
-	    -I. \
-            --python_out=. \
-            --grpc_python_out=. \
-            --descriptor_set_out=google/api/annotations.desc \
-            --include_imports \
-            --include_source_info \
-        google/api/annotations.proto google/api/http.proto
-
-build: $(PROTO_PB2_FILES)
-
-%_pb2.py: %.proto
-	python -m grpc.tools.protoc \
-                -I. \
-                -I/protos \
-                --python_out=. \
-                --grpc_python_out=. \
-                --descriptor_set_out=$(basename $<).desc \
-                --include_imports \
-                --include_source_info \
-                $<
-
-clean:
-	rm -f $(PROTO_PB2_FILES) \
-		$(PROTO_ALL_DESC_FILES) \
-		$(PROTO_ALL_PB2_GPRC_FILES) \
-		$(PROTO_All_PB2_C_FILES) \
-		$(PROTO_PB2_GOOGLE_API)