Step3-Tarball制备全流程
# 1. 流程结构一览
提示
本环节负责组件源码包(tarball)的归档、规整和入库,是所有下游打包步骤(如 RPM/DEB 构建)的前置条件。
# 2. 核心代码全注释
下面对 gradle 脚本代码逐行添加中文注释,并适当块状分组,便于新手和二次集成时快速定位业务逻辑。
task "${target}-tar"(
dependsOn: ["${target}_vardefines", "${target}-download"],
description: "Preparing a tarball for $target artifacts",
group: PACKAGES_GROUP
) doLast {
// 1. 检查目标产物文件是否已存在,如果存在则直接退出(支持增量构建)
if (new File(config.bigtop.components[target].targettar)?.exists()) {
println "\tNothing to do. Exiting..."
return
}
// 2. 预定义主要变量,便于后续多分支处理
def final TAR_DIR = config.bigtop.components[target].tardir // 解包/规整的临时目录
def final TARBALL_SRC = config.bigtop.components[target].tarball.source ?: "" // 源码包路径(zip、tar.gz 或空)
def final TARBALL_DST = config.bigtop.components[target].tarball.destination // 目标 tar 包名
def final DOWNLOAD_DST = config.bigtop.components[target].downloaddst ?: "" // 实际下载的包路径
def final SEED_TAR = config.bigtop.components[target].seedtar // 归档后的 tarball 产物名
// 3. 清理历史产物,创建全新目录
safeDelete(TAR_DIR)
mkdir(TAR_DIR)
// 4. 判断源码包类型分支(zip/空包/其他tar.gz)
if (TARBALL_SRC.isEmpty() || TARBALL_SRC.endsWith('.zip')) {
if (TARBALL_SRC.isEmpty()) {
// 4.1 源码包为空(如 bigtop-utils),只归档 LICENSE 文件
copy {
from 'LICENSE'
into TAR_DIR
}
} else {
// 4.2 若是 zip 包,先解包到临时目录
exec {
workingDir TAR_DIR
commandLine "unzip $DOWNLOAD_DST".split(' ')
}
def unpacked = new File(TAR_DIR)
// 4.3 如果解包结果只有一级目录,则需要把内容“平铺”到当前目录(兼容常见 zip 层级)
if (unpacked.list().size() == 1) {
def TOP_LEVEL_DIR = unpacked.list()[0]
new File("$TAR_DIR/$TOP_LEVEL_DIR").list({ d, f ->
(f != "." && f != "..")
}).each { f ->
new File("$TAR_DIR/$TOP_LEVEL_DIR/$f").renameTo("$TAR_DIR/$f")
}
safeDelete(TOP_LEVEL_DIR)
}
}
// 4.4 重新打包为统一格式 tar.gz,供 RPM/DEB 构建
exec {
workingDir "$TAR_DIR/.."
commandLine "tar -czf $SEED_TAR ${new File("$TAR_DIR/..").list().join(' ')}".split(' ')
}
} else {
// 5. 直接拷贝 tar.gz 包,无需解压与规整
println "Copy $DOWNLOAD_DST to $SEED_TAR"
copy {
from DOWNLOAD_DST
into config.bigtop.builddir + "/$target/tar/"
rename TARBALL_DST, SEED_TAR
}
}
// 6. 标记当前产物(touch 文件),供下游流程判断构建状态
touchTargetFile(config.bigtop.components[target].targettar)
}
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# 3. 日志还原执行过程
结合日志可以清楚对照每一步行为与脚本分支:
- 启动 redis-tar 任务
- 清理(rm -rf)目标目录
- 拷贝 redis-7.4.0.tar.gz 到 tar 目录
- 产物 touch 标记,整个 tarball 步骤结束
07:45:49.225 [INFO] ... > Task :redis-tar
...
07:45:49.226 [DEBUG] ... Command: rm -rf /opt/modules/bigtop/build/redis/tar/redis-7.4.0
...
07:45:49.232 [QUIET] [system.out] Copy /opt/modules/bigtop/dl/7.4.0.tar.gz to /opt/modules/bigtop/build/redis/tar/7.4.0.tar.gz
...
07:45:49.260 [INFO] ... [ant:touch] Creating /opt/modules/bigtop/build/redis/.tar
1
2
3
4
5
6
7
2
3
4
5
6
7
# 4. 执行流程分支梳理
分支场景 | 行为描述 | 说明举例 |
---|---|---|
tar.gz 源码包 | 直接 copy 并重命名为 seedtar | 绝大多数大数据主流组件 |
zip 源码包 | 解包 -> 平铺主目录 -> 重新 tar.gz 归档 | 个别开源项目社区分发包 |
空包/特殊组件 | 仅 copy LICENSE 文件 | 适用于 bigtop-utils |
产物已存在 | 检查 targettar 存在,存在则直接跳过 | 增量构建常见逻辑 |
- 01
- bigtop-select 打包缺 compat 报错修复 deb07-16
- 02
- bigtop-select 打包缺 control 文件报错修复 deb07-16
- 03
- 首次编译-环境初始化 必装07-16