Exemple #1
0
def buildpack():
    tmpl = {
        'repo_url': '',
        'repo_type': ['git', 'hg'],
        'description': '',
        'order': 0,
    }

    vr = get_vr()

    info = {
        'available buildpacks': [
            bp.repo_url for bp in query('buildpack', vr)
        ]
    }

    config = edit_yaml(dump_yaml(tmpl),
                       dump_yaml(info))

    click.echo('Creating buildpack with following config:\n')
    click.echo(pformat(config))
    click.echo()

    if click.confirm('Create buildpack?'):
        bp = models.Buildpack(vr, config)
        bp.create()
        click.echo('Create %s %s!' % (bp.repo_url, bp.resource_uri))
Exemple #2
0
def app():
    tmpl = {
        'name': '',
        'repo': '',
        'repo_type': [
            'git', 'hg',
        ],
    }

    vr = get_vr()

    info = {
        'current_apps': [app.name for app in query('App', vr)],
    }

    config = edit_yaml(dump_yaml(tmpl), dump_yaml(info))

    config = validate(config)
    click.echo('Creating new app with the following config:')
    click.echo(pformat(config))
    click.echo()

    if click.confirm('Add app?'):
        app = models.App(vr, config)
        app.create()
        click.echo('Added %s!' % app.name)
Exemple #3
0
def apps():
    """List apps."""

    vr = get_vr()

    # add filters if we need to be...
    for i, app in enumerate(query('App', vr)):
        click.echo(app.name)
Exemple #4
0
def ingredients(name):
    """List builds.
    """
    vr = get_vr()

    q = {}
    if name:
        q['name'] = name

    # add filters if we need to be...
    for i, ingredient in enumerate(query('Ingredient', vr, q)):
        click.echo(ingredient.name)
Exemple #5
0
def swarms(app_name, config_name, proc_name):
    vr = get_vr()
    q = {
        'app__name__icontains': app_name,
        'config_name': config_name,
        'proc_name': proc_name,
    }

    q = {k: v for k, v in q.items() if v}

    for swarm in query('Swarm', vr, q):
        click.echo(swarm.name)
Exemple #6
0
def ingredients(name):
    """List builds.
    """
    vr = get_vr()

    q = {}
    if name:
        q['name'] = name

    # add filters if we need to be...
    for i, ingredient in enumerate(query('Ingredient', vr, q)):
        click.echo(ingredient.name)
Exemple #7
0
def swarm(names, dry_run):
    """Swarm an existing swarm.

    The swarm command allows swarming more than one swarm as defined
    by the `names` argument. The names can be passed directly in the
    command.

      $ rapt swarm myapp-production-web myapp-production-workers

    The `names` can also be passed in via stdin. For eaxmple:

      $ rapt swarms | grep myapp | rapt swarm

    This will open a YAML file where each swarm's settings can be
    edited. Only those swarms that have been edited will be reswarmed.

    After the swarms have been triggered, the events for those swarms
    will be printed. The script will exit when the events have
    finished or there has been a failure in one of swarms.
    """
    vr = get_vr()
    swarms = load_swarms(vr, names or stdin())
    configs = {str(swarm.name): swarm.config for swarm in swarms}
    if not configs:
        click.echo('No configs found')
        return

    new_config = edit_yaml(dump_yaml(configs))

    if not new_config:
        click.echo('No changes to the config. Exiting...')
        return

    event_handlers = []

    for swarm in swarms:
        config = new_config[swarm.name]
        if config != swarm.config:
            click.echo('Updating swarms with: %s' % config)
            if not dry_run:
                doc = swarm.obj.dispatch(**config)
                event_handlers.append(swarm_id_handler(doc['swarm_id']))
            click.echo('Swarmed %s!' % swarm.name)

    if event_handlers:
        click.echo('Watching for events. Hit C-c to exit')
        for event in filtered_events(vr, event_handlers):
            click.echo(event)
Exemple #8
0
def releases(app_name, limit):
    """List releases and print the compiled name.

    The `compiled_name` includes the app, build version and app hash.
    """
    vr = get_vr()

    q = {
        'build__app__name': app_name,
    }

    # add filters if we need to be...
    for i, release in enumerate(query('Release', vr, q)):
        click.echo(release.compiled_name)
        if i == limit:
            return
Exemple #9
0
def builds(app_name, limit):
    """List builds.
    """
    vr = get_vr()

    q = {
        'app__name': app_name,
    }

    # add filters if we need to be...
    for i, build in enumerate(query('Build', vr, q)):
        if not build.file:
            click.echo('[failed] %s %s' % (build.resource_uri, build.app))
        else:
            click.echo(build.file)
        if i == limit:
            return
Exemple #10
0
def reswarm(names, dry_run):
    """Reswarm a swarm without editing the config."""
    vr = get_vr()
    swarms = load_swarms(vr, names or stdin())

    event_handlers = []

    for swarm in swarms:
        click.echo('Running swarm %s with: %s' % (swarm.name, swarm.config))
        if not dry_run:
            doc = swarm.obj.dispatch(**swarm.config)
            event_handlers.append(swarm_id_handler(doc['swarm_id']))
        click.echo('Swarmed %s!' % swarm.name)

    if event_handlers:
        click.echo('Watching for events. Hit C-c to exit')
        for event in filtered_events(vr, event_handlers):
            click.echo(event)
