marcoabreu commented on a change in pull request #9943: [Don't MERGE] CI 2.0, 
revamp ci scripts and dockerfiles, integrate IoT builds
URL: https://github.com/apache/incubator-mxnet/pull/9943#discussion_r171600359
 
 

 ##########
 File path: ci/build.py
 ##########
 @@ -0,0 +1,181 @@
+#!/usr/bin/env python3
+# -*- coding: utf-8 -*-
+
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you 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.
+
+"""Multi arch dockerized build tool.
+
+"""
+
+__author__ = 'Marco de Abreu, Kellen Sunderland, Anton Chernov, Pedro Larroy'
+__version__ = '0.1'
+
+import os
+import sys
+import subprocess
+import logging
+import argparse
+from subprocess import check_call, call
+import glob
+import re
+from typing import *
+from itertools import chain
+from copy import deepcopy
+
+
+
+def get_platforms(path: Optional[str]="docker"):
+    """Get a list of architectures given our dockerfiles"""
+    dockerfiles = glob.glob(os.path.join(path, "Dockerfile.build.*"))
+    dockerfiles = list(filter(lambda x: x[-1] != '~', dockerfiles))
+    files = list(map(lambda x: re.sub(r"Dockerfile.build.(.*)", r"\1", x), 
dockerfiles))
+    files.sort()
+    platforms = list(map(lambda x: os.path.split(x)[1], files))
+    return platforms
+
+
+def get_docker_tag(platform: str) -> None:
+    return "mxnet/build.{0}".format(platform)
+
+
+def get_dockerfile(platform: str, path="docker"):
+    return os.path.join(path, "Dockerfile.build.{0}".format(platform))
+
+def get_docker_binary(use_nvidia_docker: bool):
+    if use_nvidia_docker:
+        return "nvidia-docker"
+    else:
+        return "docker"
+
+def build_docker(platform: str, docker_binary: str) -> None:
+    """Build a container for the given platform"""
+    tag = get_docker_tag(platform)
+    logging.info("Building container tagged '%s' with %s", tag, docker_binary)
+    cmd = [docker_binary, "build",
+        "-f", get_dockerfile(platform),
+        "-t", tag,
+        "."]
+    logging.info("Running command: '%s'", ' '.join(cmd))
+    check_call(cmd)
+
+def get_mxnet_root() -> str:
+    curpath = os.path.abspath(os.path.dirname(__file__))
+    def is_mxnet_root(path: str) -> bool:
+        return os.path.exists(os.path.join(path, ".mxnet_root"))
+    while not is_mxnet_root(curpath):
+        parent = os.path.abspath(os.path.join(curpath, os.pardir))
+        if parent == curpath:
+            raise RuntimeError("Got to the root and couldn't find a parent 
folder with .mxnet_root")
+        curpath = parent
+    return curpath
+
+
+def container_run(platform: str, docker_binary: str, command: List[str]) -> 
None:
+    tag = get_docker_tag(platform)
+    mx_root = get_mxnet_root()
+    local_build_folder = '{}/build_{}'.format(mx_root, platform)
+    # We need to create it first, otherwise it will be created by the docker 
daemon with root only permissions
+    os.makedirs(local_build_folder, exist_ok=True)
+    logging.info("Running %s in container %s", command, tag)
+    runlist = [docker_binary, 'run', '--rm',
 
 Review comment:
   Added, thanks

----------------------------------------------------------------
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:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to