# Copyright 2017-2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"). You # may not use this file except in compliance with the License. A copy of # the License is located at # # http://aws.amazon.com/apache2.0/ # # or in the "license" file accompanying this file. This file 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 __future__ import absolute_import import os import subprocess import sys CYAN_COLOR = '\033[36m' END_COLOR = '\033[0m' def build_base_image(framework_name, framework_version, processor, base_image_tag, cwd='.'): base_image_uri = get_base_image_uri(framework_name, base_image_tag) dockerfile_location = os.path.join('docker', framework_version, 'base', 'Dockerfile.{}'.format(processor)) build_directory = os.path.dirname(dockerfile_location) subprocess.check_call( ['docker', 'build', '-t', base_image_uri, '-f', dockerfile_location, build_directory], cwd=cwd) print('created image {}'.format(base_image_uri)) return base_image_uri def build_image(py_version, framework_name, framework_version, processor, tag, cwd='.'): _check_call('python setup.py bdist_wheel') image_uri = get_image_uri(framework_name, tag) dockerfile_location = os.path.join('docker', framework_version, 'final', py_version, 'Dockerfile.{}'.format(processor)) subprocess.check_call(['docker', 'build', '-t', image_uri, '-f', dockerfile_location, '.'], cwd=cwd) print('created image {}'.format(image_uri)) return image_uri def get_base_image_uri(framework_name, base_image_tag): return '{}-base:{}'.format(framework_name, base_image_tag) def get_image_uri(framework_name, tag): return '{}:{}'.format(framework_name, tag) def _check_call(cmd, *popenargs, **kwargs): if isinstance(cmd, str): cmd = cmd.split(' ') _print_cmd(cmd) subprocess.check_call(cmd, *popenargs, **kwargs) def _print_cmd(cmd): print('executing docker command: {}{}{}'.format(CYAN_COLOR, ' '.join(cmd), END_COLOR)) sys.stdout.flush()