def start(user_execution_directory, name, image): """ This step generates a mic.yaml file and the directories (data/, src/, docker/). The argument: `model_configuration_name` is the name of the model component you are defining in MIC """ user_execution_directory = Path(user_execution_directory) mic_dir = user_execution_directory / MIC_DIR create_base_directories(mic_dir) # Cant log the start command until the mic dir has been created. Else mic will think the directory already exists if make_log_file(): log_system_info(get_mic_logger().name) log_command(logging, "start", name=name, image=image) mic_config_path = create_config_file_yaml(mic_dir) custom_image = False if image is None: framework = detect_framework_main(user_execution_directory) else: # If a user provides a image, the framework is generic. custom_image = True framework = Framework.GENERIC framework.image = image os.system(f"docker pull {framework.image}") render_dockerfile(mic_dir, framework) # Make sure the name given is valid if not name.islower(): logging.debug( "User's model name does not contain all lowercase characters. Setting it to lower" ) click.secho( "Model name must be lower case. Mic will replace any uppercase letters", fg='yellow') name = name.lower() os.system(f"docker pull {framework.image}") try: user_image = build_docker(mic_dir / DOCKER_DIR, name) except ValueError: click.secho("The extraction of dependencies has failed", fg='red') user_image = framework.image container_name = f"{name}_{str(uuid.uuid4())[:8]}" write_spec(mic_config_path, NAME_KEY, name) write_spec(mic_config_path, DOCKER_KEY, user_image) write_spec(mic_config_path, FRAMEWORK_KEY, framework.label) write_spec(mic_config_path, CONTAINER_NAME_KEY, container_name) docker_cmd = f"""docker run -ti \ --name={container_name} \ --cap-add=SYS_PTRACE \ -v \"{user_execution_directory}\":/tmp/mint \ -w /tmp/mint {user_image} """ if custom_image: click.secho(f""" You are using a custom image Installing MIC and some dependencies """, fg="green") try: os.system(docker_cmd) logging.info("start done") except Exception as e: logging.exception(f"Start failed: {e}") click.secho("Failed", fg="red") click.secho(e)
info_end_publish_dt from mic.component.detect import detect_framework_main, detect_new_reprozip, extract_dependencies from mic.component.executor import copy_code_to_src, compress_directory, execute_local, copy_config_to_src from mic.component.initialization import render_run_sh, render_io_sh, render_output, create_base_directories, \ render_bash_color, render_dockerfile, recursive_convert_to_lf from mic.component.reprozip import get_inputs_outputs_reprozip, get_outputs_reprozip, relative, generate_runner, \ generate_pre_runner, find_code_files, get_parameters_reprozip from mic.config_yaml import write_spec, write_to_yaml, get_spec, get_key_spec, create_config_file_yaml, get_configs, \ get_inputs, get_parameters, get_outputs_mic, get_code, add_params_from_config, get_framework from mic.constants import * from mic.publisher.docker import publish_docker, build_docker from mic.publisher.model_catalog import create_model_catalog_resource, publish_model_configuration, \ publish_data_transformation, create_data_transformation_resource from mic.publisher.s3 import push logging = get_mic_logger() @click.group() @click.option("--verbose", "-v", default=0, count=True) def cli(verbose): _utils.init_logger() try: lv = ".".join(_utils.get_latest_version().split(".")[:3]) except Exception as e: click.secho( f"""WARNING: Unable to check if MIC is updated""", fg="yellow", ) return