Example #1
0
def cli(config: str, command):
    """Command line entry point"""

    main_config = get_main_config(config)
    set_env_values_from_conf(main_config)

    project_name = main_config.get('project_name')
    os.putenv('COMPOSE_PROJECT_NAME', project_name)

    # What to load
    compose_file = package_utils.get_file('static', 'docker-compose.yml')
    activated_services = get_enabled_services(main_config.get('services'))

    # Create the command
    services = []
    for service in activated_services:
        services.append('-f')
        services.append(service)

    base_cmd = ['docker-compose', '-f', compose_file
                ] + services + ['-p', project_name]

    msg = click.style('[VERBOSE] ', fg='green')
    msg += 'Compose command: ' + ' '.join(base_cmd + list(command))
    click.echo(msg, err=True)
    subprocess.call(base_cmd + list(command))
Example #2
0
 def _call_service_post_script(self, service: str):
     service_script = package_utils.get_file(
         'static', 'services/{}.sh'.format(service))
     if os.path.isfile(service_script) is True:
         cmd = ['bash', service_script, docker.get_ct_item(service, 'name')]
         subprocess.call(cmd)
         command.verbose(self.context['VERBOSE'],
                         'Service Script : ' + ' '.join(cmd))
Example #3
0
    def _parse(self):
        """Parse the config from configspecs that is a file either local or from a package"""

        config_spec_file = package_utils.get_file('static', 'configspec.ini')
        config = ConfigObj(infile=self.config_file, configspec=config_spec_file)

        validator = Validator()
        validated = config.validate(validator, preserve_errors=True)
        if validated is not True:
            self._register_errors(config, validated)
            return False

        return config
Example #4
0
def _copy_file(venv_dir: str, source_file: str, force: bool):
    full_path = package_utils.get_file('tpls', source_file)
    dest_file = venv_dir + '/' + source_file
    if os.path.isfile(dest_file) and force is False:
        print('  - {} exists, do not overwrite'.format(source_file))
        return

    print('  - {} written'.format(source_file))
    try:
        shutil.copy(full_path, dest_file)
    except Exception:
        msg = "Error trying to copy {} .. check that the file is there ...".format(full_path)
        print(msg, file=sys.stderr)
Example #5
0
    def _parse(self):
        """Parse the config from configspecs that is a file either local or from a package"""

        config_spec_file = package_utils.get_file('static', 'configspec.ini')
        config = ConfigObj(infile=self.config_file,
                           configspec=config_spec_file)

        validator = Validator()
        validated = config.validate(validator, preserve_errors=True)
        if validated is not True:
            self._register_errors(config, validated)
            return False

        return config
Example #6
0
def _copy_file(venv_dir: str, source_file: str, force: bool):
    full_path = package_utils.get_file('tpls', source_file)
    dest_file = venv_dir + '/' + source_file
    if os.path.isfile(dest_file) and force is False:
        print('  - {} exists, do not overwrite'.format(source_file))
        return

    print('  - {} written'.format(source_file))
    try:
        shutil.copy(full_path, dest_file)
    except Exception:
        msg = "Error trying to copy {} .. check that the file is there ...".format(
            full_path)
        print(msg, file=sys.stderr)
Example #7
0
def get_base_command(project_name: str, config: dict):
    """Build the docker-compose file to be run as a command."""
    main_file = 'docker-compose.yml'
    # Set the network subnet ?
    if config.get('subnet') != '':
        main_file = 'docker-compose.subnet.yml'
    cmd = ['docker-compose', '-f', package_utils.get_file('static', main_file)]

    # What to load
    activated_services = get_enabled_services(config.get('services'))
    # Create the command
    services = []
    for service in activated_services:
        services.append('-f')
        services.append(service)

    return cmd + services + ['-p', project_name]
Example #8
0
 def _call_service_post_script(self, service: str):
     service_script = package_utils.get_file('static', 'services/{}.sh'.format(service))
     if os.path.isfile(service_script) is True:
         cmd = ['bash', service_script, docker_actions.get_ct_item(service, 'name')]
         subprocess.call(cmd)
         command.verbose(self.context['VERBOSE'], 'Service Script : ' + ' '.join(cmd))