zotregistry.io/zot@v1.4.4-0.20231124084042-02a8ed785457/test/blackbox/sync_replica_cluster.bats (about) 1 # Note: Intended to be run as "make run-blackbox-tests" or "make run-blackbox-ci" 2 # Makefile target installs & checks all necessary tooling 3 # Extra tools that are not covered in Makefile target needs to be added in verify_prerequisites() 4 5 load helpers_zot 6 7 function verify_prerequisites() { 8 if [ ! $(command -v curl) ]; then 9 echo "you need to install curl as a prerequisite to running the tests" >&3 10 return 1 11 fi 12 13 if [ ! $(command -v jq) ]; then 14 echo "you need to install jq as a prerequisite to running the tests" >&3 15 return 1 16 fi 17 18 if [ ! $(command -v docker) ]; then 19 echo "you need to install docker as a prerequisite to running the tests" >&3 20 return 1 21 fi 22 23 return 0 24 } 25 26 function setup_file() { 27 # Verify prerequisites are available 28 if ! $(verify_prerequisites); then 29 exit 1 30 fi 31 32 # Download test data to folder common for the entire suite, not just this file 33 skopeo --insecure-policy copy --format=oci docker://ghcr.io/project-zot/golang:1.20 oci:${TEST_DATA_DIR}/golang:1.20 34 # Setup zot server 35 local zot_sync_one_root_dir=${BATS_FILE_TMPDIR}/zot-one 36 local zot_sync_two_root_dir=${BATS_FILE_TMPDIR}/zot-two 37 38 local zot_sync_one_config_file=${BATS_FILE_TMPDIR}/zot_sync_one_config.json 39 local zot_sync_two_config_file=${BATS_FILE_TMPDIR}/zot_sync_two_config.json 40 41 mkdir -p ${zot_sync_one_root_dir} 42 mkdir -p ${zot_sync_two_root_dir} 43 44 zot_port1=$(get_free_port) 45 echo ${zot_port1} > ${BATS_FILE_TMPDIR}/zot.port1 46 zot_port2=$(get_free_port) 47 echo ${zot_port2} > ${BATS_FILE_TMPDIR}/zot.port2 48 49 cat >${zot_sync_one_config_file} <<EOF 50 { 51 "distSpecVersion": "1.1.0-dev", 52 "storage": { 53 "rootDirectory": "${zot_sync_one_root_dir}" 54 }, 55 "http": { 56 "address": "0.0.0.0", 57 "port": "${zot_port1}" 58 }, 59 "log": { 60 "level": "debug" 61 }, 62 "extensions": { 63 "sync": { 64 "registries": [ 65 { 66 "urls": [ 67 "http://localhost:${zot_port1}", 68 "http://localhost:${zot_port2}" 69 ], 70 "onDemand": false, 71 "tlsVerify": false, 72 "PollInterval": "1s", 73 "content": [ 74 { 75 "prefix": "**" 76 } 77 ] 78 } 79 ] 80 } 81 } 82 } 83 EOF 84 85 cat >${zot_sync_two_config_file} <<EOF 86 { 87 "distSpecVersion": "1.1.0-dev", 88 "storage": { 89 "rootDirectory": "${zot_sync_two_root_dir}" 90 }, 91 "http": { 92 "address": "0.0.0.0", 93 "port": "${zot_port2}" 94 }, 95 "log": { 96 "level": "debug" 97 }, 98 "extensions": { 99 "sync": { 100 "registries": [ 101 { 102 "urls": [ 103 "http://localhost:${zot_port1}", 104 "http://localhost:${zot_port2}" 105 ], 106 "onDemand": false, 107 "tlsVerify": false, 108 "PollInterval": "1s", 109 "content": [ 110 { 111 "prefix": "**" 112 } 113 ] 114 } 115 ] 116 } 117 } 118 } 119 EOF 120 121 git -C ${BATS_FILE_TMPDIR} clone https://github.com/project-zot/helm-charts.git 122 123 zot_serve ${ZOT_PATH} ${zot_sync_one_config_file} 124 wait_zot_reachable ${zot_port1} 125 126 zot_serve ${ZOT_PATH} ${zot_sync_two_config_file} 127 wait_zot_reachable ${zot_port2} 128 } 129 130 function teardown_file() { 131 zot_stop_all 132 } 133 134 # sync image 135 @test "push one image to zot one, zot two should sync it" { 136 zot_port1=`cat ${BATS_FILE_TMPDIR}/zot.port1` 137 zot_port2=`cat ${BATS_FILE_TMPDIR}/zot.port2` 138 run skopeo --insecure-policy copy --dest-tls-verify=false \ 139 oci:${TEST_DATA_DIR}/golang:1.20 \ 140 docker://127.0.0.1:${zot_port1}/golang:1.20 141 [ "$status" -eq 0 ] 142 run curl http://127.0.0.1:${zot_port1}/v2/_catalog 143 [ "$status" -eq 0 ] 144 [ $(echo "${lines[-1]}" | jq '.repositories[]') = '"golang"' ] 145 run curl http://127.0.0.1:${zot_port1}/v2/golang/tags/list 146 [ "$status" -eq 0 ] 147 [ $(echo "${lines[-1]}" | jq '.tags[]') = '"1.20"' ] 148 149 run sleep 30s 150 151 run curl http://127.0.0.1:${zot_port2}/v2/_catalog 152 [ "$status" -eq 0 ] 153 [ $(echo "${lines[-1]}" | jq '.repositories[]') = '"golang"' ] 154 155 run curl http://127.0.0.1:${zot_port2}/v2/golang/tags/list 156 [ "$status" -eq 0 ] 157 [ $(echo "${lines[-1]}" | jq '.tags[]') = '"1.20"' ] 158 } 159 160 @test "push one image to zot-two, zot-one should sync it" { 161 zot_port1=`cat ${BATS_FILE_TMPDIR}/zot.port1` 162 zot_port2=`cat ${BATS_FILE_TMPDIR}/zot.port2` 163 run skopeo --insecure-policy copy --dest-tls-verify=false \ 164 oci:${TEST_DATA_DIR}/golang:1.20 \ 165 docker://127.0.0.1:${zot_port2}/anothergolang:1.20 166 [ "$status" -eq 0 ] 167 run curl http://127.0.0.1:${zot_port2}/v2/_catalog 168 [ "$status" -eq 0 ] 169 [ $(echo "${lines[-1]}" | jq '.repositories[0]') = '"anothergolang"' ] 170 run curl http://127.0.0.1:${zot_port2}/v2/anothergolang/tags/list 171 [ "$status" -eq 0 ] 172 [ $(echo "${lines[-1]}" | jq '.tags[]') = '"1.20"' ] 173 174 run sleep 30s 175 176 run curl http://127.0.0.1:${zot_port1}/v2/_catalog 177 [ "$status" -eq 0 ] 178 [ $(echo "${lines[-1]}" | jq '.repositories[0]') = '"anothergolang"' ] 179 180 run curl http://127.0.0.1:${zot_port1}/v2/anothergolang/tags/list 181 [ "$status" -eq 0 ] 182 [ $(echo "${lines[-1]}" | jq '.tags[]') = '"1.20"' ] 183 }