コード例 #1
0
def build(
        working_dir_path: str,
        template_file_path: str,
        var_file_paths: List[str] = None,
        vars: dict = None,
        vars_from_files: dict = None,
        debug: bool = False,
        force: bool = False) -> dict:
    packer_command_args = []
    # add any specified var file paths
    if var_file_paths:
        for var_file_path in var_file_paths:
            packer_command_args.append(f"-var-file={var_file_path}")
    # add any specified vars
    if vars:
        for var_name, var_value in vars.items():
            packer_command_args.append(f"-var={var_name}={var_value}")
    # add any vars from files
    if vars_from_files:
        for var_name, file_path in vars_from_files.items():
            var_value = \
                read_value_from_file(
                    file_path,
                    working_dir=working_dir_path)
            packer_command_args.append(f"-var={var_name}={var_value}")
    # add force if requested
    if force:
        packer_command_args.append("-force")
    # dump args on debug
    if debug:
        log('build args:')
        log_pretty(packer_command_args)
    # execute build command
    packer_command_result = _packer(
        'build',
        *packer_command_args,
        template_file_path,
        working_dir=working_dir_path)
    # get build manifest from output
    packer_build_manifest = \
        _parse_packer_parsed_output_for_build_manifest(packer_command_result)
    # return the manifest
    return packer_build_manifest
コード例 #2
0
def validate(working_dir_path: str,
             template_file_path: str,
             only_builder: str = None,
             var_file_paths: List[str] = None,
             vars: dict = None,
             vars_from_files: dict = None,
             syntax_only: bool = False,
             debug: bool = False) -> None:
    packer_command_args = []
    # add any specified var file paths
    if var_file_paths:
        for var_file_path in var_file_paths:
            packer_command_args.append(f"-var-file={var_file_path}")
    # add any specified vars
    if vars:
        for var_name, var_value in vars.items():
            packer_command_args.append(f"-var={var_name}={var_value}")
    # add any vars from files
    if vars_from_files:
        for var_name, file_path in vars_from_files.items():
            var_value = \
                read_value_from_file(
                    file_path,
                    working_dir=working_dir_path)
            packer_command_args.append(f"-var={var_name}={var_value}")
    # optionally check only syntax
    if syntax_only:
        packer_command_args.append('-syntax-only')
    # optionally check only builder
    if only_builder:
        packer_command_args.append(f"-only={only_builder}")
    # dump args on debug
    if debug:
        log('validate args:')
        log_pretty(packer_command_args)
    # execute validate command
    _packer('validate',
            *packer_command_args,
            template_file_path,
            working_dir=working_dir_path)
コード例 #3
0
def _process_env_var_files(env_var_files: dict, working_dir: str) -> None:
    for var_name, file_path in env_var_files.items():
        os.environ[var_name] = (read_value_from_file(file_path,
                                                     working_dir=working_dir))