|
1 | 1 | #!/usr/bin/env bash
|
2 | 2 |
|
3 |
| -set -e |
| 3 | +# ------------- Import some defaults for the shell |
| 4 | + |
| 5 | +# Source shell defaults |
| 6 | +# $0 is the currently running program (this file) |
| 7 | +this_file_directory=$(dirname $0) |
| 8 | +relative_path_to_defaults=$this_file_directory/../shell_defaults |
| 9 | + |
| 10 | +# if a file exists there, source it. otherwise complain |
| 11 | +if test -f $relative_path_to_defaults; then |
| 12 | + # source and '.' are the same program |
| 13 | + source $relative_path_to_defaults |
| 14 | +else |
| 15 | + echo -e "\033[31m\nFAILED TO SOURCE TEST RUNNING OPTIONS.\033[39m" |
| 16 | + echo -e "\033[31mTried $relative_path_to_defaults\033[39m" |
| 17 | + exit 1 |
| 18 | +fi |
| 19 | + |
| 20 | +set +o xtrace # +x easier human reading here |
4 | 21 |
|
5 | 22 | . tools/lib/lib.sh
|
6 | 23 |
|
| 24 | + |
7 | 25 | function docker_tag_exists() {
|
8 |
| - # Added check for images pushed to github container registry |
9 |
| - if [[ $1 == ghcr* ]] |
| 26 | + # Is true for images stored in the Github Container Registry |
| 27 | + repo=$1 |
| 28 | + tag=$2 |
| 29 | + # we user [[ here because test doesn't support globbing well |
| 30 | + if [[ $repo == ghcr* ]] |
10 | 31 | then
|
11 | 32 | TOKEN_URL=https://ghcr.io/token\?scope\="repository:$1:pull"
|
12 |
| - token=$(curl $TOKEN_URL | jq -r '.token') |
| 33 | + token=$(curl $TOKEN_URL | jq -r '.token' > /dev/null) |
13 | 34 | URL=https://ghcr.io/v2/$1/manifests/$2
|
14 |
| - printf "\tURL: %s\n" "$URL" |
15 |
| - curl --silent -H "Authorization: Bearer $token" -f -lSL "$URL" > /dev/null |
| 35 | + echo -e "$blue_text""\n\n\tURL: $URL""$default_text" |
| 36 | + curl -H "Authorization: Bearer $token" --location --silent --show-error --dump-header header.txt "$URL" > /dev/null |
| 37 | + curl_success=$? |
16 | 38 | else
|
17 | 39 | URL=https://hub.docker.com/v2/repositories/"$1"/tags/"$2"
|
18 |
| - printf "\tURL: %s\n" "$URL" |
19 |
| - curl --silent -f -lSL "$URL" > /dev/null |
| 40 | + echo -e "$blue_text""\n\n\tURL: $URL""$default_text" |
| 41 | + curl --silent --show-error --location --dump-header header.txt "$URL" > /dev/null |
| 42 | + curl_success=$? |
| 43 | + # some bullshit to get the number out of a header that looks like this |
| 44 | + # < content-length: 1039 |
| 45 | + # < x-ratelimit-limit: 180 |
| 46 | + # < x-ratelimit-reset: 1665683196 |
| 47 | + # < x-ratelimit-remaining: 180 |
| 48 | + docker_rate_limit_remaining=$(grep 'x-ratelimit-remaining: ' header.txt | grep --only-matching --extended-regexp "\d+") |
| 49 | + # too noisy when set to < 1. Dockerhub starts complaining somewhere around 10 |
| 50 | + if test "$docker_rate_limit_remaining" -lt 20; then |
| 51 | + echo -e "$red_text""We are close to a sensitive dockerhub rate limit!""$default_text" |
| 52 | + echo -e "$red_text""SLEEPING 60s sad times""$default_text" |
| 53 | + sleep 60 |
| 54 | + docker_tag_exists $1 $2 |
| 55 | + elif test $docker_rate_limit_remaining -lt 50; then |
| 56 | + echo -e "$red_text""Rate limit reported as $docker_rate_limit_remaining""$default_text" |
| 57 | + fi |
| 58 | + fi |
| 59 | + if test $curl_success -ne 0; then |
| 60 | + echo -e "$red_text""Curl Said this didn't work. Please investigate""$default_text" |
| 61 | + exit 1 |
20 | 62 | fi
|
21 | 63 | }
|
22 | 64 |
|
23 | 65 | checkPlatformImages() {
|
24 |
| - echo "Checking platform images exist..." |
25 |
| - docker-compose pull || exit 1 |
26 |
| - echo "Success! All platform images exist!" |
| 66 | + 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 |
27 | 82 | }
|
28 | 83 |
|
29 | 84 | checkNormalizationImages() {
|
| 85 | + echo -e "$blue_text""Checking Normalization images exist...""$default_text" |
30 | 86 | # the only way to know what version of normalization the platform is using is looking in NormalizationRunnerFactory.
|
31 | 87 | local image_version;
|
32 | 88 | factory_path=airbyte-commons-worker/src/main/java/io/airbyte/workers/normalization/NormalizationRunnerFactory.java
|
33 |
| - # This check should fail if the file doesn't exist, so just try to ls the file |
34 |
| - ls $factory_path > /dev/null |
| 89 | + # -f True if file exists and is a regular file |
| 90 | + if ! test -f $factory_path; then |
| 91 | + echo -e "$red_text""No NormalizationRunnerFactory found at path! H4LP!!!""$default_text" |
| 92 | + fi |
35 | 93 | image_version=$(cat $factory_path | grep 'NORMALIZATION_VERSION =' | cut -d"=" -f2 | sed 's:;::' | sed -e 's:"::g' | sed -e 's:[[:space:]]::g')
|
36 |
| - echo "Checking normalization images with version $image_version exist..." |
37 |
| - VERSION=$image_version docker-compose -f airbyte-integrations/bases/base-normalization/docker-compose.yaml pull || exit 1 |
38 |
| - echo "Success! All normalization images exist!" |
| 94 | + 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 |
39 | 103 | }
|
40 | 104 |
|
41 | 105 | checkConnectorImages() {
|
42 |
| - echo "Checking connector images exist..." |
43 |
| - |
| 106 | + echo -e "$blue_text""Checking connector images exist...""$default_text" |
44 | 107 | CONNECTOR_DEFINITIONS=$(grep "dockerRepository" -h -A1 airbyte-config/init/src/main/resources/seed/*.yaml | grep -v -- "^--$" | tr -d ' ')
|
45 | 108 | [ -z "CONNECTOR_DEFINITIONS" ] && echo "ERROR: Could not find any connector definition." && exit 1
|
46 | 109 |
|
47 | 110 | while IFS=":" read -r _ REPO; do
|
48 | 111 | IFS=":" read -r _ TAG
|
49 |
| - printf "${REPO}: ${TAG}\n" |
| 112 | + printf "\t${REPO}: ${TAG}\n" |
50 | 113 | if docker_tag_exists "$REPO" "$TAG"; then
|
51 | 114 | printf "\tSTATUS: found\n"
|
52 | 115 | else
|
53 | 116 | printf "\tERROR: not found!\n" && exit 1
|
54 | 117 | fi
|
55 |
| - # Docker hub has a rate limit of 180 requests per minute, so slow down our rate of calling the API |
56 |
| - # https://docs.docker.com/docker-hub/api/latest/#tag/rate-limiting |
57 |
| - sleep 1 |
58 | 118 | done <<< "${CONNECTOR_DEFINITIONS}"
|
59 |
| - |
60 |
| - echo "Success! All connector images exist!" |
| 119 | + echo -e "$blue_text""Success! All connector images exist!""$default_text" |
61 | 120 | }
|
62 | 121 |
|
63 | 122 | main() {
|
64 | 123 | assert_root
|
65 | 124 |
|
66 | 125 | SUBSET=${1:-all} # default to all.
|
67 | 126 | [[ ! "$SUBSET" =~ ^(all|platform|connectors)$ ]] && echo "Usage ./tools/bin/check_image_exists.sh [all|platform|connectors]" && exit 1
|
68 |
| - |
69 |
| - echo "checking images for: $SUBSET" |
| 127 | + echo -e "$blue_text""checking images for: $SUBSET""$default_text" |
70 | 128 |
|
71 | 129 | [[ "$SUBSET" =~ ^(all|platform)$ ]] && checkPlatformImages
|
72 | 130 | [[ "$SUBSET" =~ ^(all|platform|connectors)$ ]] && checkNormalizationImages
|
73 | 131 | [[ "$SUBSET" =~ ^(all|connectors)$ ]] && checkConnectorImages
|
74 |
| - |
75 |
| - echo "Image check complete." |
| 132 | + echo -e "$blue_text""Image check complete.""$default_text" |
| 133 | + test -f header.txt && rm header.txt |
| 134 | + test -f compose_output && rm compose_output |
76 | 135 | }
|
77 | 136 |
|
78 | 137 | main "$@"
|
0 commit comments