TT Bigdata TT Bigdata
首页
GitHub (opens new window)
JaneTTR

JaneTTR

数据酿造智慧,每一滴都是沉淀!
  • Ambari 深度专题

  • Bigtop 方法论

    • Bigtop 深度专题
    • 方法论

    • 组件编译技巧

    • 打包技巧-DEB

    • 打包技巧-RPM

    • 实战-日志与源码解读

      • Step0-打包完整链路
      • Step1-bigtop.bom配置
      • Step2-源码包触发下载
        • 1. 核心代码原文
        • 2. 逐段详细解读
          • 2.1 变量准备
          • 2.2 GIT/鉴权参数判定
          • 2.3 下载地址校验 & 幂等性检查
          • 2.4 核心分支:GIT拉取 or URL下载
          • 2.4.1 GIT拉取源码(优先)
          • 2.4.2 URL 直链下载
          • 2.5 状态标记,便于后续链路
        • 3. 我的做法
      • Step3-Tarball制备全流程
      • 适用于REDHAT

    • 其他技巧

  • 自定义集成

  • Ambari Server 与 Web

  • Ambari Metrics

  • Ambari Plus 思考

  • Redis集成实战

  • 通用代码模板

  • 各组件代码

  • 技术专题
  • Bigtop 方法论
  • 实战-日志与源码解读
JaneTTR
2025-07-03
目录
1. 核心代码原文
2. 逐段详细解读
2.1 变量准备
2.2 GIT/鉴权参数判定
2.3 下载地址校验 & 幂等性检查
2.4 核心分支:GIT拉取 or URL下载
2.4.1 GIT拉取源码(优先)
2.4.2 URL 直链下载
2.5 状态标记,便于后续链路
3. 我的做法

Step2-源码包触发下载

# 1. 核心代码原文

