zotregistry.io/zot@v1.4.4-0.20231124084042-02a8ed785457/test/blackbox/sync_docker.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 # Setup zot server 33 local zot_root_dir=${BATS_FILE_TMPDIR}/zot 34 local zot_sync_ondemand_config_file=${BATS_FILE_TMPDIR}/zot_sync_ondemand_config.json 35 zot_port=$(get_free_port) 36 echo ${zot_port} > ${BATS_FILE_TMPDIR}/zot.port 37 38 mkdir -p ${zot_root_dir} 39 40 cat >${zot_sync_ondemand_config_file} <<EOF 41 { 42 "distSpecVersion": "1.1.0-dev", 43 "storage": { 44 "rootDirectory": "${zot_root_dir}" 45 }, 46 "http": { 47 "address": "0.0.0.0", 48 "port": "${zot_port}" 49 }, 50 "log": { 51 "level": "debug", 52 "output": "/tmp/blackbox.log" 53 }, 54 "extensions": { 55 "sync": { 56 "registries": [ 57 { 58 "urls": [ 59 "https://index.docker.io" 60 ], 61 "content": [ 62 { 63 "prefix": "registry" 64 }, 65 { 66 "prefix": "archlinux" 67 } 68 ], 69 "onDemand": true, 70 "tlsVerify": true 71 }, 72 { 73 "urls": [ 74 "https://registry.k8s.io" 75 ], 76 "content": [ 77 { 78 "prefix": "kube-apiserver" 79 }, 80 { 81 "prefix": "pause" 82 }, 83 { 84 "prefix": "kube-apiserver-amd64" 85 } 86 ], 87 "onDemand": true, 88 "tlsVerify": true 89 }, 90 { 91 "urls": [ 92 "https://public.ecr.aws" 93 ], 94 "content": [ 95 { 96 "prefix": "amazonlinux/amazonlinux" 97 } 98 ], 99 "onDemand": true, 100 "tlsVerify": true 101 }, 102 { 103 "urls": [ 104 "https://gcr.io" 105 ], 106 "content": [ 107 { 108 "prefix": "google-containers/kube-proxy-amd64" 109 } 110 ], 111 "onDemand": true, 112 "tlsVerify": true 113 }, 114 { 115 "urls": [ 116 "https://mcr.microsoft.com" 117 ], 118 "content": [ 119 { 120 "prefix": "azure-cognitive-services/vision/spatial-analysis/diagnostics" 121 } 122 ], 123 "onDemand": true, 124 "tlsVerify": true 125 }, 126 { 127 "urls": [ 128 "https://registry.gitlab.com" 129 ], 130 "content": [ 131 { 132 "prefix": "gitlab-org/public-image-archive/gitlab-ee" 133 } 134 ], 135 "onDemand": true, 136 "tlsVerify": true 137 }, 138 { 139 "urls": [ 140 "https://quay.io" 141 ], 142 "content": [ 143 { 144 "prefix": "coreos/etcd" 145 } 146 ], 147 "onDemand": true, 148 "tlsVerify": true 149 }, 150 { 151 "urls": [ 152 "https://ghcr.io" 153 ], 154 "content": [ 155 { 156 "prefix": "project-zot/zot-linux-amd64" 157 } 158 ], 159 "onDemand": true, 160 "tlsVerify": true 161 } 162 ] 163 } 164 } 165 } 166 EOF 167 168 zot_serve ${ZOT_PATH} ${zot_sync_ondemand_config_file} 169 wait_zot_reachable ${zot_port} 170 } 171 172 function teardown_file() { 173 zot_stop_all 174 } 175 176 # sync image 177 @test "sync docker image list on demand" { 178 zot_port=`cat ${BATS_FILE_TMPDIR}/zot.port` 179 run skopeo --insecure-policy copy --multi-arch=all --src-tls-verify=false \ 180 docker://127.0.0.1:${zot_port}/registry \ 181 oci:${TEST_DATA_DIR} 182 [ "$status" -eq 0 ] 183 184 run curl http://127.0.0.1:${zot_port}/v2/_catalog 185 [ "$status" -eq 0 ] 186 [ $(echo "${lines[-1]}" | jq '.repositories[]') = '"registry"' ] 187 run curl http://127.0.0.1:${zot_port}/v2/registry/tags/list 188 [ "$status" -eq 0 ] 189 [ $(echo "${lines[-1]}" | jq '.tags[]') = '"latest"' ] 190 191 # make sure image is skipped when synced again 192 run skopeo --insecure-policy copy --multi-arch=all --src-tls-verify=false \ 193 docker://127.0.0.1:${zot_port}/registry \ 194 oci:${TEST_DATA_DIR} 195 [ "$status" -eq 0 ] 196 197 run $("cat /tmp/blackbox.log | grep -q registry:latest.*.skipping image because it's already synced") 198 [ "$status" -eq 0 ] 199 } 200 201 @test "sync docker image on demand" { 202 zot_port=`cat ${BATS_FILE_TMPDIR}/zot.port` 203 run skopeo --insecure-policy copy --src-tls-verify=false \ 204 docker://127.0.0.1:${zot_port}/archlinux \ 205 oci:${TEST_DATA_DIR} 206 [ "$status" -eq 0 ] 207 208 run curl http://127.0.0.1:${zot_port}/v2/_catalog 209 [ "$status" -eq 0 ] 210 [ $(echo "${lines[-1]}" | jq '.repositories[0]') = '"archlinux"' ] 211 run curl http://127.0.0.1:${zot_port}/v2/archlinux/tags/list 212 [ "$status" -eq 0 ] 213 [ $(echo "${lines[-1]}" | jq '.tags[]') = '"latest"' ] 214 215 # make sure image is skipped when synced again 216 run skopeo --insecure-policy copy --src-tls-verify=false \ 217 docker://127.0.0.1:${zot_port}/archlinux \ 218 oci:${TEST_DATA_DIR} 219 [ "$status" -eq 0 ] 220 221 run $("cat /tmp/blackbox.log | grep -q archlinux:latest.*.skipping image because it's already synced") 222 [ "$status" -eq 0 ] 223 } 224 225 @test "sync k8s image list on demand" { 226 zot_port=`cat ${BATS_FILE_TMPDIR}/zot.port` 227 run skopeo --insecure-policy copy --multi-arch=all --src-tls-verify=false \ 228 docker://127.0.0.1:${zot_port}/kube-apiserver:v1.26.0 \ 229 oci:${TEST_DATA_DIR} 230 [ "$status" -eq 0 ] 231 232 run curl http://127.0.0.1:${zot_port}/v2/_catalog 233 [ "$status" -eq 0 ] 234 [ $(echo "${lines[-1]}" | jq '.repositories[1]') = '"kube-apiserver"' ] 235 run curl http://127.0.0.1:${zot_port}/v2/kube-apiserver/tags/list 236 [ "$status" -eq 0 ] 237 [ $(echo "${lines[-1]}" | jq '.tags[]') = '"v1.26.0"' ] 238 } 239 240 @test "sync k8s image on demand" { 241 zot_port=`cat ${BATS_FILE_TMPDIR}/zot.port` 242 run skopeo --insecure-policy copy --src-tls-verify=false \ 243 docker://127.0.0.1:${zot_port}/pause \ 244 oci:${TEST_DATA_DIR} 245 [ "$status" -eq 0 ] 246 247 run curl http://127.0.0.1:${zot_port}/v2/_catalog 248 [ "$status" -eq 0 ] 249 [ $(echo "${lines[-1]}" | jq '.repositories[2]') = '"pause"' ] 250 run curl http://127.0.0.1:${zot_port}/v2/pause/tags/list 251 [ "$status" -eq 0 ] 252 [ $(echo "${lines[-1]}" | jq '.tags[]') = '"latest"' ] 253 } 254 255 @test "sync image on demand from registry.k8s.io" { 256 zot_port=`cat ${BATS_FILE_TMPDIR}/zot.port` 257 run skopeo copy docker://127.0.0.1:${zot_port}/kube-apiserver-amd64:v1.10.0 oci:${TEST_DATA_DIR} --src-tls-verify=false 258 [ "$status" -eq 0 ] 259 260 run curl http://127.0.0.1:${zot_port}/v2/_catalog 261 [ "$status" -eq 0 ] 262 [ $(echo "${lines[-1]}"| jq '.repositories | map(select(. == "kube-apiserver-amd64"))' | jq '.[]') = '"kube-apiserver-amd64"' ] 263 run curl http://127.0.0.1:${zot_port}/v2/kube-apiserver-amd64/tags/list 264 [ "$status" -eq 0 ] 265 [ $(echo "${lines[-1]}" | jq '.tags[]') = '"v1.10.0"' ] 266 } 267 268 @test "sync image on demand from aws.amazon.com/ecr" { 269 zot_port=`cat ${BATS_FILE_TMPDIR}/zot.port` 270 run skopeo copy docker://127.0.0.1:${zot_port}/amazonlinux/amazonlinux:latest oci:${TEST_DATA_DIR} --src-tls-verify=false 271 [ "$status" -eq 0 ] 272 273 run curl http://127.0.0.1:${zot_port}/v2/_catalog 274 [ "$status" -eq 0 ] 275 [ $(echo "${lines[-1]}"| jq '.repositories | map(select(. == "amazonlinux/amazonlinux"))' | jq '.[]') = '"amazonlinux/amazonlinux"' ] 276 run curl http://127.0.0.1:${zot_port}/v2/amazonlinux/amazonlinux/tags/list 277 [ "$status" -eq 0 ] 278 [ $(echo "${lines[-1]}" | jq '.tags[]') = '"latest"' ] 279 } 280 281 @test "sync image on demand from gcr.io" { 282 zot_port=`cat ${BATS_FILE_TMPDIR}/zot.port` 283 run skopeo copy docker://127.0.0.1:${zot_port}/google-containers/kube-proxy-amd64:v1.17.9 oci:${TEST_DATA_DIR} --src-tls-verify=false 284 [ "$status" -eq 0 ] 285 286 run curl http://127.0.0.1:${zot_port}/v2/_catalog 287 [ "$status" -eq 0 ] 288 [ $(echo "${lines[-1]}"| jq '.repositories | map(select(. == "google-containers/kube-proxy-amd64"))' | jq '.[]') = '"google-containers/kube-proxy-amd64"' ] 289 run curl http://127.0.0.1:${zot_port}/v2/google-containers/kube-proxy-amd64/tags/list 290 [ "$status" -eq 0 ] 291 [ $(echo "${lines[-1]}" | jq '.tags[]') = '"v1.17.9"' ] 292 } 293 294 @test "sync image on demand from mcr.microsoft.com" { 295 zot_port=`cat ${BATS_FILE_TMPDIR}/zot.port` 296 run skopeo copy docker://127.0.0.1:${zot_port}/azure-cognitive-services/vision/spatial-analysis/diagnostics:latest oci:${TEST_DATA_DIR} --src-tls-verify=false 297 [ "$status" -eq 0 ] 298 299 run curl http://127.0.0.1:${zot_port}/v2/_catalog 300 [ "$status" -eq 0 ] 301 [ $(echo "${lines[-1]}"| jq '.repositories | map(select(. == "azure-cognitive-services/vision/spatial-analysis/diagnostics"))' | jq '.[]') = '"azure-cognitive-services/vision/spatial-analysis/diagnostics"' ] 302 run curl http://127.0.0.1:${zot_port}/v2/azure-cognitive-services/vision/spatial-analysis/diagnostics/tags/list 303 [ "$status" -eq 0 ] 304 [ $(echo "${lines[-1]}" | jq '.tags[]') = '"latest"' ] 305 } 306 307 @test "sync image on demand from registry.gitlab.com" { 308 zot_port=`cat ${BATS_FILE_TMPDIR}/zot.port` 309 run skopeo copy docker://127.0.0.1:${zot_port}/gitlab-org/public-image-archive/gitlab-ee:15.11.6-ee.0 oci:${TEST_DATA_DIR} --src-tls-verify=false 310 [ "$status" -eq 0 ] 311 312 run curl http://127.0.0.1:${zot_port}/v2/_catalog 313 [ "$status" -eq 0 ] 314 [ $(echo "${lines[-1]}"| jq '.repositories | map(select(. == "gitlab-org/public-image-archive/gitlab-ee"))' | jq '.[]') = '"gitlab-org/public-image-archive/gitlab-ee"' ] 315 run curl http://127.0.0.1:${zot_port}/v2/gitlab-org/public-image-archive/gitlab-ee/tags/list 316 [ "$status" -eq 0 ] 317 [ $(echo "${lines[-1]}" | jq '.tags[]') = '"15.11.6-ee.0"' ] 318 } 319 320 @test "sync image on demand from quay.io" { 321 zot_port=`cat ${BATS_FILE_TMPDIR}/zot.port` 322 run skopeo copy docker://127.0.0.1:${zot_port}/coreos/etcd:v3.4.26 oci:${TEST_DATA_DIR} --src-tls-verify=false 323 [ "$status" -eq 0 ] 324 325 run curl http://127.0.0.1:${zot_port}/v2/_catalog 326 [ "$status" -eq 0 ] 327 [ $(echo "${lines[-1]}"| jq '.repositories | map(select(. == "coreos/etcd"))' | jq '.[]') = '"coreos/etcd"' ] 328 run curl http://127.0.0.1:${zot_port}/v2/coreos/etcd/tags/list 329 [ "$status" -eq 0 ] 330 [ $(echo "${lines[-1]}" | jq '.tags[]') = '"v3.4.26"' ] 331 } 332 333 @test "sync image on demand from ghcr.io" { 334 zot_port=`cat ${BATS_FILE_TMPDIR}/zot.port` 335 run skopeo copy docker://127.0.0.1:${zot_port}/project-zot/zot-linux-amd64:v2.0.0-rc5 oci:${TEST_DATA_DIR} --src-tls-verify=false 336 [ "$status" -eq 0 ] 337 338 run curl http://127.0.0.1:${zot_port}/v2/_catalog 339 [ "$status" -eq 0 ] 340 [ $(echo "${lines[-1]}"| jq '.repositories | map(select(. == "project-zot/zot-linux-amd64"))' | jq '.[]') = '"project-zot/zot-linux-amd64"' ] 341 run curl http://127.0.0.1:${zot_port}/v2/project-zot/zot-linux-amd64/tags/list 342 [ "$status" -eq 0 ] 343 [ $(echo "${lines[-1]}" | jq '.tags[]') = '"v2.0.0-rc5"' ] 344 } 345 346 @test "run docker with image synced from docker.io" { 347 zot_port=`cat ${BATS_FILE_TMPDIR}/zot.port` 348 local zot_root_dir=${BATS_FILE_TMPDIR}/zot 349 run rm -rf ${zot_root_dir} 350 [ "$status" -eq 0 ] 351 352 run docker run -d 127.0.0.1:${zot_port}/archlinux:latest 353 [ "$status" -eq 0 ] 354 355 run curl http://127.0.0.1:${zot_port}/v2/_catalog 356 [ "$status" -eq 0 ] 357 [ $(echo "${lines[-1]}"| jq '.repositories | map(select(. == "archlinux"))' | jq '.[]') = '"archlinux"' ] 358 run curl http://127.0.0.1:${zot_port}/v2/archlinux/tags/list 359 [ "$status" -eq 0 ] 360 [ $(echo "${lines[-1]}" | jq '.tags[]') = '"latest"' ] 361 362 run docker kill $(docker ps -q) 363 } 364 365 @test "run docker with image synced from registry.k8s.io" { 366 zot_port=`cat ${BATS_FILE_TMPDIR}/zot.port` 367 run docker run -d 127.0.0.1:${zot_port}/kube-apiserver-amd64:v1.10.0 368 [ "$status" -eq 0 ] 369 370 run curl http://127.0.0.1:${zot_port}/v2/_catalog 371 [ "$status" -eq 0 ] 372 [ $(echo "${lines[-1]}"| jq '.repositories | map(select(. == "kube-apiserver-amd64"))' | jq '.[]') = '"kube-apiserver-amd64"' ] 373 run curl http://127.0.0.1:${zot_port}/v2/kube-apiserver-amd64/tags/list 374 [ "$status" -eq 0 ] 375 [ $(echo "${lines[-1]}" | jq '.tags[]') = '"v1.10.0"' ] 376 377 run docker kill $(docker ps -q) 378 } 379 380 @test "run docker with image synced from aws.amazon.com/ecr" { 381 zot_port=`cat ${BATS_FILE_TMPDIR}/zot.port` 382 run docker run -d 127.0.0.1:${zot_port}/amazonlinux/amazonlinux:latest 383 [ "$status" -eq 0 ] 384 385 run curl http://127.0.0.1:${zot_port}/v2/_catalog 386 [ "$status" -eq 0 ] 387 [ $(echo "${lines[-1]}"| jq '.repositories | map(select(. == "amazonlinux/amazonlinux"))' | jq '.[]') = '"amazonlinux/amazonlinux"' ] 388 run curl http://127.0.0.1:${zot_port}/v2/amazonlinux/amazonlinux/tags/list 389 [ "$status" -eq 0 ] 390 [ $(echo "${lines[-1]}" | jq '.tags[]') = '"latest"' ] 391 392 run docker kill $(docker ps -q) 393 } 394 395 @test "run docker with image synced from gcr.io" { 396 zot_port=`cat ${BATS_FILE_TMPDIR}/zot.port` 397 run docker run -d 127.0.0.1:${zot_port}/google-containers/kube-proxy-amd64:v1.17.9 398 [ "$status" -eq 0 ] 399 400 run curl http://127.0.0.1:${zot_port}/v2/_catalog 401 [ "$status" -eq 0 ] 402 [ $(echo "${lines[-1]}"| jq '.repositories | map(select(. == "google-containers/kube-proxy-amd64"))' | jq '.[]') = '"google-containers/kube-proxy-amd64"' ] 403 run curl http://127.0.0.1:${zot_port}/v2/google-containers/kube-proxy-amd64/tags/list 404 [ "$status" -eq 0 ] 405 [ $(echo "${lines[-1]}" | jq '.tags[]') = '"v1.17.9"' ] 406 407 run docker kill $(docker ps -q) 408 } 409 410 @test "run docker with image synced from mcr.microsoft.com" { 411 zot_port=`cat ${BATS_FILE_TMPDIR}/zot.port` 412 run docker run -d 127.0.0.1:${zot_port}/azure-cognitive-services/vision/spatial-analysis/diagnostics:latest 413 [ "$status" -eq 0 ] 414 415 run curl http://127.0.0.1:${zot_port}/v2/_catalog 416 [ "$status" -eq 0 ] 417 [ $(echo "${lines[-1]}"| jq '.repositories | map(select(. == "azure-cognitive-services/vision/spatial-analysis/diagnostics"))' | jq '.[]') = '"azure-cognitive-services/vision/spatial-analysis/diagnostics"' ] 418 run curl http://127.0.0.1:${zot_port}/v2/azure-cognitive-services/vision/spatial-analysis/diagnostics/tags/list 419 [ "$status" -eq 0 ] 420 [ $(echo "${lines[-1]}" | jq '.tags[]') = '"latest"' ] 421 422 run docker kill $(docker ps -q) 423 } 424 425 @test "run docker with image synced from registry.gitlab.com" { 426 zot_port=`cat ${BATS_FILE_TMPDIR}/zot.port` 427 run docker run -d 127.0.0.1:${zot_port}/gitlab-org/public-image-archive/gitlab-ee:15.11.6-ee.0 428 [ "$status" -eq 0 ] 429 430 run curl http://127.0.0.1:${zot_port}/v2/_catalog 431 [ "$status" -eq 0 ] 432 [ $(echo "${lines[-1]}"| jq '.repositories | map(select(. == "gitlab-org/public-image-archive/gitlab-ee"))' | jq '.[]') = '"gitlab-org/public-image-archive/gitlab-ee"' ] 433 run curl http://127.0.0.1:${zot_port}/v2/gitlab-org/public-image-archive/gitlab-ee/tags/list 434 [ "$status" -eq 0 ] 435 [ $(echo "${lines[-1]}" | jq '.tags[]') = '"15.11.6-ee.0"' ] 436 } 437 438 @test "run docker with image synced from quay.io" { 439 zot_port=`cat ${BATS_FILE_TMPDIR}/zot.port` 440 run docker run -d 127.0.0.1:${zot_port}/coreos/etcd:v3.4.26 441 [ "$status" -eq 0 ] 442 443 run curl http://127.0.0.1:${zot_port}/v2/_catalog 444 [ "$status" -eq 0 ] 445 [ $(echo "${lines[-1]}"| jq '.repositories | map(select(. == "coreos/etcd"))' | jq '.[]') = '"coreos/etcd"' ] 446 run curl http://127.0.0.1:${zot_port}/v2/coreos/etcd/tags/list 447 [ "$status" -eq 0 ] 448 [ $(echo "${lines[-1]}" | jq '.tags[]') = '"v3.4.26"' ] 449 } 450 451 @test "run docker with image synced from ghcr.io" { 452 zot_port=`cat ${BATS_FILE_TMPDIR}/zot.port` 453 run docker run -d 127.0.0.1:${zot_port}/project-zot/zot-linux-amd64:v2.0.0-rc5 454 [ "$status" -eq 0 ] 455 456 run curl http://127.0.0.1:${zot_port}/v2/_catalog 457 [ "$status" -eq 0 ] 458 [ $(echo "${lines[-1]}"| jq '.repositories | map(select(. == "project-zot/zot-linux-amd64"))' | jq '.[]') = '"project-zot/zot-linux-amd64"' ] 459 run curl http://127.0.0.1:${zot_port}/v2/project-zot/zot-linux-amd64/tags/list 460 [ "$status" -eq 0 ] 461 [ $(echo "${lines[-1]}" | jq '.tags[]') = '"v2.0.0-rc5"' ] 462 }