def test_multiple_path_from_env_windows(self): with mock.patch.dict(os.environ): os.environ['COMPOSE_FILE'] = 'one.yml;two.yml' environment = Environment.from_env_file('.') assert get_config_path_from_options( '.', {}, environment ) == ['one.yml', 'two.yml']
def test_unicode_path_from_env(self): with mock.patch.dict(os.environ): os.environ[ 'COMPOSE_FILE'] = b'\xe5\xb0\xb1\xe5\x90\x83\xe9\xa5\xad/docker-compose.yml' environment = Environment.from_env_file('.') assert get_config_path_from_options( '.', {}, environment) == ['就吃饭/docker-compose.yml']
def config(self, config_options, options): """ Validate and view the compose file. Usage: config [options] Options: -q, --quiet Only validate the configuration, don't print anything. --services Print the service names, one per line. """ print "project dir:" + self.project_dir environment = Environment.from_env_file(self.project_dir) print environment config_path = get_config_path_from_options(self.project_dir, config_options, environment) compose_config = config.load( config.find(self.project_dir, config_path, environment)) if options['--quiet']: return if options['--services']: print('\n'.join(service['name'] for service in compose_config.services)) return print(serialize_config(compose_config))
def config(self, config_options, options): """ Validate and view the compose file. Usage: config [options] Options: -q, --quiet Only validate the configuration, don't print anything. --services Print the service names, one per line. """ print "project dir:" + self.project_dir environment = Environment.from_env_file(self.project_dir) print environment config_path = get_config_path_from_options( self.project_dir, config_options, environment ) compose_config = config.load( config.find(self.project_dir, config_path, environment) ) if options['--quiet']: return if options['--services']: print('\n'.join(service['name'] for service in compose_config.services)) return print(serialize_config(compose_config))
def test_unicode_path_from_env(self): with mock.patch.dict(os.environ): os.environ['COMPOSE_FILE'] = b'\xe5\xb0\xb1\xe5\x90\x83\xe9\xa5\xad/docker-compose.yml' environment = Environment.from_env_file('.') assert get_config_path_from_options( '.', {}, environment ) == ['就吃饭/docker-compose.yml']
def test_unicode_path_from_options(self): paths = [b'\xe5\xb0\xb1\xe5\x90\x83\xe9\xa5\xad/docker-compose.yml'] opts = {'--file': paths} environment = Environment.from_env_file('.') assert get_config_path_from_options( '.', opts, environment ) == ['就吃饭/docker-compose.yml']
def test_multiple_path_from_env_custom_separator(self): with mock.patch.dict(os.environ): os.environ['COMPOSE_PATH_SEPARATOR'] = '^' os.environ['COMPOSE_FILE'] = 'c:\\one.yml^.\\semi;colon.yml' environment = Environment.from_env_file('.') assert get_config_path_from_options( {}, environment) == ['c:\\one.yml', '.\\semi;colon.yml']
def top_level_cmd(self): try: compose_files = self.get_compose_files() config_path = get_config_path_from_options( ".", {}, {"COMPOSE_FILE": compose_files}, ) os.environ["COMPOSE_FILE"] = compose_files for k, v in self.settings.items(): if k == "CONFIGURATION_OPTIONAL_SCOPES": continue if isinstance(v, bool): v = f"{v}".lower() if isinstance(v, int): v = str(v) os.environ[k] = v env = Environment() env.update(os.environ) project = get_project(os.getcwd(), config_path, environment=env) tlc = TopLevelCommand(project) yield tlc except Exception: # noqa: B902 raise
def get_project(path): """ get docker project given file path """ logging.debug('get project ' + path) config_path = get_config_path_from_options(dict([('--file', path)])) project = compose_get_project(config_path) return project
def test_multiple_path_from_env_custom_separator(self): with mock.patch.dict(os.environ): os.environ['COMPOSE_PATH_SEPARATOR'] = '^' os.environ['COMPOSE_FILE'] = 'c:\\one.yml^.\\semi;colon.yml' environment = Environment.from_env_file('.') assert get_config_path_from_options( '.', {}, environment ) == ['c:\\one.yml', '.\\semi;colon.yml']
def create_dump(ctx): manifest_log = StringIO() manifest_handler = logging.StreamHandler(manifest_log) setup_loghandler(manifest_handler, ctx.options["verbose"]) log.addHandler(manifest_handler) scopes = ctx.options["scopes"] meta = ctx.manifest["meta"] = OrderedDict() meta["invocation_time"] = datetime.now().isoformat() meta["finish_time"] = None meta["argv"] = sys.argv meta["options"] = ctx.options meta["host"] = gethostname() meta["uid"] = os.getuid() meta["gid"] = os.getgid() meta["version"] = VERSION init_storage(ctx) base_dir = str(ctx.options["project_dir"]) config_path = get_config_path_from_options( base_dir, {"--file": ctx.options["compose_files"]}, ctx.environment ) ctx.project = get_project( base_dir, config_path=config_path, project_name=ctx.options["project_name"], verbose=ctx.options["verbose"], host=None, tls_config=None, environment=ctx.environment, ) if "config" in scopes: store_config(ctx) if "mounted" in scopes or "volumes" in scopes: if not ctx.options["no_pause"]: ctx.project.pause(service_names=ctx.options["services"]) store_volumes(ctx) if not ctx.options["no_pause"]: ctx.project.unpause(service_names=ctx.options["services"]) meta["finish_time"] = datetime.now().isoformat() normalize_manifest_mapping(ctx.manifest) manifest_log.seek(0) doc = yaml.dump(ctx.manifest, default_flow_style=False) doc += "---\n" doc += yaml.dump( [x.strip() for x in manifest_log.readlines() if x], default_style='"' ) ctx.storage.write_file(doc, "Manifest.yml") ctx.storage.finalize()
def get_project(path): """ get docker project given file path """ logging.debug('get project ' + path) environment = Environment.from_env_file(path) config_path = get_config_path_from_options(path, dict(), environment) project = compose_get_project(path, config_path) return project
def get_project(path, project_name=None): """ get docker project given file path """ environment = Environment.from_env_file(path) config_path = get_config_path_from_options(path, dict(), environment) project = compose_get_project(path, config_path, project_name=project_name, host='{0}:{1}'.format(config.swarm_scheduling_host, config.swarm_scheduling_port)) return project
def load_config(self, project_dir, options): try: environment = Environment.from_env_file(project_dir) config_path = get_config_path_from_options(project_dir, options, environment) config_details = config.find(project_dir, config_path, environment) self.config = config.load(config_details) except ComposeFileNotFound: self.config = False self._load_plugins()
def init_project(orgId): print("[init_project]: Compose project init started...") namespace, api_data, repl = create_customer(orgId) environment = Environment.from_env_file(FOLDER_PATH) config_path = get_config_path_from_options(FOLDER_PATH, dict(), environment) project = get_project(FOLDER_PATH, config_path, namespace) project_name = get_project_name(FOLDER_PATH, namespace) print("[init_project]: Compose project init finished...") return (project, namespace, api_data, repl)
def create_dump(ctx): manifest_log = StringIO() manifest_handler = logging.StreamHandler(manifest_log) setup_loghandler(manifest_handler, ctx.options['verbose']) log.addHandler(manifest_handler) scopes = ctx.options['scopes'] meta = ctx.manifest['meta'] = OrderedDict() meta['invocation_time'] = datetime.now().isoformat() meta['finish_time'] = None meta['argv'] = sys.argv meta['options'] = ctx.options meta['host'] = gethostname() meta['uid'] = os.getuid() meta['gid'] = os.getgid() meta['version'] = VERSION init_storage(ctx) base_dir = str(ctx.options['project_dir']) config_path = get_config_path_from_options( base_dir, {'--file': ctx.options['compose_files']}, ctx.environment) ctx.project = \ get_project(base_dir, config_path=config_path, project_name=ctx.options['project_name'], verbose=ctx.options['verbose'], host=None, tls_config=None, environment=ctx.environment) if 'config' in scopes: store_config(ctx) if 'mounted' in scopes or 'volumes' in scopes: if not ctx.options['no_pause']: ctx.project.pause(service_names=ctx.options['services']) store_volumes(ctx) if not ctx.options['no_pause']: ctx.project.unpause(service_names=ctx.options['services']) meta['finish_time'] = datetime.now().isoformat() normalize_manifest_mapping(ctx.manifest) manifest_log.seek(0) doc = yaml.dump(ctx.manifest, default_flow_style=False) doc += '---\n' doc += yaml.dump([x.strip() for x in manifest_log.readlines() if x], default_style='"') ctx.storage.write_file(doc, 'Manifest.yml') ctx.storage.finalize()
def create_dump(ctx): manifest_log = StringIO() manifest_handler = logging.StreamHandler(manifest_log) setup_loghandler(manifest_handler, ctx.options['verbose']) log.addHandler(manifest_handler) scopes = ctx.options['scopes'] meta = ctx.manifest['meta'] = OrderedDict() meta['invocation_time'] = datetime.now().isoformat() meta['finish_time'] = None meta['argv'] = sys.argv meta['options'] = ctx.options meta['host'] = gethostname() meta['uid'] = os.getuid() meta['gid'] = os.getgid() meta['version'] = __version__ init_storage(ctx) base_dir = str(ctx.options['project_dir']) config_path = get_config_path_from_options( base_dir, {'--file': ctx.options['compose_files']}, ctx.environment) ctx.project = \ get_project(base_dir, config_path=config_path, project_name=ctx.options['project_name'], verbose=ctx.options['verbose'], host=None, tls_config=None, environment=ctx.environment) if 'config' in scopes: store_config(ctx) if 'mounted' in scopes or 'volumes' in scopes: if ctx.options['no_pause']: ctx.project.pause(service_names=ctx.options['services']) store_volumes(ctx) if ctx.options['no_pause']: ctx.project.unpause(service_names=ctx.options['services']) meta['finish_time'] = datetime.now().isoformat() normalize_manifest_mapping(ctx.manifest) manifest_log.seek(0) doc = yaml.dump(ctx.manifest, default_flow_style=False) doc += '---\n' doc += yaml.dump([x.strip() for x in manifest_log.readlines() if x], default_style='"') ctx.storage.write_file(doc, 'Manifest.yml') ctx.storage.finalize()
def get_project(self, path): environment = Environment.from_env_file(path) config_path = get_config_path_from_options(path, dict(), environment) project = compose_get_project(path, config_path) return project
def test_no_path(self): assert not get_config_path_from_options({})
def test_multiple_path_from_env_windows(self): with mock.patch.dict(os.environ): os.environ['COMPOSE_FILE'] = 'one.yml;two.yml' assert get_config_path_from_options({}) == ['one.yml', 'two.yml']
def test_single_path_from_env(self): with mock.patch.dict(os.environ): os.environ['COMPOSE_FILE'] = 'one.yml' assert get_config_path_from_options({}) == ['one.yml']
def test_path_from_options(self): paths = ['one.yml', 'two.yml'] opts = {'--file': paths} assert get_config_path_from_options(opts) == paths
def test_path_from_options(self): paths = ['one.yml', 'two.yml'] opts = {'--file': paths} environment = Environment.from_env_file('.') assert get_config_path_from_options(opts, environment) == paths
def test_path_from_options(self): paths = ['one.yml', 'two.yml'] opts = {'--file': paths} environment = Environment.from_env_file('.') assert get_config_path_from_options('.', opts, environment) == paths
def test_no_path(self): environment = Environment.from_env_file('.') assert not get_config_path_from_options('.', {}, environment)
def test_single_path_from_env(self): with mock.patch.dict(os.environ): os.environ['COMPOSE_FILE'] = 'one.yml' environment = Environment.from_env_file('.') assert get_config_path_from_options({}, environment) == ['one.yml']
def test_no_path(self): environment = Environment.from_env_file('.') assert not get_config_path_from_options({}, environment)