-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasic.hcl
More file actions
86 lines (73 loc) · 2.2 KB
/
basic.hcl
File metadata and controls
86 lines (73 loc) · 2.2 KB
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
// ../build 命令会自动设置的变量
variable "BUILD_USER" { default = "" }
variable "BUILD_NAME" { default = "" }
variable "BUILD_IMAGE" {
default = notequal("", BUILD_USER) ? "${BUILD_USER}/${BUILD_NAME}" : "${BUILD_NAME}"
}
variable "BUILD_PLATFORM" {
default = "linux/amd64,linux/arm64,linux/arm/v7,linux/arm/v6"
}
// ===
// 相应的hcl文件可重写
// 最新的版本 image:latest安装的版本
variable "VERSION" { default = "" }
// 多架构平台使用的平台 不设置默认为 BUILD_PLATFORM
variable "PLATFORM" { default = "" }
variable "USE_DEFAULT_TARGET" { default = false }
variable "MULTI_TARGET" { default = false }
function "_v_fmt" {
params = [fmt, value]
result = value != "" ? format(fmt, value) : ""
}
function "genImage" {
params = [img, ver]
result = "${_v_fmt("%s/", BUILD_USER)}${img}${_v_fmt(":%s", ver)}"
}
function "latestImage" {
params = [img]
result = genImage(img, "")
}
function "latestImages" {
params = [img]
variadic_params = vers
result = concat([latestImage(img)], [for v in vers: genImage(img, v) if v != ""])
}
function "_gen_tags" {
params = [items]
result = formatlist("${BUILD_IMAGE}:%s", [for s in items : s if s != ""])
}
function "genTags" {
params = []
variadic_params = items
result = _gen_tags(items)
}
function "genLatestTags" {
params = []
variadic_params = items
result = concat([BUILD_IMAGE], _gen_tags(items))
}
function "defaultPlatforms" {
params = []
result = split(",", BUILD_PLATFORM)
}
function "genPlatforms" {
params = [plats]
result = split(",", plats != "" ? plats : BUILD_PLATFORM)
}
function "validTargetName" {
params = [str]
result = replace(str, ".", "_")
}
// ===
target "base" {
tags = genLatestTags(VERSION)
platforms = genPlatforms(PLATFORM)
args = VERSION != "" ? { VERSION = "${VERSION}" } : {}
}
// 只是一个别名
// 当 MULTI_TARGET==false 继承自 default
// 当 MULTI_TARGET==true 且 VERSION 存在 继承自 VERSION TARGET (将版本号的.改为_)
// 否则 继承自 base
target "latest" {
inherits = [MULTI_TARGET ? (VERSION != "" ? validTargetName(VERSION) : "base") : "default"]
}