コード例 #1
0
def get_project(compose_file=COMPOSE_FILE):
    from compose import __version__ as compose_version
    from compose.config import find, load
    from compose.project import Project
    from compose.cli.docker_client import docker_client

    if compose_version.startswith('1.4'):
        yaml_file = find('.', str(compose_file))
    else:
        # compose >= 1.5
        yaml_file = find('.', [str(compose_file)])

    config = load(yaml_file)
    return Project.from_dicts(PROJECT_NAME, config, docker_client())
コード例 #2
0
def parse_compose(file_dir, file_name=None):
    options = {}
    if file_name is not None:
        options["--file"] = [file_name]
    environment = Environment.from_env_file(file_dir)
    config_path = get_config_path_from_options(options, environment)
    return config.load(config.find(file_dir, config_path, environment))
コード例 #3
0
ファイル: _main.py プロジェクト: KitB/compose-deploy
def get_config(basedir, files):
    """ Returns the config object for the selected docker-compose.yml

    This is an instance of `compose.config.config.Config`.
    """
    config_details = config.find(
        basedir, files,
        environment.Environment.from_env_file(basedir))

    return config.load(config_details)
コード例 #4
0
 def open_compose_data(self, project_id):
     """
     Use Docker Compose to load the data of a project given in parameter.
     Return a Docker Compose data object.
     """
     project_dir = '/data/%s' % project_id
     config_files = config.config.get_default_config_files(project_dir)
     environment = Environment.from_env_file(project_dir)
     config_details = config.find(project_dir, config_files, environment)
     return config.load(config_details)
コード例 #5
0
def gen_services(path):
    parent = str(path.parent)
    env = config.environment.Environment.from_env_file(parent)
    details = config.find(parent, [path.name], env)
    resolved = config.load(details)
    for s in resolved.services:
        if "image" not in s:
            raise RuntimeError("Service {!r} have no 'image' field".format(
                s["name"]))
        yield s
コード例 #6
0
 def open_compose_data(self, project_id):
     """
     Use Docker Compose to load the data of a project given in parameter.
     Return a Docker Compose data object.
     """
     project_dir = '/data/%s' % project_id
     config_files = config.config.get_default_config_files(project_dir)
     environment = Environment.from_env_file(project_dir)
     config_details = config.find(project_dir, config_files, environment)
     return config.load(config_details)
コード例 #7
0
ファイル: main.py プロジェクト: funkyfuture/compose-dump
def get_compose_context(options):
    base_dir = str(options['project_dir'])
    environment = compose_config.environment.Environment.from_env_file(base_dir)
    config_details = compose_config.find(base_dir, options['compose_files'], environment)
    config = compose_config.load(config_details)
    unknown_services = set(options['services']) - set(x['name'] for x in config.services)
    if unknown_services:
        log.error('Unknown services: %s' % ', '.join(unknown_services))
        raise SystemExit(1)
    if not options['services']:
        options['services'] = tuple(x['name'] for x in config.services)
    return config, config_details, environment
コード例 #8
0
    def from_compose(self, project_name=None, filename='docker-compose.yml'):
        """Return a host group with hosts names extracted from compose file"""
        from compose.project import Project
        from compose import config

        project_dir = os.getcwd()
        project_name = project_name or os.path.basename(project_dir)
        conf = config.load(config.find(project_dir, [filename], os.environ))
        project = Project.from_config('', conf, client=None)
        for service in project.get_services():
            name = '{0}-{1.name}-1'.format(project_name, service)
            self.get_or_create_node(hostname=name)
        return self
コード例 #9
0
ファイル: main.py プロジェクト: 3mb3dw0rk5/compose-dump
def get_compose_context(options):
    base_dir = str(options['project_dir'])
    environment = compose_config.environment.Environment.from_env_file(
        base_dir)
    config_details = compose_config.find(base_dir, options['compose_files'],
                                         environment)
    config = compose_config.load(config_details)
    unknown_services = set(options['services']) - set(x['name']
                                                      for x in config.services)
    if unknown_services:
        log.error('Unknown services: %s' % ', '.join(unknown_services))
        raise SystemExit(1)
    if not options['services']:
        options['services'] = tuple(x['name'] for x in config.services)
    return config, config_details, environment
コード例 #10
0
def get_compose_context(options):
    base_dir = str(options["project_dir"])
    environment = compose_config.environment.Environment.from_env_file(
        base_dir)
    config_details = compose_config.find(base_dir, options["compose_files"],
                                         environment)
    config = compose_config.load(config_details)
    unknown_services = set(options["services"]) - set(x["name"]
                                                      for x in config.services)
    if unknown_services:
        log.error("Unknown services: %s" % ", ".join(unknown_services))
        raise SystemExit(1)
    if not options["services"]:
        options["services"] = tuple(x["name"] for x in config.services)
    return config, config_details, environment
コード例 #11
0
ファイル: config_test.py プロジェクト: bfirsh/fig
def load_from_filename(filename):
    return config.load(config.find('.', filename))
コード例 #12
0
ファイル: config_test.py プロジェクト: bkamana/Docker-compose
def load_from_filename(filename):
    return config.load(config.find('.', filename))
コード例 #13
0
UID_ENVIRONMENT_KEY = "MANAGER_UID"
COMPOSE_DIRECTORY = "/compose"

if __name__ == "__main__":
    manager_uid = os.environ.get("MANAGER_UID")
    listened_container = os.environ.get("MANAGER_LISTEN_SERVICE", None)

    WORKING_DIR = "/compose-fin"

    shutil.copytree(COMPOSE_DIRECTORY, WORKING_DIR)
    client = docker.from_env()
    node_id = client.info()["Swarm"]["NodeID"]
    config = compose_config.load(
        compose_config.find(
            WORKING_DIR,
            ["docker-compose.yml"],
            compose_config.environment.Environment(os.environ)
        )
    )

    services = config.services
    for service in services:
        if 'deploy' not in service:
            service['deploy'] = {}
        service['deploy']['placement'] = {}
        service['deploy']['placement']['constraints'] = [
            'node.id == ' + node_id]
        service['deploy']['restart_policy'] = {}
        service['deploy']['restart_policy']['condition'] = 'none'

    final_file_path = os.path.join(WORKING_DIR, 'docker-compose-final.yml')