def build()

in benchmarking/pipemode_benchmark/script.py [0:0]


    def build(self, sdist_path):
        """Build the script into a docker image and upload to ECR.

        Args:
              sdist_path (str): The path to a sagemaker_tensorflow sdist .tar.gz that will be benchmarked.
        """
        # Copy in the sdist into a docker build directory
        docker_build_dir = ".docker-build-{}".format(self.name)
        if os.path.exists(docker_build_dir):
            shutil.rmtree(docker_build_dir)

        # Copy everything in the docker package data into the docker build dir
        docker_install_dir = '/' + '/'.join(list(__file__.split('/')[:-1]) + ['docker/'])
        shutil.copytree(docker_install_dir, docker_build_dir)

        # Copy sagemaker_tensorflow sdist
        sdist_name = os.path.basename(sdist_path)
        sdist_dest = "{}/{}".format(docker_build_dir, sdist_name)
        shutil.copyfile(sdist_path, sdist_dest)

        tf_version = sdist_name.split("-")[1][:3]

        client = docker.from_env()
        ecr_client = boto3.client('ecr', region_name=region_helper.region)
        token = ecr_client.get_authorization_token()
        username, password = base64.b64decode(token['authorizationData'][0]['authorizationToken']).decode().split(':')
        tag = "{}:{}".format(self.repository, self.tag)
        print "Pulling base image {}".format(FROM_IMAGE)
        client.images.pull(FROM_IMAGE, auth_config={'username': username, 'password': password})
        print "Building image {}".format(tag)
        client.images.build(
            path=docker_build_dir,
            tag=tag,
            buildargs={'sagemaker_tensorflow': sdist_name,
                       'device': self.device,
                       'tf_version': tf_version,
                       'script': self.script_name})
        print "Push image"
        client.images.push(tag,
                           auth_config={'username': username, 'password': password})
        print "Image pushed, cleaning up"
        shutil.rmtree(docker_build_dir)