libbuild.py 文件源码

python
阅读 31 收藏 0 点赞 0 评论 0

项目:Dockerfiles 作者: appscode 项目源码 文件源码
def metadata(cwd, goos='', goarch=''):
    md = {
        'commit_hash': subprocess.check_output('git rev-parse --verify HEAD', shell=True, cwd=cwd).strip(),
        'git_branch': subprocess.check_output('git rev-parse --abbrev-ref HEAD', shell=True, cwd=cwd).strip(),
        # http://stackoverflow.com/a/1404862/3476121
        'git_tag': subprocess.check_output('git describe --exact-match --abbrev=0 2>/dev/null || echo ""', shell=True,
                                           cwd=cwd).strip(),
        'commit_timestamp': datetime.datetime.utcfromtimestamp(
            int(subprocess.check_output('git show -s --format=%ct', shell=True, cwd=cwd).strip())).isoformat(),
        'build_timestamp': datetime.datetime.utcnow().isoformat(),
        'build_host': socket.gethostname(),
        'build_host_os': GOENV["GOHOSTOS"],
        'build_host_arch': GOENV["GOHOSTARCH"]
    }
    if md['git_tag']:
        md['version'] = md['git_tag']
        md['version_strategy'] = 'tag'
    elif not md['git_branch'] in ['master', 'HEAD'] and not md['git_branch'].startswith('release-'):
        md['version'] = md['git_branch']
        md['version_strategy'] = 'branch'
    else:
        hash_ver = subprocess.check_output('git describe --tags --always --dirty', shell=True, cwd=cwd).strip()
        md['version'] = hash_ver
        md['version_strategy'] = 'commit_hash'
    if goos:
        md['os'] = goos
    if goarch:
        md['arch'] = goarch
    return md
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号