当前位置: 首页>>代码示例>>Python>>正文


Python Repo.add方法代码示例

本文整理汇总了Python中git.Repo.add方法的典型用法代码示例。如果您正苦于以下问题:Python Repo.add方法的具体用法?Python Repo.add怎么用?Python Repo.add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在git.Repo的用法示例。


在下文中一共展示了Repo.add方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: release_kuber

# 需要导入模块: from git import Repo [as 别名]
# 或者: from git.Repo import add [as 别名]
def release_kuber(context, app, version):
    # check whether the app belongs to the context
    if app not in config.app_dict.get(context, []):
        log.error('Provided app does not belong to the context')
        return

    git = Repo('{}/..'.format(os.getcwd())).git
    git.checkout('master')
    git.pull()

    try:
        # # check whether a container with app name and provided version number exists
        # container_tags = subprocess.check_output(['gsutil', 'ls', '{}/{}'.format(config.gs_path_to_app, app)])
        # container_exist = False
        #
        # for tag in container_tags.split('\n'):
        #     # tag sample:
        #     # gs://artifacts.sojern-platform.appspot.com/containers/repositories/library/applier/tag_2.3.11
        #     version_list = re.findall('\d+\.\d+\.\d+', tag.split('/')[-1])
        #     if version_list and version_list[0] == version:
        #         container_exist = True
        #         break
        #
        # if not container_exist:
        #     log.error('The container with provided app and version number does not exist')
        #     return

        # modify app.yml file with new version
        yaml_file = '{}.yml'.format(app)

        with open(yaml_file) as f:
            yaml_dict = yaml.load(f)

        _update_yaml_file(yaml_dict, version)

        with open(yaml_file, 'w') as f:
            yaml.dump(yaml_dict, f, default_flow_style=False)

        # get replication controller name, sample output of this command:
        # CONTROLLER              CONTAINER (S)     IMAGES            SELECTOR     REPLICAS
        # backend-controller      applier           applier_2.3.11    applier      3
        rc_name = subprocess.check_output(['kubectl', '--context={}'.format(context), 'get', 'rc',
                                           '--selector=run={}'.format(app)]).split('\n')[1].split()[0]

        print 'controller name:', rc_name
        # run rolling update
        exit_code = subprocess.call(['kubectl', '--context=vagrant', 'rolling-update',
                                     '{}'.format(rc_name), '-f', yaml_file])

        # if rolling update succeeds, commit changes in Git repo and push back to master
        if exit_code == 0:
            log.info('Rolling update {} to {} successfully'.format(app, version))
            git.add(yaml_file)
            git.commit(m='bump {} to {}'.format(app, version))
            git.push()
        else:
            log.error('Errors in rolling update command, exit code:{}'.format(exit_code))
            git.checkout('.')

    except Exception as e:
        git.checkout('.')
        log.exception('Exception:{}'.format(e))
开发者ID:yangxiangliang,项目名称:kubertest,代码行数:64,代码来源:release_kuber.py

示例2: release_kuber

# 需要导入模块: from git import Repo [as 别名]
# 或者: from git.Repo import add [as 别名]
def release_kuber(context, app, version):
    # check whether the app belongs to the context
    if app not in config.app_dict.get(context, []):
        log.error('Provided app does not belong to the context')
        return

    to_kuber = os.path.join(os.getcwd(), 'hellonode')
    git = Repo(os.path.abspath('{}/..'.format(to_kuber))).git
    git = Repo('{}'.format(os.getcwd())).git
    git.checkout('master')
    git.pull()

    try:
        try:
        # check whether a container with app name and provided version number exists
            print version
            version = version if version.startswith('v') else 'v'+version
            print version
            container_tags = subprocess.check_output(['gsutil', 'ls', '{}/{}/tag_{}'.format(
                                config.gs_path_to_app, app, version)])
            log.info('App and version check successful')
        except:
            log.error('The container with provided app and version number does not exist')
            return

        # modify app.yml file with new version
        yaml_file = '{}.yml'.format(app)

        print os.getcwd()
        with open(yaml_file) as f:
            yaml_dict = yaml.load(f)

        _update_yaml_file(yaml_dict, version)

        with open(yaml_file, 'w') as f:
            yaml.dump(yaml_dict, f, default_flow_style=False)

        # get replication controller name, sample output of this command:
        # CONTROLLER              CONTAINER (S)     IMAGES            SELECTOR     REPLICAS
        # backend-controller      applier           applier_2.3.11    applier      3
        rc_name = subprocess.check_output(['kubectl','get', 'deployment',
                                           '{}'.format(app)]).split('\n')[1].split()[0]

        log.info('Applying New Configuration')
        # run rolling update
        exit_code = subprocess.call(['kubectl', 'apply', '-f', yaml_file])

        # if rolling update succeeds, commit changes in Git repo and push back to master
        if exit_code == 0:
            log.info('Updated {} to {} successfully'.format(app, version))
            git.add(yaml_file)
            commit_message = ' bump {} to {}'.format(app, version)
            git.commit(m=commit_message)
            log.info(commit_message)
            git.push()
        else:
            log.error('Errors in updating deployment, exit code:{}'.format(exit_code))
            git.checkout('.')

    except Exception as e:
        git.checkout('.')
        log.exception('Exception:{}'.format(e))
开发者ID:ishaqsharief318,项目名称:kubernetes-test,代码行数:64,代码来源:release_kuber.py


注:本文中的git.Repo.add方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。