Skip to content

Commit 8b9f028

Browse files
authored
Merge pull request kubernetes#103156 from claudiubelu/windows-osversion-cleanup
images: Removes OS Version workaround for manifest list images
2 parents 4c498db + a7c48e9 commit 8b9f028

File tree

4 files changed

+14
-33
lines changed

4 files changed

+14
-33
lines changed

build/pause/Makefile

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -81,21 +81,13 @@ push-manifest:
8181
docker manifest create --amend $(IMAGE):$(TAG) $(shell echo $(ALL_OS_ARCH) | sed -e "s~[^ ]*~$(IMAGE):$(TAG)\-&~g")
8282
set -x; for arch in $(ALL_ARCH.linux); do docker manifest annotate --os linux --arch $${arch} ${IMAGE}:${TAG} ${IMAGE}:${TAG}-linux-$${arch}; done
8383
# For Windows images, we also need to include the "os.version" in the manifest list, so the Windows node can pull the proper image it needs.
84-
# At the moment, docker manifest annotate doesn't allow us to set the os.version, so we'll have to it ourselves. The manifest list can be found locally as JSONs.
85-
# See: https://github.com/moby/moby/issues/41417
86-
# If the ${REGISTRY} is on dockerhub, the prefix "docker.io/" is optional. However, we need the full
87-
# registry name for setting the os.version for Windows images below.
88-
# If the registry name does not contain any slashes, we prepend "docker.io/"
89-
# TODO(claudiub): Clean this up once the above issue has been fixed.
84+
# we use awk to also trim the quotes around the OS version string.
9085
set -x; \
91-
registry_prefix=$(shell (echo ${REGISTRY} | grep -Eq ".*\/.*") && echo "" || echo "docker.io/"); \
92-
manifest_image_folder=`echo "$${registry_prefix}${IMAGE}" | sed "s|/|_|g" | sed "s/:/-/"`; \
9386
for arch in $(ALL_ARCH.windows); do \
9487
for osversion in ${ALL_OSVERSIONS.windows}; do \
95-
docker manifest annotate --os windows --arch $${arch} ${IMAGE}:${TAG} ${IMAGE}:${TAG}-windows-$${arch}-$${osversion}; \
9688
BASEIMAGE=${BASE.windows}:$${osversion}; \
97-
full_version=`docker manifest inspect ${BASE.windows}:$${osversion} | grep "os.version" | head -n 1 | awk '{print $$2}'` || true; \
98-
sed -i -r "s/(\"os\"\:\"windows\")/\0,\"os.version\":$${full_version}/" "${HOME}/.docker/manifests/$${manifest_image_folder}-${TAG}/$${manifest_image_folder}-${TAG}-windows-$${arch}-$${osversion}"; \
89+
full_version=`docker manifest inspect ${BASE.windows}:$${osversion} | grep "os.version" | head -n 1 | awk -F\" '{print $$4}'` || true; \
90+
docker manifest annotate --os windows --arch $${arch} --os-version $${full_version} ${IMAGE}:${TAG} ${IMAGE}:${TAG}-windows-$${arch}-$${osversion}; \
9991
done; \
10092
done
10193
docker manifest push --purge ${IMAGE}:${TAG}

build/pause/cloudbuild.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ options:
44
substitution_option: ALLOW_LOOSE
55
machineType: 'N1_HIGHCPU_8'
66
steps:
7-
- name: 'gcr.io/k8s-testimages/gcb-docker-gcloud:v20200422-b25d964'
7+
- name: 'gcr.io/k8s-testimages/gcb-docker-gcloud:v20210622-762366a'
88
entrypoint: 'bash'
99
dir: ./build/pause
1010
env:

test/images/cloudbuild.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ options:
99
substitution_option: ALLOW_LOOSE
1010
machineType: 'N1_HIGHCPU_8'
1111
steps:
12-
- name: 'gcr.io/k8s-testimages/gcb-docker-gcloud:v20201130-750d12f'
12+
- name: 'gcr.io/k8s-testimages/gcb-docker-gcloud:v20210622-762366a'
1313
entrypoint: 'bash'
1414
dir: ./test/images/
1515
env:

