@@ -34,6 +34,33 @@ listOsArchs() {
34
34
cut -d " =" -f 1 " ${image} " /BASEIMAGE
35
35
}
36
36
37
+ splitOsArch () {
38
+ image=$1
39
+ os_arch=$2
40
+
41
+ if [[ $os_arch =~ .* /.* /.* ]]; then
42
+ # for Windows, we have to support both LTS and SAC channels, so we're building multiple Windows images.
43
+ # the format for this case is: OS/ARCH/OS_VERSION.
44
+ os_name=$( echo " $os_arch " | cut -d " /" -f 1)
45
+ arch=$( echo " $os_arch " | cut -d " /" -f 2)
46
+ os_version=$( echo " $os_arch " | cut -d " /" -f 3)
47
+ suffix=" $os_name -$arch -$os_version "
48
+
49
+ # currently, GCE does not have Hyper-V support, which means that the same node cannot be used to build
50
+ # multiple versions of Windows images. Which is why we have $REMOTE_DOCKER_URL_$os_version URLs configured.
51
+ # TODO(claudiub): once Hyper-V support has been added to GCE, revert this to just $REMOTE_DOCKER_URL.
52
+ remote_docker_url_name=" REMOTE_DOCKER_URL_$os_version "
53
+ REMOTE_DOCKER_URL=$( eval echo " \$ {${remote_docker_url_name} :-}" )
54
+ elif [[ $os_arch =~ .* /.* ]]; then
55
+ os_name=$( echo " $os_arch " | cut -d " /" -f 1)
56
+ arch=$( echo " $os_arch " | cut -d " /" -f 2)
57
+ suffix=" $os_name -$arch "
58
+ else
59
+ echo " The BASEIMAGE file for the ${image} image is not properly formatted. Expected entries to start with 'os/arch', found '${os_arch} ' instead."
60
+ exit 1
61
+ fi
62
+ }
63
+
37
64
# Returns baseimage need to used in Dockerfile for any given architecture
38
65
getBaseImage () {
39
66
os_arch=$1
@@ -56,24 +83,12 @@ build() {
56
83
kube::util::ensure-gnu-sed
57
84
58
85
for os_arch in ${os_archs} ; do
59
- if [[ $os_arch =~ .* /.* /.* ]]; then
60
- # for Windows, we have to support both LTS and SAC channels, so we're building multiple Windows images.
61
- # the format for this case is: OS/ARCH/OS_VERSION.
62
- os_name=$( echo " $os_arch " | cut -d " /" -f 1)
63
- arch=$( echo " $os_arch " | cut -d " /" -f 2)
64
- os_version=$( echo " $os_arch " | cut -d " /" -f 3)
65
-
66
- # currently, GCE does not have Hyper-V support, which means that the same node cannot be used to build
67
- # multiple versions of Windows images. Which is why we have $REMOTE_DOCKER_URL_$os_version URLs configured.
68
- # TODO(claudiub): once Hyper-V support has been added to GCE, revert this to just $REMOTE_DOCKER_URL.
69
- remote_docker_url_name=" REMOTE_DOCKER_URL_$os_version "
70
- REMOTE_DOCKER_URL=$( eval echo " \$ {${remote_docker_url_name} :-}" )
71
- elif [[ $os_arch =~ .* /.* ]]; then
72
- os_name=$( echo " $os_arch " | cut -d " /" -f 1)
73
- arch=$( echo " $os_arch " | cut -d " /" -f 2)
74
- else
75
- echo " The BASEIMAGE file for the ${image} image is not properly formatted. Expected entries to start with 'os/arch', found '${os_arch} ' instead."
76
- exit 1
86
+ splitOsArch " ${image} " " ${os_arch} "
87
+ if [[ " ${os_name} " == " windows" && -z " ${REMOTE_DOCKER_URL} " ]]; then
88
+ # If we have a Windows os_arch entry but no Remote Docker Daemon for it,
89
+ # we should skip it, so we don't have to build any binaries for it.
90
+ echo " Cannot build the image '${image} ' for ${os_arch} . REMOTE_DOCKER_URL_$os_version should be set, containing the URL to a Windows docker daemon."
91
+ continue
77
92
fi
78
93
79
94
echo " Building image for ${image} OS/ARCH: ${os_arch} ..."
@@ -139,8 +154,6 @@ build() {
139
154
--tlscert " ${HOME} /.docker-${os_version} /cert.pem" --tlskey " ${HOME} /.docker-${os_version} /key.pem" \
140
155
-H " ${REMOTE_DOCKER_URL} " build --pull -t " ${REGISTRY} /${image} :${TAG} -${os_name} -${arch} -${os_version} " \
141
156
--build-arg BASEIMAGE=" ${BASEIMAGE} " -f $dockerfile_name .
142
- else
143
- echo " Cannot build the image '${image} ' for ${os_arch} . REMOTE_DOCKER_URL_$os_version should be set, containing the URL to a Windows docker daemon."
144
157
fi
145
158
popd
146
159
done
@@ -168,25 +181,7 @@ push() {
168
181
os_archs=$( printf ' linux/%s\n' " ${! QEMUARCHS[*]} " )
169
182
fi
170
183
for os_arch in ${os_archs} ; do
171
- if [[ $os_arch =~ .* /.* /.* ]]; then
172
- # for Windows, we have to support both LTS and SAC channels, so we're building multiple Windows images.
173
- # the format for this case is: OS/ARCH/OS_VERSION.
174
- os_name=$( echo " $os_arch " | cut -d " /" -f 1)
175
- arch=$( echo " $os_arch " | cut -d " /" -f 2)
176
- os_version=$( echo " $os_arch " | cut -d " /" -f 3)
177
-
178
- # currently, GCE does not have Hyper-V support, which means that the same node cannot be used to build
179
- # multiple versions of Windows images. Which is why we have $REMOTE_DOCKER_URL_$os_version URLs configured.
180
- # TODO(claudiub): once Hyper-V support has been added to GCE, revert this to just $REMOTE_DOCKER_URL.
181
- remote_docker_url_name=" REMOTE_DOCKER_URL_$os_version "
182
- REMOTE_DOCKER_URL=$( eval echo " \$ {${remote_docker_url_name} :-}" )
183
- elif [[ $os_arch =~ .* /.* ]]; then
184
- os_name=$( echo " $os_arch " | cut -d " /" -f 1)
185
- arch=$( echo " $os_arch " | cut -d " /" -f 2)
186
- else
187
- echo " The BASEIMAGE file for the ${image} image is not properly formatted. Expected entries to start with 'os/arch', found '${os_arch} ' instead."
188
- exit 1
189
- fi
184
+ splitOsArch " ${image} " " ${os_arch} "
190
185
191
186
if [[ " $os_name " = " linux" ]]; then
192
187
docker push " ${REGISTRY} /${image} :${TAG} -${os_name} -${arch} "
@@ -197,16 +192,11 @@ push() {
197
192
-H " ${REMOTE_DOCKER_URL} " push " ${REGISTRY} /${image} :${TAG} -${os_name} -${arch} -${os_version} "
198
193
else
199
194
echo " Cannot push the image '${image} ' for ${os_arch} . REMOTE_DOCKER_URL_${os_version} should be set, containing the URL to a Windows docker daemon."
195
+ # we should exclude this image from the manifest list as well, we couldn't build / push it.
196
+ os_archs=$( printf " %s\n" " $os_archs " | grep -v " $os_arch " || true)
200
197
fi
201
198
done
202
199
203
- # NOTE(claudiub): if the REMOTE_DOCKER_URL var is not set, or it is an empty string, we mustn't include
204
- # Windows images into the manifest list.
205
- if test -z " ${REMOTE_DOCKER_URL:- } " && printf " %s\n" " $os_archs " | grep -q ' ^windows' ; then
206
- echo " Skipping pushing the image '${image} ' for Windows. REMOTE_DOCKER_URL_\$ {os_version} should be set, containing the URL to a Windows docker daemon."
207
- os_archs=$( printf " %s\n" " $os_archs " | grep -v " ^windows" || true)
208
- fi
209
-
210
200
if test -z " ${os_archs} " ; then
211
201
# this can happen for Windows-only images if they have been skipped entirely.
212
202
echo " No image for the manifest list. Skipping ${image} ."
@@ -223,21 +213,7 @@ push() {
223
213
while IFS=' ' read -r line; do manifest+=(" $line " ); done < <( echo " $os_archs " | ${SED} " s~\/~-~g" | ${SED} -e " s~[^ ]*~$REGISTRY \/$image :$TAG \-&~g" )
224
214
docker manifest create --amend " ${REGISTRY} /${image} :${TAG} " " ${manifest[@]} "
225
215
for os_arch in ${os_archs} ; do
226
- if [[ $os_arch =~ .* /.* /.* ]]; then
227
- # for Windows, we have to support both LTS and SAC channels, so we're building multiple Windows images.
228
- # the format for this case is: OS/ARCH/OS_VERSION.
229
- os_name=$( echo " $os_arch " | cut -d " /" -f 1)
230
- arch=$( echo " $os_arch " | cut -d " /" -f 2)
231
- os_version=$( echo " $os_arch " | cut -d " /" -f 3)
232
- suffix=" $os_name -$arch -$os_version "
233
- elif [[ $os_arch =~ .* /.* ]]; then
234
- os_name=$( echo " $os_arch " | cut -d " /" -f 1)
235
- arch=$( echo " $os_arch " | cut -d " /" -f 2)
236
- suffix=" $os_name -$arch "
237
- else
238
- echo " The BASEIMAGE file for the ${image} image is not properly formatted. Expected entries to start with 'os/arch', found '${os_arch} ' instead."
239
- exit 1
240
- fi
216
+ splitOsArch " ${image} " " ${os_arch} "
241
217
docker manifest annotate --os " ${os_name} " --arch " ${arch} " " ${REGISTRY} /${image} :${TAG} " " ${REGISTRY} /${image} :${TAG} -${suffix} "
242
218
done
243
219
docker manifest push --purge " ${REGISTRY} /${image} :${TAG} "
0 commit comments