def build_config(app, env, cluster, local, deployconfigs): app_config = 'deploy/configuration' deployconfigs = [deployconfigs] if local: deployconfigs.append(os.path.join(app_config, 'local')) sources = config_sources(app, env, cluster, deployconfigs, app_config) if local: sources = itertools.chain(sources, local_config_sources(app, deployconfigs, app_config)) return smush_config(sources)
def configure(self): build_settings = self.deploy_settings.build configs_dirs = [build_settings.configs_dir] app_conf_dir = os.path.join('deploy', 'configuration') sources = config_sources(self.app, build_settings.environment, build_settings.cluster, configs_dirs, app_conf_dir, build=True) config = smush_config(sources, initial={'yoconfigurator': { 'app': self.app, 'environment': build_settings.environment, }}) write_config(config, '.') # public configuration public_filter_pathname = os.path.join(app_conf_dir, 'public-data.py') public_config = filter_config(config, public_filter_pathname) if public_config: write_config(public_config, '.', 'configuration_public.json')
def write_config(self): conf_root = os.path.join(self.settings.paths.apps, 'configs') if not os.path.exists(conf_root): os.mkdir(conf_root) conf_tarball = os.path.join(conf_root, 'configs.tar.gz') with SpinLockFile(os.path.join(conf_root, 'deploy.lock'), timeout=30): try: with self.repository.get('configs', target='master') as f1: with open(conf_tarball, 'w') as f2: shutil.copyfileobj(f1, f2) except KeyError: raise Exception("No configs in artifacts repository") configs = os.path.join(conf_root, 'configs') if os.path.exists(configs): shutil.rmtree(configs) extract_tar(conf_tarball, configs) os.unlink(conf_tarball) configs_dirs = [configs] + self.settings.deployconfigs.overrides app_conf_dir = self.deploy_path('deploy', 'configuration') sources = config_sources(self.app, self.settings.artifacts.environment, self.settings.artifacts.cluster, configs_dirs, app_conf_dir) config = smush_config( sources, initial={'yoconfigurator': {'app': self.app}}) public_filter_pn = os.path.join(app_conf_dir, 'public-data.py') public_config = filter_config(config, public_filter_pn) write_config(config, self.deploy_dir) if public_config: write_config( public_config, self.deploy_dir, 'configuration_public.json')
def main(): p = argparse.ArgumentParser( description="Build a Yola application's configuration.json file") p.add_argument('--configs-dir', '-d', metavar='DIRECTORY', action='append', help='Location of Configs. ' 'Can be specified multiple times. ' '(Default: /srv/configs/configs, ' '/etc/yola/deployconfigs/chef)') p.add_argument('--app-dir', '-a', metavar='DIRECTORY', default='.', help='Location of the application. ' 'The configuration.json will be written here. ' '(Default: .)') p.add_argument('--cluster', '-c', metavar='CLUSTER', help='Deployment cluster (Default: None)') p.add_argument('--local', '-l', action='store_true', help='Do a second pass, applying -local configuration') p.add_argument('--build', '-b', action='store_true', help='Do a third pass, applying -build configuration ' '(implies --local)') p.add_argument('--dry-run', '-n', action='store_true', help="Display the generated configuration, " "but don't write it.") p.add_argument('--verbose', '-v', action='store_true', help="Display the configuration at each step of merging") p.add_argument('--hostname', '-H', help='Specify a hostname to refer to (only with --local). ' 'This gets stuffed into an attribute in the configs ' 'for the benefit of hostname-local.') p.add_argument('app', help='Application name') p.add_argument('environment', help='Deployment environment') options = p.parse_args() if options.build: options.local = True if options.verbose: logging.basicConfig(level=logging.DEBUG, stream=sys.stderr) else: logging.basicConfig(level=logging.INFO, stream=sys.stderr) if not options.configs_dir: options.configs_dir = [ '/srv/configs/configs', '/etc/yola/deployconfigs/chef' ] app_config = os.path.join(options.app_dir, 'deploy', 'configuration') site_config = options.configs_dir initial = { 'yoconfigurator': { 'app': options.app, }, } if options.local: site_config.insert( 0, os.path.join(options.app_dir, 'deploy', 'configuration', 'local')) initial['yoconfigurator']['environment'] = options.environment if options.hostname: initial['yoconfigurator']['local_hostname'] = options.hostname sources = config_sources(options.app, options.environment, options.cluster, site_config, app_config, local=options.local, build=options.build) config = smush_config(sources, initial=initial) public_filter_pathname = os.path.join(app_config, 'public-data.py') pub_config = filter_config(config, public_filter_pathname) if options.dry_run: json.dump(config, sys.stdout, indent=4, separators=(',', ': ')) return write_config(config, options.app_dir) if pub_config: write_config(pub_config, options.app_dir, 'configuration_public.json')
def main(): p = argparse.ArgumentParser( description="Build a Yola application's configuration.json file") p.add_argument('--configs-dir', '-d', metavar='DIRECTORY', action='append', help='Location of Configs. ' 'Can be specified multiple times. ' '(Default: /srv/configs/configs, ' '/etc/yola/deployconfigs/chef)') p.add_argument('--app-dir', '-a', metavar='DIRECTORY', default='.', help='Location of the application. ' 'The configuration.json will be written here. ' '(Default: .)') p.add_argument('--cluster', '-c', metavar='CLUSTER', help='Deployment cluster (Default: None)') p.add_argument('--local', '-l', action='store_true', help='Do a second pass, applying -local configuration') p.add_argument('--build', '-b', action='store_true', help='Do a third pass, applying -build configuration ' '(implies --local)') p.add_argument('--dry-run', '-n', action='store_true', help="Display the generated configuration, " "but don't write it.") p.add_argument('--verbose', '-v', action='store_true', help="Display the configuration at each step of merging") p.add_argument('--hostname', '-H', help='Specify a hostname to refer to (only with --local). ' 'This gets stuffed into an attribute in the configs ' 'for the benefit of hostname-local.') p.add_argument('app', help='Application name') p.add_argument('environment', help='Deployment environment') options = p.parse_args() if options.build: options.local = True if options.verbose: logging.basicConfig(level=logging.DEBUG, stream=sys.stderr) else: logging.basicConfig(level=logging.INFO, stream=sys.stderr) if not options.configs_dir: options.configs_dir = [ '/srv/configs/configs', '/etc/yola/deployconfigs/chef' ] app_config = os.path.join(options.app_dir, 'deploy', 'configuration') site_config = options.configs_dir initial = { 'yoconfigurator': { 'app': options.app, }, } if options.local: site_config.insert(0, os.path.join(options.app_dir, 'deploy', 'configuration', 'local')) initial['yoconfigurator']['environment'] = options.environment if options.hostname: initial['yoconfigurator']['local_hostname'] = options.hostname sources = config_sources(options.app, options.environment, options.cluster, site_config, app_config, local=options.local, build=options.build) config = smush_config(sources, initial=initial) public_filter_pathname = os.path.join(app_config, 'public-data.py') pub_config = filter_config(config, public_filter_pathname) if options.dry_run: json.dump(config, sys.stdout, indent=4, separators=(',', ': ')) return write_config(config, options.app_dir) if pub_config: write_config(pub_config, options.app_dir, 'configuration_public.json')