Skip to content

Commit 7427ced

Browse files
committed
Use HCL user-defined functions to simplify tags
Also only set the "latest" tags when `TF_VERSION` is set to the upstream latest version of TensorFlow.
1 parent aeeccb8 commit 7427ced

File tree

1 file changed

+31
-26
lines changed

1 file changed

+31
-26
lines changed

docker/docker-bake.hcl

Lines changed: 31 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ variable "TF_VERSION" {
1919
default = "2.12.0"
2020
}
2121

22+
function "TF_LATEST_VERSION" {
23+
params = []
24+
result = "2.12.0" # current upstream version
25+
}
26+
2227
variable "REGISTRY" {
2328
default = "quay.io/entropyorg/"
2429
}
@@ -35,6 +40,21 @@ variable "NB_UID" {
3540
default = 1000
3641
}
3742

43+
function "device2tag" {
44+
params = [device]
45+
result = equal(device,"cpu") ? "" : equal(device,"gpu") ? "-gpu" : ""
46+
}
47+
48+
function "tag" {
49+
params = [device, suffix]
50+
result = [
51+
"${REGISTRY}${IMAGE}:${TF_VERSION}${device2tag(device)}${suffix}",
52+
equal(TF_VERSION, TF_LATEST_VERSION())
53+
? "${REGISTRY}${IMAGE}:latest${device2tag(device)}${suffix}"
54+
: "",
55+
]
56+
}
57+
3858
target "nb-all" {
3959
args = {
4060
NB_USER = NB_USER
@@ -47,66 +67,54 @@ target "nb-cpu" {
4767
inherits = [ "nb-all" ]
4868
args = {
4969
TF_DEVICE_TYPE = "cpu"
50-
TF_DEVICE_TAG = ""
70+
TF_DEVICE_TAG = "${device2tag("cpu")}"
5171
}
5272
}
5373

5474
target "nb-gpu" {
5575
inherits = [ "nb-all" ]
5676
args = {
5777
TF_DEVICE_TYPE = "gpu"
58-
TF_DEVICE_TAG = "-gpu"
78+
TF_DEVICE_TAG = "${device2tag("gpu")}"
5979
}
6080
}
6181

6282
target "base" {
63-
inherits = [ "nb-all" ]
83+
inherits = [ "nb-cpu" ]
6484
dockerfile = "docker/Dockerfile"
6585
target = "base"
66-
tags = [
67-
"${REGISTRY}${IMAGE}:latest",
68-
"${REGISTRY}${IMAGE}:${TF_VERSION}",
69-
]
86+
tags = tag("cpu", "")
7087
}
7188

7289
target "nb-image-class" {
73-
inherits = [ "nb-all" ]
90+
inherits = [ "nb-cpu" ]
7491
dockerfile = "docker/Dockerfile.nb-image-class"
7592
target = "image-classification"
7693
contexts = {
7794
base = "target:base"
7895
}
79-
tags = [
80-
"${REGISTRY}${IMAGE}:latest-nb-image-class",
81-
"${REGISTRY}${IMAGE}:${TF_VERSION}-nb-image-class",
82-
]
96+
tags = tag("cpu", "-nb-image-class")
8397
}
8498

8599
target "nb-gene-expr-pred" {
86-
inherits = [ "nb-all" ]
100+
inherits = [ "nb-cpu" ]
87101
dockerfile = "docker/Dockerfile.nb-gene-expr-pred"
88102
target = "gene-expression-prediction"
89103
contexts = {
90104
base = "target:base"
91105
}
92-
tags = [
93-
"${REGISTRY}${IMAGE}:latest-nb-gene-expr-pred",
94-
"${REGISTRY}${IMAGE}:${TF_VERSION}-nb-gene-expr-pred",
95-
]
106+
tags = tag("cpu", "-nb-gene-expr-pred")
96107
}
97108

98109
target "nb-omnibus" {
99-
inherits = [ "nb-all" ]
110+
inherits = [ "nb-cpu" ]
100111
dockerfile = "docker/Dockerfile.nb-omnibus"
101112
contexts = {
102113
base = "target:base"
103114
nb-image-class = "target:nb-image-class"
104115
nb-gene-expr-pred = "target:nb-gene-expr-pred"
105116
}
106-
tags = [
107-
"${REGISTRY}${IMAGE}:latest-nb-omnibus",
108-
"${REGISTRY}${IMAGE}:${TF_VERSION}-nb-omnibus",
109-
]
117+
tags = tag("cpu", "-nb-omnibus")
110118
}
111119

112120
target "gpu-nb-omnibus" {
@@ -122,8 +130,5 @@ target "gpu-nb-omnibus" {
122130
contexts = {
123131
nb-base = "target:nb-omnibus"
124132
}
125-
tags = [
126-
"${REGISTRY}${IMAGE}:latest-gpu-nb-omnibus",
127-
"${REGISTRY}${IMAGE}:${TF_VERSION}-gpu-nb-omnibus",
128-
]
133+
tags = tag("gpu", "-nb-omnibus")
129134
}

0 commit comments

Comments
 (0)