コード例 #1
0
def _prepare_deploy_params(project, version, image_name, endpoint, apikey,
                           username, password, email):
    # Reusing shub.image.list logic to get spiders list
    metadata = list_mod.list_cmd(image_name, project, endpoint, apikey)
    if 'scripts' not in metadata:
        metadata['scripts'] = _extract_scripts_from_project()
    params = {
        'project': project,
        'version': version,
        'image_url': image_name,
        'project_type': metadata['project_type'],
    }
    if metadata.get('spiders'):
        params['spiders'] = ','.join(metadata['spiders'])
    if metadata.get('scripts'):
        params['scripts'] = ','.join(metadata['scripts'])
    if not username:
        params['pull_insecure_registry'] = True
    else:
        params['pull_auth_config'] = json.dumps(
            {
                'username': username,
                'password': password,
                'email': email
            },
            sort_keys=True)
    return params
コード例 #2
0
def test_shub_image_info_fallback(get_docker_client_mock, _):
    exception = docker.errors.APIError(
        mock.Mock(),
        mock.Mock(),
        explanation=
        ('Cannot start container xxx: [8] System error: exec: "shub-image-info": '
         'executable file not found in $PATH'))
    get_docker_client_mock().create_container.return_value = {'Id': 'id'}
    get_docker_client_mock().start.side_effect = [
        exception,
        None,
    ]
    get_docker_client_mock().wait.return_value = 0
    get_docker_client_mock().logs.return_value = 'abc\ndef\n'
    result = list_cmd('image_name', 111, 'endpoint', 'apikey')
    assert get_docker_client_mock().start.call_count == 2
    assert result == {'spiders': [u'abc', u'def'], 'project_type': 'scrapy'}
コード例 #3
0
ファイル: deploy.py プロジェクト: scrapinghub/shub
def _prepare_deploy_params(project, version, image_name, endpoint, apikey,
                           username, password, email):
    # Reusing shub.image.list logic to get spiders list
    metadata = list_mod.list_cmd(image_name, project, endpoint, apikey)
    if not metadata.get('scripts'):
        metadata['scripts'] = _extract_scripts_from_project()
    params = {
        'project': project,
        'version': version,
        'image_url': image_name,
        'project_type': metadata['project_type'],
    }
    if metadata.get('spiders'):
        params['spiders'] = ','.join(metadata['spiders'])
    if metadata.get('scripts'):
        params['scripts'] = ','.join(metadata['scripts'])
    if not username:
        params['pull_insecure_registry'] = True
    else:
        params['pull_auth_config'] = json.dumps(
            {'username': username,
             'password': password,
             'email': email}, sort_keys=True)
    return params