예제 #1
0
파일: deploy.py 프로젝트: dscho/skypipe
def check_satellite(cli, context):
    url = '/applications/{0}/environment'.format(app)
    try:
        var = cli.user.get(url).item
        port = var['DOTCLOUD_SATELLITE_ZMQ_PORT']
        host = socket.gethostbyname(var['DOTCLOUD_SATELLITE_ZMQ_HOST'])
        endpoint = "tcp://{0}:{1}".format(host, port)
        req = context.socket(zmq.DEALER)
        req.linger = 0
        req.connect(endpoint)
        req.send_multipart(["SKYPIPE/0.1", "HELLO"])
        ok = None
        timeout = time.time() + 20
        while time.time() < timeout:
            try:
                ok = req.recv_multipart(zmq.NOBLOCK)
                break
            except zmq.ZMQError:
                continue
        req.close()
        if ok:
            cli.info("DEBUG: Found satellite")
            return endpoint
        else:
            #cli.die("no reply")
            return deploy_satellite(cli, context)
    except (RESTAPIError, KeyError):
        #cli.die("key error")
        return deploy_satellite(cli, context)
예제 #2
0
파일: deploy.py 프로젝트: dscho/skypipe
def deploy_satellite(cli, context):
    cli.info(' '.join(["Launching skypipe satellite.", 
    "This only has to happen once for your account."]))
    cli.info("This may take about a minute...")
    # destroy
    url = '/applications/{0}'.format(app)
    try:
        res = cli.user.delete(url)
    except RESTAPIError:
        pass

    # create
    url = '/applications'
    try:
        cli.user.post(url, {
            'name': app,
            'flavor': 'sandbox'
            })
    except RESTAPIError as e:
        if e.code == 409:
            cli.die('Application "{0}" already exists.'.format(app))
        else:
            cli.die('Creating application "{0}" failed: {1}'.format(app, e))
    class args: application = app
    #cli._connect(args)

    # push
    protocol = 'rsync'
    url = '/applications/{0}/push-endpoints{1}'.format(app, '')
    endpoint = cli._select_endpoint(cli.user.get(url).items, protocol)
    class args: path = satellite_path
    cli.push_with_rsync(args, endpoint)

    # deploy
    revision = None
    clean = False
    url = '/applications/{0}/deployments'.format(app)
    response = cli.user.post(url, {'revision': revision, 'clean': clean})
    deploy_trace_id = response.trace_id
    deploy_id = response.item['deploy_id']

    try:
        res = cli._stream_deploy_logs(app, deploy_id,
                deploy_trace_id=deploy_trace_id, follow=True)
        if res != 0:
            return res
    except KeyboardInterrupt:
        cli.error('You\'ve closed your log stream with Ctrl-C, ' \
            'but the deployment is still running in the background.')
        cli.error('If you aborted because of an error ' \
            '(e.g. the deployment got stuck), please e-mail\n' \
            '[email protected] and mention this trace ID: {0}'
            .format(deploy_trace_id))
        cli.error('If you want to continue following your deployment, ' \
                'try:\n{0}'.format(
                    cli._fmt_deploy_logs_command(deploy_id)))
        cli.die()
    except RuntimeError:
        pass
    return check_satellite(cli, context)
예제 #3
0
def launch_satellite(cli):
    """Deploys a new satellite app over any existing app"""

    cli.info("Launching skypipe satellite:")

    finish = wait_for("    Pushing to dotCloud")

    # destroy any existing satellite
    destroy_satellite(cli)

    # create new satellite app
    url = '/applications'
    try:
        cli.user.post(url, {
            'name': APPNAME,
            'flavor': 'sandbox'
            })
    except RESTAPIError as e:
        if e.code == 409:
            cli.die('Application "{0}" already exists.'.format(APPNAME))
        else:
            cli.die('Creating application "{0}" failed: {1}'.format(APPNAME, e))
    class args: application = APPNAME
    #cli._connect(args)

    # push satellite code
    protocol = 'rsync'
    url = '/applications/{0}/push-endpoints{1}'.format(APPNAME, '')
    endpoint = cli._select_endpoint(cli.user.get(url).items, protocol)
    class args: path = satellite_path
    cli.push_with_rsync(args, endpoint)

    # tell dotcloud to deploy, then wait for it to finish
    revision = None
    clean = False
    url = '/applications/{0}/deployments'.format(APPNAME)
    response = cli.user.post(url, {'revision': revision, 'clean': clean})
    deploy_trace_id = response.trace_id
    deploy_id = response.item['deploy_id']


    original_stdout = sys.stdout

    finish = wait_for("    Waiting for deployment", finish, original_stdout)

    try:
        sys.stdout = StringIO()
        res = cli._stream_deploy_logs(APPNAME, deploy_id,
                deploy_trace_id=deploy_trace_id, follow=True)
        if res != 0:
            return res
    except KeyboardInterrupt:
        cli.error('You\'ve closed your log stream with Ctrl-C, ' \
            'but the deployment is still running in the background.')
        cli.error('If you aborted because of an error ' \
            '(e.g. the deployment got stuck), please e-mail\n' \
            '[email protected] and mention this trace ID: {0}'
            .format(deploy_trace_id))
        cli.error('If you want to continue following your deployment, ' \
                'try:\n{0}'.format(
                    cli._fmt_deploy_logs_command(deploy_id)))
        cli.die()
    except RuntimeError:
        # workaround for a bug in the current dotcloud client code
        pass
    finally:
        sys.stdout = original_stdout

    finish = wait_for("    Satellite coming online", finish)

    endpoint = lookup_endpoint(cli)
    ok = client.check_skypipe_endpoint(endpoint, 120)
   
    finish.set()
    time.sleep(0.1) # sigh, threads

    if ok:
        return endpoint
    else:
        cli.die("Satellite failed to come online")
예제 #4
0
파일: deploy.py 프로젝트: dscho/skypipe
def find_satellite(context):
    cli = CLI(endpoint=url)
    if not cli.global_config.loaded:
        cli.info("First time use, please setup dotCloud account")
        setup_account(cli)
    return check_satellite(cli, context)