download 任务代码片段
Task t = task "${target}-download"(dependsOn: "${target}_vardefines",
        description: "Download $target artifacts",
        group: PACKAGES_GROUP) doLast {

    def final TARBALL_SRC = config.bigtop.components[target].tarball.source
    def final TARBALL_DST = config.bigtop.components[target].tarball.destination
    def final DOWNLOAD_DST = config.bigtop.components[target].downloaddst
    def final DOWNLOAD_URL = config.bigtop.components[target].downloadurl

    def final GIT_REPO = project.hasProperty('git_repo') ? project.property('git_repo') : config.bigtop.components[target].git.repo
    def final GIT_REF = project.hasProperty('git_ref') ? project.property('git_ref') : config.bigtop.components[target].git.ref
    def final GIT_DIR = project.hasProperty('git_dir') ? project.property('git_dir') : config.bigtop.components[target].git.dir
    def final GIT_COMMIT_HASH = project.hasProperty('git_commit_hash') ? project.property('git_commit_hash') : config.bigtop.components[target].git.commit_hash
    def final GIT_USER_NAME = config.bigtop.components[target].git.user ?: config.bigtop.git.user
    def final GIT_ACCESS_TOKEN = config.bigtop.components[target].git.token ?: config.bigtop.git.token

    if (!DOWNLOAD_URL && !(GIT_REPO && GIT_REF))
        return

    mkdir(DL_DIR)
    if (TARBALL_DST?.isEmpty() || new File(DOWNLOAD_DST)?.exists() || new File(config.bigtop.components[target].targetdl)?.exists()) {
        println "\tFile $DOWNLOAD_DST appears to be already downloaded. Exiting..."
        return
    }
    if (GIT_REPO && GIT_REF) {
        // ... 见下文 ...
    } else {
        download {
            src DOWNLOAD_URL
            dest DOWNLOAD_DST
            retries 3
        }
    }
    touchTargetFile(config.bigtop.components[target].targetdl)
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35

# 2. 逐段详细解读

# 2.1 变量准备

def final TARBALL_SRC = config.bigtop.components[target].tarball.source
def final TARBALL_DST = config.bigtop.components[target].tarball.destination
def final DOWNLOAD_DST = config.bigtop.components[target].downloaddst
def final DOWNLOAD_URL = config.bigtop.components[target].downloadurl
1
2
3
4
  • 用途:这些变量都从 BOM 配置自动解析出来,控制本次要拉取的源码包名字、落盘位置和下载 URL。

# 2.2 GIT/鉴权参数判定

def final GIT_REPO = project.hasProperty('git_repo') ? project.property('git_repo') : config.bigtop.components[target].git.repo
def final GIT_REF = project.hasProperty('git_ref') ? project.property('git_ref') : config.bigtop.components[target].git.ref
def final GIT_DIR = project.hasProperty('git_dir') ? project.property('git_dir') : config.bigtop.components[target].git.dir
def final GIT_COMMIT_HASH = project.hasProperty('git_commit_hash') ? project.property('git_commit_hash') : config.bigtop.components[target].git.commit_hash
def final GIT_USER_NAME = config.bigtop.components[target].git.user ?: config.bigtop.git.user
def final GIT_ACCESS_TOKEN = config.bigtop.components[target].git.token ?: config.bigtop.git.token
1
2
3
4
5
6
  • 用途:支持通过 gradle -P 覆盖配置,也可从 BOM 读取默认值。这样既支持批量自动化,也能在 CI 场景临时指定分支/仓库/commit/token。

# 2.3 下载地址校验 & 幂等性检查

if (!DOWNLOAD_URL && !(GIT_REPO && GIT_REF))
    return
1
2
  • 说明:只要没配置 http 源码包链接、又没配 git 仓库+分支,则本次无需下载,直接 return。
mkdir(DL_DIR)
if (TARBALL_DST?.isEmpty() || new File(DOWNLOAD_DST)?.exists() || new File(config.bigtop.components[target].targetdl)?.exists()) {
    println "\tFile $DOWNLOAD_DST appears to be already downloaded. Exiting..."
    return
}
1
2
3
4
5
  • 说明:只要源码包已存在(无论 tarball、download 标记文件),任务直接跳过,保证幂等性,可多次重复构建不卡壳。

# 2.4 核心分支:GIT拉取 or URL下载

# 2.4.1 GIT拉取源码(优先)

if (GIT_REPO && GIT_REF) {
    def dir = GIT_DIR
    if (dir == null || dir.isEmpty()) {
        dir = TARBALL_SRC.substring(0, TARBALL_SRC.lastIndexOf(".t"))
    }
    delete("${DL_DIR}/${dir}")
    def depth = "--depth 1"
    if (GIT_COMMIT_HASH) {
        depth = ""
    }
    // 私有仓库鉴权分支
    if (GIT_USER_NAME && GIT_ACCESS_TOKEN) {
        // ... 拼接 http(s) 认证 URL ...
        exec {
            workingDir DL_DIR
            commandLine "git clone ${depth} --branch $GIT_REF ${uri} ${dir}".split()
        }
    } else {
        exec {
            workingDir DL_DIR
            commandLine "git clone ${depth} --branch $GIT_REF ${GIT_REPO} ${dir}".split()
        }
    }
    exec {
        workingDir "$DL_DIR/${dir}"
        commandLine "git submodule update --init".split()
    }
    if (GIT_COMMIT_HASH) {
        exec {
            workingDir "$DL_DIR/${dir}"
            commandLine "git reset $GIT_COMMIT_HASH --hard".split()
        }
    }
    delete("${DL_DIR}/${dir}/.git")
    exec {
        workingDir DL_DIR
        commandLine "tar -czf ${TARBALL_DST} ${dir}".split()
    }
    delete("${DL_DIR}/${dir}")
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
  • 要点:

    • 支持 clone 指定分支或 commit,拉到后清理 .git,保证打包 tar.gz 干净无多余元数据。
    • 支持 submodule 递归拉取,防止依赖遗漏。
    • token 拼接只支持 http(s) 协议,SSH 不支持自动注入 token。
    • 拉取结束后源码目录即被删除,节省空间、保证可重入。

# 2.4.2 URL 直链下载

else {
    download {
        src DOWNLOAD_URL
        dest DOWNLOAD_DST
        retries 3
    }
}
1
2
3
4
5
6
7
  • 要点:简单直接拉包,遇到网络抖动支持最多三次自动重试。

# 2.5 状态标记,便于后续链路

touchTargetFile(config.bigtop.components[target].targetdl)
1
  • 要点:任务收尾时写入 .download 文件,后续所有构建、解压、打包都能自动检测当前组件源码状态,无需重复下载。

# 3. 我的做法

在日常大数据环境集成和自动化打包过程中,我优先推荐使用 URL 直链下载源码包,这种方式稳定、简单、高效,是绝大多数主流组件集成的首选做法。

为什么优先用 URL 下载?

  • 配置简单:只需填写 downloadurl 字段,无需关心分支、commit 或仓库权限。
  • 下载高效:支持自动断点续传与多次重试,大幅提升批量构建效率。
  • 结果可控:下载后的 tarball 文件结构清晰,便于后续自动化解包与打包。

常见配置与用法举例:

download {
    src DOWNLOAD_URL
    dest DOWNLOAD_DST
    retries 3
}
1
2
3
4
5

注意只要按下述填好即可

    tarball {
        destination = "${version.base}.tar.gz"
        source = destination
    }
    url {
        site = bigtop.gh_proxy + "https://github.com/redis/redis/archive/refs/tags/"
        archive = site
    }
1
2
3
4
5
6
7
8
#Bigtop#源码解析#Ambari#Redis#Stack集成
Step1-bigtop.bom配置
Step3-Tarball制备全流程

← Step1-bigtop.bom配置 Step3-Tarball制备全流程→

最近更新
01
当前版本 2026/08
08-29
02
把 Ambari Server HA 稳稳地跑起来
08-17
03
从一次启用操作追到主备就绪
08-17
更多文章>
Theme by Vdoing | Copyright © 2017-2026 JaneTTR | MIT License
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式