Exemple #11
0
def deploy(build_config, app_name, release, proc, config_name, hostname, port):
    """Trigger new a build.

    The `build_config` is a YAML file with the require fields
    necessary to do the build. If no build_config is provided, your
    $EDITOR will be opened with a template that can be used to
    configure the build.
    """
    tmpl = {
        'release': release or '',
        'proc': proc or '',
        'config_name': config_name or '',
        'hostname': hostname or '',
        'port': port or '',
    }
    vr = get_vr()

    # Do we use some pre-canned yaml?
    if build_config:
        config = load_yaml(build_config[0])

    # How about some command line flags
    elif release and proc and config_name and hostname:
        config = tmpl

    # No? We'll use our template and editor
    else:
        config = edit_yaml(dump_yaml(tmpl))

    # We have a config so we'll actually do stuff
    if config:
        release = get_release(config, vr)

        # TODO: Get VR returning some value.
        release.deploy(config['hostname'], config['port'], config['proc'],
                       config['config_name'])

        click.echo('Watching for events. Hit C-c to exit')
        for event in filtered_events(vr, forever=True):
            click.echo(event)
Exemple #12
0
def build(build_config, app_name=None, tag=None):
    """Trigger new a build.

    The `build_config` is a YAML file with the require fields
    necessary to do the build. If no build_config is provided, your
    $EDITOR will be opened with a template that can be used to
    configure the build.
    """
    tmpl = {
        'app': str(app_name) or '',
        'tag': str(tag) or '',
        'os_image': ''
    }
    vr = get_vr()

    # grab our images and apps to validate them.
    images = query('OSImage', vr)
    apps = query('App', vr)

    # Do we use some pre-canned yaml?
    if build_config:
        config = load_yaml(build_config[0])

    # How about some command line flags
    elif app_name and tag:
        config = tmpl

    # No? We'll use our template and editor
    else:
        config = edit_yaml(dump_yaml(tmpl))

    # We have a config so we'll actually do stuff
    if config:
        config = validate(config, apps, images)
        build = models.Build(vr, config)
        build.assemble()

        click.echo('Watching for events. Hit C-c to exit')
        for event in filtered_events(vr, forever=True):
            click.echo(event)
Exemple #13
0
def swarm(config):
    """Add a new swarm."""
    vr = get_vr()

    apps = query('App', vr)
    squads = query('Squad', vr)

    if config:
        config = load_yaml(config[0])

    config = config or get_config(vr, apps, squads)

    if config:
        config = validate(config, squads, apps)
        click.echo('Creating swarm with following config:\n\n')
        click.echo(dump_yaml(config))
        click.echo()
        click.echo()

        if click.confirm('Add the swarm?', default=True):
            swarm = models.Swarm(vr, config)
            swarm.create()
            click.echo('Swarm %s created!' % (swarm.name))
Exemple #14
0
def ingredient(name, read):
    """View a complete ingredient config."""
    vr = get_vr()
    q = {'name': name}
    ingredient = query('Ingredient', vr, q).next()

    doc = {
        'config': load_yaml(ingredient.config_yaml),
        'env': load_yaml(ingredient.env_yaml),
    }

    if read:
        click.echo(dump_yaml(doc))
        return

    config = edit_yaml(dump_yaml(doc))

    if not config:
        click.echo('No changes')
        return

    ingredient.config_yaml = dump_yaml(config['config'])
    ingredient.env_yaml = dump_yaml(config['env'])
    ingredient.save()
Exemple #15
0
def build(build_config, app_name=None, tag=None):
    """Trigger new a build.

    The `build_config` is a YAML file with the require fields
    necessary to do the build. If no build_config is provided, your
    $EDITOR will be opened with a template that can be used to
    configure the build.
    """
    tmpl = {'app': str(app_name) or '', 'tag': str(tag) or '', 'os_image': ''}
    vr = get_vr()

    # grab our images and apps to validate them.
    images = query('OSImage', vr)
    apps = query('App', vr)

    # Do we use some pre-canned yaml?
    if build_config:
        config = load_yaml(build_config[0])

    # How about some command line flags
    elif app_name and tag:
        config = tmpl

    # No? We'll use our template and editor
    else:
        config = edit_yaml(dump_yaml(tmpl))

    # We have a config so we'll actually do stuff
    if config:
        config = validate(config, apps, images)
        build = models.Build(vr, config)
        build.assemble()

        click.echo('Watching for events. Hit C-c to exit')
        for event in filtered_events(vr, forever=True):
            click.echo(event)
Exemple #16
0
def buildpack():
    tmpl = {
        'repo_url': '',
        'repo_type': ['git', 'hg'],
        'description': '',
        'order': 0,
    }

    vr = get_vr()

    info = {
        'available buildpacks': [bp.repo_url for bp in query('buildpack', vr)]
    }

    config = edit_yaml(dump_yaml(tmpl), dump_yaml(info))

    click.echo('Creating buildpack with following config:\n')
    click.echo(pformat(config))
    click.echo()

    if click.confirm('Create buildpack?'):
        bp = models.Buildpack(vr, config)
        bp.create()
        click.echo('Create %s %s!' % (bp.repo_url, bp.resource_uri))
Exemple #17
0
def ingredient(name, read):
    """View a complete ingredient config."""
    vr = get_vr()
    q = {'name': name}
    ingredient = query('Ingredient', vr, q).next()

    doc = {
        'config': load_yaml(ingredient.config_yaml),
        'env': load_yaml(ingredient.env_yaml),
    }

    if read:
        click.echo(dump_yaml(doc))
        return

    config = edit_yaml(dump_yaml(doc))

    if not config:
        click.echo('No changes')
        return

    ingredient.config_yaml = dump_yaml(config['config'])
    ingredient.env_yaml = dump_yaml(config['env'])
    ingredient.save()