Skip to content

Commit 7389385

Browse files
committed
test images: Adds various fixes and cleanups to the image building process
Adds splitOsArch function to image-util.sh, which makes the script DRY-er. When building a Windows test image, if REMOTE_DOCKER_URL is not set, skip the rest of the building process for that image, which will save some time (no need to build binaries). If a REMOTE_DOCKER_URL was not set for a particular OS version, exclude that image from the manifest list. This fixes an issue where, if REMOTE_DOCKER_URL was not set for Windows Server 1909, the Windows were completely excluded from the manifest list, including for Windows Server 1809 and 1903 which could have been built and pushed. Sets "test-webserver" as the default CMD for kitten and nautilus. Since they are now based on agnhost, they should be set to run test-webserver to maintain previous behaviour.
1 parent 3524a5a commit 7389385

File tree

3 files changed

+39
-61
lines changed

3 files changed

+39
-61
lines changed

test/images/image-util.sh

Lines changed: 37 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,33 @@ listOsArchs() {
3434
cut -d "=" -f 1 "${image}"/BASEIMAGE
3535
}
3636

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+
3764
# Returns baseimage need to used in Dockerfile for any given architecture
3865
getBaseImage() {
3966
os_arch=$1
@@ -56,24 +83,12 @@ build() {
5683
kube::util::ensure-gnu-sed
5784

5885
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
7792
fi
7893

7994
echo "Building image for ${image} OS/ARCH: ${os_arch}..."
@@ -139,8 +154,6 @@ build() {
139154
--tlscert "${HOME}/.docker-${os_version}/cert.pem" --tlskey "${HOME}/.docker-${os_version}/key.pem" \
140155
-H "${REMOTE_DOCKER_URL}" build --pull -t "${REGISTRY}/${image}:${TAG}-${os_name}-${arch}-${os_version}" \
141156
--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."
144157
fi
145158
popd
146159
done
@@ -168,25 +181,7 @@ push() {
168181
os_archs=$(printf 'linux/%s\n' "${!QEMUARCHS[*]}")
169182
fi
170183
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}"
190185

191186
if [[ "$os_name" = "linux" ]]; then
192187
docker push "${REGISTRY}/${image}:${TAG}-${os_name}-${arch}"
@@ -197,16 +192,11 @@ push() {
197192
-H "${REMOTE_DOCKER_URL}" push "${REGISTRY}/${image}:${TAG}-${os_name}-${arch}-${os_version}"
198193
else
199194
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)
200197
fi
201198
done
202199

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-
210200
if test -z "${os_archs}"; then
211201
# this can happen for Windows-only images if they have been skipped entirely.
212202
echo "No image for the manifest list. Skipping ${image}."
@@ -223,21 +213,7 @@ push() {
223213
while IFS='' read -r line; do manifest+=("$line"); done < <(echo "$os_archs" | ${SED} "s~\/~-~g" | ${SED} -e "s~[^ ]*~$REGISTRY\/$image:$TAG\-&~g")
224214
docker manifest create --amend "${REGISTRY}/${image}:${TAG}" "${manifest[@]}"
225215
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}"
241217
docker manifest annotate --os "${os_name}" --arch "${arch}" "${REGISTRY}/${image}:${TAG}" "${REGISTRY}/${image}:${TAG}-${suffix}"
242218
done
243219
docker manifest push --purge "${REGISTRY}/${image}:${TAG}"

test/images/kitten/Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,4 @@ ARG BASEIMAGE
1616
FROM $BASEIMAGE
1717
COPY html/kitten.jpg kitten.jpg
1818
COPY html/data.json data.json
19+
CMD ["test-webserver"]

test/images/nautilus/Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,4 @@ ARG BASEIMAGE
1616
FROM $BASEIMAGE
1717
COPY html/nautilus.jpg nautilus.jpg
1818
COPY html/data.json data.json
19+
CMD ["test-webserver"]

0 commit comments

Comments
 (0)