Skip to content

Commit c5936b0

Browse files
authored
[CI] Speed up check_images_exist (#18873)
* [CI] Speed up check_images_exist * Refactor to use helper function and cleanup output * Remove test for `compose_output` file
1 parent 6b21802 commit c5936b0

File tree

1 file changed

+20
-28
lines changed

1 file changed

+20
-28
lines changed

tools/bin/check_images_exist.sh

Lines changed: 20 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,18 @@ set +o xtrace # +x easier human reading here
2121

2222
. tools/lib/lib.sh
2323

24+
function check_compose_image_exist() {
25+
local compose_file=$1
26+
local tag=$2
27+
for img in `grep "image:" ${compose_file} | tr -d ' ' | cut -d ':' -f2`; do
28+
printf "\t${img}: ${tag}\n"
29+
if docker_tag_exists $img $tag; then
30+
printf "\tSTATUS: found\n\n"
31+
else
32+
printf "\tERROR: not found!\n\n" && exit 1
33+
fi
34+
done
35+
}
2436

2537
function docker_tag_exists() {
2638
# Is true for images stored in the Github Container Registry
@@ -32,12 +44,12 @@ function docker_tag_exists() {
3244
TOKEN_URL=https://ghcr.io/token\?scope\="repository:$1:pull"
3345
token=$(curl $TOKEN_URL | jq -r '.token' > /dev/null)
3446
URL=https://ghcr.io/v2/$1/manifests/$2
35-
echo -e "$blue_text""\n\n\tURL: $URL""$default_text"
47+
echo -e "$blue_text""\tURL: $URL""$default_text"
3648
curl -H "Authorization: Bearer $token" --location --silent --show-error --dump-header header.txt "$URL" > /dev/null
3749
curl_success=$?
3850
else
3951
URL=https://hub.docker.com/v2/repositories/"$1"/tags/"$2"
40-
echo -e "$blue_text""\n\n\tURL: $URL""$default_text"
52+
echo -e "$blue_text""\tURL: $URL""$default_text"
4153
curl --silent --show-error --location --dump-header header.txt "$URL" > /dev/null
4254
curl_success=$?
4355
# some bullshit to get the number out of a header that looks like this
@@ -64,21 +76,8 @@ function docker_tag_exists() {
6476

6577
checkPlatformImages() {
6678
echo -e "$blue_text""Checking platform images exist...""$default_text"
67-
#Pull without printing progress information and send error stream because that where image names are
68-
docker-compose pull --quiet 2> compose_output
69-
docker_compose_success=$?
70-
# quiet output is just SHAs ie: f8a3d002a8a6
71-
images_pulled_count=$(docker images --quiet | wc -l)
72-
if test $images_pulled_count -eq 0; then
73-
echo -e "$red_text""Nothing was pulled! This script may be broken! We expect to pull something""$default_text"
74-
exit 1
75-
elif test $docker_compose_success -eq 0; then
76-
echo -e "$blue_text""Docker successfully pulled all images""$default_text"
77-
else
78-
echo -e "$red_text""docker-compose failed to pull all images""$default_text"
79-
cat compose_output
80-
exit 1
81-
fi
79+
# Check dockerhub to see if the images exist
80+
check_compose_image_exist docker-compose.yaml $VERSION
8281
}
8382

8483
checkNormalizationImages() {
@@ -92,14 +91,8 @@ checkNormalizationImages() {
9291
fi
9392
image_version=$(cat $factory_path | grep 'NORMALIZATION_VERSION =' | cut -d"=" -f2 | sed 's:;::' | sed -e 's:"::g' | sed -e 's:[[:space:]]::g')
9493
echo -e "$blue_text""Checking normalization images with version $image_version exist...""$default_text"
95-
VERSION=$image_version docker-compose --file airbyte-integrations/bases/base-normalization/docker-compose.yaml pull --quiet
96-
docker_compose_success=$?
97-
if test $docker_compose_success -eq 0; then
98-
echo -e "$blue_text""Docker successfully pulled all images for normalization""$default_text"
99-
else
100-
echo -e "$red_text""docker-compose failed to pull all images for normalization""$default_text"
101-
exit 1
102-
fi
94+
VERSION=$image_version
95+
check_compose_image_exist airbyte-integrations/bases/base-normalization/docker-compose.yaml $VERSION
10396
}
10497

10598
checkConnectorImages() {
@@ -111,9 +104,9 @@ checkConnectorImages() {
111104
IFS=":" read -r _ TAG
112105
printf "\t${REPO}: ${TAG}\n"
113106
if docker_tag_exists "$REPO" "$TAG"; then
114-
printf "\tSTATUS: found\n"
107+
printf "\tSTATUS: found\n\n"
115108
else
116-
printf "\tERROR: not found!\n" && exit 1
109+
printf "\tERROR: not found!\n\n" && exit 1
117110
fi
118111
done <<< "${CONNECTOR_DEFINITIONS}"
119112
echo -e "$blue_text""Success! All connector images exist!""$default_text"
@@ -131,7 +124,6 @@ main() {
131124
[[ "$SUBSET" =~ ^(all|connectors)$ ]] && checkConnectorImages
132125
echo -e "$blue_text""Image check complete.""$default_text"
133126
test -f header.txt && rm header.txt
134-
test -f compose_output && rm compose_output
135127
}
136128

137129
main "$@"

0 commit comments

Comments
 (0)