KellenSunderland commented on a change in pull request #12276: [Don't 
merge][Review] A solution to prevent zombie containers locally and in CI
URL: https://github.com/apache/incubator-mxnet/pull/12276#discussion_r211867390
 
 

 ##########
 File path: ci/build.py
 ##########
 @@ -226,19 +393,48 @@ def load_docker_cache(tag, docker_registry) -> None:
     else:
         logging.info('Distributed docker cache disabled')
 
-def main() -> int:
+def ec2_instance_id_hostname() -> str:
+    if under_ci():
+        result = []
+        try:
+            r = 
requests.get("http://instance-data/latest/meta-data/instance-id";)
+            if r.status_code == 200:
+                result.append(r.content.decode())
+            r = 
requests.get("http://instance-data/latest/meta-data/public-hostname";)
+            if r.status_code == 200:
+                result.append(r.content.decode())
+            return ' '.join(result)
+        except ConnectionError as e:
+            pass
+        return '?'
+    else:
+        return ''
+
+def log_environment():
+    instance_id = ec2_instance_id_hostname()
+    if instance_id:
+        logging.info("Instance id: %s", instance_id)
+    pp = pprint.PrettyPrinter(indent=4)
+    logging.info("Build environment: %s", pp.pformat(dict(os.environ)))
+
+def chdir_to_script_directory():
     # We need to be in the same directory than the script so the commands in 
the dockerfiles work as
     # expected. But the script can be invoked from a different path
     base = os.path.split(os.path.realpath(__file__))[0]
     os.chdir(base)
 
-    logging.getLogger().setLevel(logging.INFO)
+def script_name() -> str:
+    return os.path.split(sys.argv[0])[1]
 
-    def script_name() -> str:
-        return os.path.split(sys.argv[0])[1]
 
+def main() -> int:
+    logging.getLogger().setLevel(logging.INFO)
+    logging.getLogger("requests").setLevel(logging.WARNING)
     logging.basicConfig(format='{}: %(asctime)-15s 
%(message)s'.format(script_name()))
 
+    log_environment()
 
 Review comment:
   I'd make this change in a different PR.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to