Fix to docker import issues and swagger error

This is actually two fixes in one change:
1. Fixing the import issues in the docker containers, also cleaning
   it up.
2. Avoiding the creation of multiple swagger.json files by specifying
   which of the proto files represent the top-level service.

Change-Id: I9fec5cf48df127725673ba53f0e91d2ed2e275ad
diff --git a/grpc_client/grpc_client.py b/grpc_client/grpc_client.py
index 9a95330..36618be 100644
--- a/grpc_client/grpc_client.py
+++ b/grpc_client/grpc_client.py
@@ -34,6 +34,7 @@
 from werkzeug.exceptions import ServiceUnavailable
 
 from common.utils.asleep import asleep
+from chameleon.protos import third_party
 from chameleon.protos.schema_pb2 import SchemaServiceStub
 from google.protobuf.empty_pb2 import Empty
 
@@ -101,8 +102,8 @@
             log.info('connecting', endpoint=_endpoint)
             self.channel = grpc.insecure_channel(_endpoint)
 
-            self._retrieve_schema()
-            self._compile_proto_files()
+            swagger_from = self._retrieve_schema()
+            self._compile_proto_files(swagger_from)
             self._clear_backoff()
 
             self.connected = True
@@ -192,8 +193,9 @@
                       length=len(desc_content))
             with open(os.path.join(self.work_dir, desc_fname), 'wb') as f:
                 f.write(desc_content)
+        return schemas.swagger_from
 
-    def _compile_proto_files(self):
+    def _compile_proto_files(self, swagger_from):
         """
         For each *.proto file in the work directory, compile the proto
         file into the respective *_pb2.py file as well as generate the
@@ -211,7 +213,8 @@
         for fname in [f for f in os.listdir(self.work_dir)
                       if f.endswith('.proto')]:
 
-            log.debug('compiling', file=fname)
+            need_swagger = fname == swagger_from
+            log.debug('compiling', file=fname, need_swagger=need_swagger)
             cmd = (
                 'cd %s && '
                 'env PATH=%s PYTHONPATH=%s '
@@ -223,7 +226,7 @@
                 '--plugin=protoc-gen-gw=%s/gw_gen.py '
                 '--gw_out=. '
                 '--plugin=protoc-gen-swagger=%s/swagger_gen.py '
-                '--swagger_out=. '
+                '%s'
                 '%s' % (
                     self.work_dir,
                     ':'.join([os.environ['PATH'], self.plugin_dir]),
@@ -231,6 +234,7 @@
                     google_api_dir,
                     self.plugin_dir,
                     self.plugin_dir,
+                    '--swagger_out=. ' if need_swagger else '',
                     fname)
             )
             log.debug('executing', cmd=cmd, file=fname)