zotregistry.io/zot@v1.4.4-0.20231124084042-02a8ed785457/test/blackbox/restore_s3_blobs.bats (about) 1 # Note: Intended to be run as "make run-blackbox-tests" or "make run-blackbox-dedupe-nightly" 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_cloud 6 load helpers_wait 7 8 function setup_file() { 9 # Verify prerequisites are available 10 if ! $(verify_prerequisites); then 11 exit 1 12 fi 13 14 # Download test data to folder common for the entire suite, not just this file 15 skopeo --insecure-policy copy --format=oci docker://ghcr.io/project-zot/test-images/alpine:3.17.3 oci:${TEST_DATA_DIR}/alpine:1 16 # Setup zot server 17 local zot_root_dir=${BATS_FILE_TMPDIR}/zot 18 local zot_config_file_dedupe=${BATS_FILE_TMPDIR}/zot_config_dedupe.json 19 local zot_config_file_nodedupe=${BATS_FILE_TMPDIR}/zot_config_nodedupe.json 20 local ZOT_LOG_FILE_DEDUPE=${BATS_FILE_TMPDIR}/zot-log-dedupe.json 21 local ZOT_LOG_FILE_NODEDUPE=${BATS_FILE_TMPDIR}/zot-log-nodedupe.json 22 23 touch ${ZOT_LOG_FILE_NODEDUPE} 24 mkdir -p ${zot_root_dir} 25 26 cat > ${zot_config_file_dedupe}<<EOF 27 { 28 "distSpecVersion": "1.1.0-dev", 29 "storage": { 30 "rootDirectory": "${zot_root_dir}", 31 "dedupe": true, 32 "remoteCache": true, 33 "storageDriver": { 34 "name": "s3", 35 "rootdirectory": "/zot", 36 "region": "us-east-2", 37 "regionendpoint": "localhost:4566", 38 "bucket": "zot-storage", 39 "secure": false, 40 "skipverify": false 41 }, 42 "cacheDriver": { 43 "name": "dynamodb", 44 "endpoint": "http://localhost:4566", 45 "region": "us-east-2", 46 "cacheTablename": "BlobTable" 47 } 48 }, 49 "http": { 50 "address": "127.0.0.1", 51 "port": "8080" 52 }, 53 "log": { 54 "level": "debug", 55 "output": "${ZOT_LOG_FILE_DEDUPE}" 56 } 57 } 58 EOF 59 60 cat > ${zot_config_file_nodedupe}<<EOF 61 { 62 "distSpecVersion": "1.1.0-dev", 63 "storage": { 64 "rootDirectory": "${zot_root_dir}", 65 "dedupe": false, 66 "gc": false, 67 "storageDriver": { 68 "name": "s3", 69 "rootdirectory": "/zot", 70 "region": "us-east-2", 71 "regionendpoint": "localhost:4566", 72 "bucket": "zot-storage", 73 "secure": false, 74 "skipverify": false 75 } 76 }, 77 "http": { 78 "address": "127.0.0.1", 79 "port": "8080" 80 }, 81 "log": { 82 "level": "debug", 83 "output": "${ZOT_LOG_FILE_NODEDUPE}" 84 } 85 } 86 EOF 87 awslocal s3 --region "us-east-2" mb s3://zot-storage 88 awslocal dynamodb --region "us-east-2" create-table --table-name "BlobTable" --attribute-definitions AttributeName=Digest,AttributeType=S --key-schema AttributeName=Digest,KeyType=HASH --provisioned-throughput ReadCapacityUnits=10,WriteCapacityUnits=5 89 zot_serve ${zot_config_file_dedupe} 90 wait_zot_reachable 8080 91 } 92 93 function teardown() { 94 # conditionally printing on failure is possible from teardown but not from from teardown_file 95 cat ${BATS_FILE_TMPDIR}/zot-log-dedupe.json 96 cat ${BATS_FILE_TMPDIR}/zot-log-nodedupe.json || true 97 } 98 99 function teardown_file() { 100 local zot_root_dir=${BATS_FILE_TMPDIR}/zot 101 zot_stop 102 rm -rf ${zot_root_dir} 103 awslocal s3 rb s3://"zot-storage" --force 104 awslocal dynamodb --region "us-east-2" delete-table --table-name "BlobTable" 105 } 106 107 @test "push 50 images with dedupe enabled" { 108 for i in {1..50} 109 do 110 run skopeo --insecure-policy copy --dest-tls-verify=false \ 111 oci:${TEST_DATA_DIR}/alpine:1 \ 112 docker://127.0.0.1:8080/alpine${i}:1 113 [ "$status" -eq 0 ] 114 done 115 } 116 117 @test "restart zot with dedupe false and wait for restore blobs task to finish" { 118 local zot_config_file_nodedupe=${BATS_FILE_TMPDIR}/zot_config_nodedupe.json 119 local zot_root_dir=${BATS_FILE_TMPDIR}/zot 120 local ZOT_LOG_FILE=${BATS_FILE_TMPDIR}/zot-log-nodedupe.json 121 122 # stop server 123 zot_stop 124 125 sleep 10 126 127 # start with dedupe disabled 128 zot_serve ${zot_config_file_nodedupe} 129 130 sleep 1 # if we wait for zot to be reachable we may not catch the log message 131 132 start=`date +%s` 133 echo "waiting for restoring blobs task to finish" >&3 134 run wait_for_string "dedupe rebuild: finished" ${ZOT_LOG_FILE} "5m" 135 [ "$status" -eq 0 ] 136 137 end=`date +%s` 138 139 runtime=$((end-start)) 140 echo "restoring blobs finished in $runtime sec" >&3 141 sleep 10 # wait a bit more because dedupe runs in background. 142 } 143 144 @test "pulling a previous deduped image should work" { 145 wait_zot_reachable 8080 146 147 # alpine1 should have original blobs already 148 echo "pulling first image" >&3 149 run skopeo --insecure-policy copy --src-tls-verify=false \ 150 docker://127.0.0.1:8080/alpine1:1 \ 151 oci:${TEST_DATA_DIR}/alpine1:1 152 [ "$status" -eq 0 ] 153 154 echo "pulling second image" >&3 155 # alpine2 should have original blobs after restoring blobs 156 run skopeo --insecure-policy copy --src-tls-verify=false \ 157 docker://127.0.0.1:8080/alpine2:1 \ 158 oci:${TEST_DATA_DIR}/alpine2:1 159 [ "$status" -eq 0 ] 160 } 161 162