test/images/image-util.sh

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ declare -A WINDOWS_OS_VERSIONS_MAP
4343
initWindowsOsVersions() {
4444
for os_version in "${windows_os_versions[@]}"; do
4545
img_base="mcr.microsoft.com/windows/nanoserver:${os_version}"
46-
full_version=$(docker manifest inspect "${img_base}" | grep "os.version" | head -n 1 | awk '{print $2}') || true
46+
# we use awk to also trim the quotes around the OS version string.
47+
full_version=$(docker manifest inspect "${img_base}" | grep "os.version" | head -n 1 | awk -F\" '{print $4}') || true
4748
WINDOWS_OS_VERSIONS_MAP["${os_version}"]="${full_version}"
4849
done
4950
}
@@ -193,10 +194,11 @@ build() {
193194
}
194195

195196
docker_version_check() {
196-
# docker buildx has been introduced in 19.03, so we need to make sure we have it.
197+
# docker manifest annotate --os-version has been introduced in 20.10.0,
198+
# so we need to make sure we have it.
197199
docker_version=$(docker version --format '{{.Client.Version}}' | cut -d"-" -f1)
198-
if [[ ${docker_version} != 19.03.0 && ${docker_version} < 19.03.0 ]]; then
199-
echo "Minimum docker version 19.03.0 is required for using docker buildx: ${docker_version}]"
200+
if [[ ${docker_version} != 20.10.0 && ${docker_version} < 20.10.0 ]]; then
201+
echo "Minimum docker version 20.10.0 is required for annotating the OS Version in the manifest list images: ${docker_version}]"
200202
exit 1
201203
fi
202204
}
@@ -229,29 +231,16 @@ push() {
229231
while IFS='' read -r line; do manifest+=("$line"); done < <(echo "$os_archs" | "${SED}" "s~\/~-~g" | "${SED}" -e "s~[^ ]*~$REGISTRY\/$image:$TAG\-&~g")
230232
docker manifest create --amend "${REGISTRY}/${image}:${TAG}" "${manifest[@]}"
231233

232-
# We will need the full registry name in order to set the "os.version" for Windows images.
233-
# If the ${REGISTRY} dcesn't have any slashes, it means that it's on dockerhub.
234-
registry_prefix=""
235-
if [[ ! $REGISTRY =~ .*/.* ]]; then
236-
registry_prefix="docker.io/"
237-
fi
238-
# The images in the manifest list are stored locally. The folder / file name is almost the same,
239-
# with a few changes.
240-
manifest_image_folder=$(echo "${registry_prefix}${REGISTRY}/${image}:${TAG}" | sed "s|/|_|g" | sed "s/:/-/")
241-
242234
for os_arch in ${os_archs}; do
243235
splitOsArch "${image}" "${os_arch}"
244-
docker manifest annotate --os "${os_name}" --arch "${arch}" "${REGISTRY}/${image}:${TAG}" "${REGISTRY}/${image}:${TAG}-${suffix}"
245236

246237
# For Windows images, we also need to include the "os.version" in the manifest list, so the Windows node
247238
# can pull the proper image it needs.
248239
if [[ "$os_name" = "windows" ]]; then
249240
full_version="${WINDOWS_OS_VERSIONS_MAP[$os_version]}"
250-
251-
# At the moment, docker manifest annotate doesn't allow us to set the os.version, so we'll have to
252-
# it ourselves. The manifest list can be found locally as JSONs.
253-
sed -i -r "s/(\"os\"\:\"windows\")/\0,\"os.version\":$full_version/" \
254-
"${HOME}/.docker/manifests/${manifest_image_folder}/${manifest_image_folder}-${suffix}"
241+
docker manifest annotate --os "${os_name}" --arch "${arch}" --os-version "${full_version}" "${REGISTRY}/${image}:${TAG}" "${REGISTRY}/${image}:${TAG}-${suffix}"
242+
else
243+
docker manifest annotate --os "${os_name}" --arch "${arch}" "${REGISTRY}/${image}:${TAG}" "${REGISTRY}/${image}:${TAG}-${suffix}"
255244
fi
256245
done
257246
popd

0 commit comments

Comments
 (0)