zotregistry.dev/zot@v1.4.4-0.20240314164342-eec277e14d20/test/blackbox/pushpull_running_dedupe.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_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 return 0 19 } 20 21 function setup_file() { 22 # Verify prerequisites are available 23 if ! $(verify_prerequisites); then 24 exit 1 25 fi 26 # Download test data to folder common for the entire suite, not just this file 27 skopeo --insecure-policy copy --format=oci docker://ghcr.io/project-zot/test-images/alpine:3.17.3 oci:${TEST_DATA_DIR}/alpine:1 28 # Setup zot server 29 local zot_root_dir=${BATS_FILE_TMPDIR}/zot 30 local zot_config_file=${BATS_FILE_TMPDIR}/zot_config.json 31 local oci_data_dir=${BATS_FILE_TMPDIR}/oci 32 mkdir -p ${zot_root_dir} 33 mkdir -p ${oci_data_dir} 34 cat > ${zot_config_file}<<EOF 35 { 36 "distSpecVersion": "1.1.0", 37 "storage": { 38 "rootDirectory": "${zot_root_dir}", 39 "dedupe": false, 40 "gc": true, 41 "gcInterval": "30s" 42 }, 43 "http": { 44 "address": "0.0.0.0", 45 "port": "8080" 46 }, 47 "log": { 48 "level": "debug", 49 "output": "${BATS_FILE_TMPDIR}/zot.log" 50 } 51 } 52 EOF 53 git -C ${BATS_FILE_TMPDIR} clone https://github.com/project-zot/helm-charts.git 54 zot_serve ${ZOT_PATH} ${zot_config_file} 55 wait_zot_reachable 8080 56 } 57 58 function teardown() { 59 # conditionally printing on failure is possible from teardown but not from from teardown_file 60 cat ${BATS_FILE_TMPDIR}/zot.log 61 } 62 63 function teardown_file() { 64 zot_stop_all 65 } 66 67 @test "push image - dedupe not running" { 68 start=`date +%s` 69 run skopeo --insecure-policy copy --dest-tls-verify=false \ 70 oci:${TEST_DATA_DIR}/alpine:1 \ 71 docker://127.0.0.1:8080/alpine:1 72 [ "$status" -eq 0 ] 73 end=`date +%s` 74 75 runtime=$((end-start)) 76 echo "push image exec time: $runtime sec" >&3 77 78 run curl http://127.0.0.1:8080/v2/_catalog 79 [ "$status" -eq 0 ] 80 [ $(echo "${lines[-1]}" | jq '.repositories[]') = '"alpine"' ] 81 run curl http://127.0.0.1:8080/v2/alpine/tags/list 82 [ "$status" -eq 0 ] 83 [ $(echo "${lines[-1]}" | jq '.tags[]') = '"1"' ] 84 } 85 86 @test "pull image - dedupe not running" { 87 local oci_data_dir=${BATS_FILE_TMPDIR}/oci 88 start=`date +%s` 89 run skopeo --insecure-policy copy --src-tls-verify=false \ 90 docker://127.0.0.1:8080/alpine:1 \ 91 oci:${oci_data_dir}/alpine:1 92 [ "$status" -eq 0 ] 93 end=`date +%s` 94 95 runtime=$((end-start)) 96 echo "pull image exec time: $runtime sec" >&3 97 run cat ${BATS_FILE_TMPDIR}/oci/alpine/index.json 98 [ "$status" -eq 0 ] 99 [ $(echo "${lines[-1]}" | jq '.manifests[].annotations."org.opencontainers.image.ref.name"') = '"1"' ] 100 } 101 102 @test "push 50 images with dedupe disabled" { 103 for i in {1..50} 104 do 105 run skopeo --insecure-policy copy --dest-tls-verify=false \ 106 oci:${TEST_DATA_DIR}/alpine:1 \ 107 docker://127.0.0.1:8080/alpine${i}:1 108 [ "$status" -eq 0 ] 109 done 110 } 111 112 @test "restart zot with dedupe enabled" { 113 local zot_config_file=${BATS_FILE_TMPDIR}/zot_config.json 114 115 # stop server 116 zot_stop_all 117 118 # enable dedupe 119 sed -i 's/false/true/g' ${zot_config_file} 120 121 zot_serve ${ZOT_PATH} ${zot_config_file} 122 123 # sleep a bit before running wait_zot_reachable(curl) 124 sleep 5 125 126 wait_zot_reachable 8080 127 # deduping will now run in background (task scheduler) while we push images, shouldn't interfere 128 } 129 130 @test "push image - dedupe running" { 131 start=`date +%s` 132 run skopeo --insecure-policy copy --dest-tls-verify=false \ 133 oci:${TEST_DATA_DIR}/alpine:1 \ 134 docker://127.0.0.1:8080/dedupe/alpine:1 135 [ "$status" -eq 0 ] 136 end=`date +%s` 137 138 runtime=$((end-start)) 139 echo "push image exec time: $runtime sec" >&3 140 } 141 142 @test "pull image - dedupe running" { 143 local oci_data_dir=${BATS_FILE_TMPDIR}/oci 144 145 mkdir -p ${oci_data_dir}/dedupe/ 146 147 start=`date +%s` 148 run skopeo --insecure-policy copy --src-tls-verify=false \ 149 docker://127.0.0.1:8080/dedupe/alpine:1 \ 150 oci:${oci_data_dir}/dedupe/alpine:1 151 [ "$status" -eq 0 ] 152 end=`date +%s` 153 runtime=$((end-start)) 154 155 echo "pull image exec time: $runtime sec" >&3 156 } 157 158 @test "pull deduped image - dedupe running" { 159 local oci_data_dir=${BATS_FILE_TMPDIR}/oci 160 161 mkdir -p ${oci_data_dir}/dedupe/ 162 163 start=`date +%s` 164 run skopeo --insecure-policy copy --src-tls-verify=false \ 165 docker://127.0.0.1:8080/alpine2:1 \ 166 oci:${oci_data_dir}/dedupe/alpine2:1 167 [ "$status" -eq 0 ] 168 end=`date +%s` 169 runtime=$((end-start)) 170 171 echo "pull image exec time: $runtime sec" >&3 172 } 173 174 @test "push image index - dedupe running" { 175 # --multi-arch below pushes an image index (containing many images) instead 176 # of an image manifest (single image) 177 start=`date +%s` 178 run skopeo --insecure-policy copy --format=oci --dest-tls-verify=false --multi-arch=all \ 179 docker://public.ecr.aws/docker/library/busybox:latest \ 180 docker://127.0.0.1:8080/busybox:latest 181 [ "$status" -eq 0 ] 182 end=`date +%s` 183 runtime=$((end-start)) 184 185 echo "push image index exec time: $runtime sec" >&3 186 run curl http://127.0.0.1:8080/v2/busybox/tags/list 187 [ "$status" -eq 0 ] 188 [ $(echo "${lines[-1]}" | jq '.tags[]') = '"latest"' ] 189 } 190 191 @test "pull image index - dedupe running" { 192 local oci_data_dir=${BATS_FILE_TMPDIR}/oci 193 start=`date +%s` 194 run skopeo --insecure-policy copy --src-tls-verify=false --multi-arch=all \ 195 docker://127.0.0.1:8080/busybox:latest \ 196 oci:${oci_data_dir}/busybox:latest 197 [ "$status" -eq 0 ] 198 end=`date +%s` 199 runtime=$((end-start)) 200 201 echo "pull image index exec time: $runtime sec" >&3 202 run cat ${BATS_FILE_TMPDIR}/oci/busybox/index.json 203 [ "$status" -eq 0 ] 204 [ $(echo "${lines[-1]}" | jq '.manifests[].annotations."org.opencontainers.image.ref.name"') = '"latest"' ] 205 run skopeo --insecure-policy --override-arch=arm64 --override-os=linux copy --src-tls-verify=false --multi-arch=all \ 206 docker://127.0.0.1:8080/busybox:latest \ 207 oci:${oci_data_dir}/busybox:latest 208 [ "$status" -eq 0 ] 209 run cat ${BATS_FILE_TMPDIR}/oci/busybox/index.json 210 [ "$status" -eq 0 ] 211 [ $(echo "${lines[-1]}" | jq '.manifests[].annotations."org.opencontainers.image.ref.name"') = '"latest"' ] 212 run curl -X DELETE http://127.0.0.1:8080/v2/busybox/manifests/latest 213 [ "$status" -eq 0 ] 214 } 215 216 @test "push oras artifact - dedupe running" { 217 echo "{\"name\":\"foo\",\"value\":\"bar\"}" > config.json 218 echo "hello world" > artifact.txt 219 start=`date +%s` 220 run oras push --plain-http 127.0.0.1:8080/hello-artifact:v2 \ 221 --config config.json:application/vnd.acme.rocket.config.v1+json artifact.txt:text/plain -d -v 222 [ "$status" -eq 0 ] 223 end=`date +%s` 224 runtime=$((end-start)) 225 226 echo "push oras artifact exec time: $runtime sec" >&3 227 rm -f artifact.txt 228 rm -f config.json 229 } 230 231 @test "pull oras artifact - dedupe running" { 232 start=`date +%s` 233 run oras pull --plain-http 127.0.0.1:8080/hello-artifact:v2 -d -v 234 [ "$status" -eq 0 ] 235 end=`date +%s` 236 runtime=$((end-start)) 237 238 echo "pull oras artifact exec time: $runtime sec" >&3 239 grep -q "hello world" artifact.txt 240 rm -f artifact.txt 241 } 242 243 @test "attach oras artifacts - dedupe running" { 244 # attach signature 245 echo "{\"artifact\": \"\", \"signature\": \"pat hancock\"}" > ${BATS_FILE_TMPDIR}/signature.json 246 start=`date +%s` 247 run oras attach --plain-http 127.0.0.1:8080/alpine:1 --image-spec v1.1-image --artifact-type 'signature/example' ${BATS_FILE_TMPDIR}/signature.json:application/json 248 [ "$status" -eq 0 ] 249 end=`date +%s` 250 runtime=$((end-start)) 251 252 echo "attach signature exec time: $runtime sec" >&3 253 # attach sbom 254 echo "{\"version\": \"0.0.0.0\", \"artifact\": \"'127.0.0.1:8080/alpine:1'\", \"contents\": \"good\"}" > ${BATS_FILE_TMPDIR}/sbom.json 255 start=`date +%s` 256 run oras attach --plain-http 127.0.0.1:8080/alpine:1 --image-spec v1.1-image --artifact-type 'sbom/example' ${BATS_FILE_TMPDIR}/sbom.json:application/json 257 [ "$status" -eq 0 ] 258 end=`date +%s` 259 runtime=$((end-start)) 260 261 echo "attach sbom exec time: $runtime sec" >&3 262 } 263 264 @test "discover oras artifacts - dedupe running" { 265 start=`date +%s` 266 run oras discover --plain-http -o json 127.0.0.1:8080/alpine:1 267 [ "$status" -eq 0 ] 268 end=`date +%s` 269 runtime=$((end-start)) 270 271 echo "discover oras artifacts exec time: $runtime sec" >&3 272 [ $(echo "$output" | jq -r ".manifests | length") -eq 2 ] 273 } 274 275 @test "push helm chart - dedupe running" { 276 run helm package ${BATS_FILE_TMPDIR}/helm-charts/charts/zot -d ${BATS_FILE_TMPDIR} 277 [ "$status" -eq 0 ] 278 local chart_version=$(awk '/version/{printf $2}' ${BATS_FILE_TMPDIR}/helm-charts/charts/zot/Chart.yaml) 279 start=`date +%s` 280 run helm push ${BATS_FILE_TMPDIR}/zot-${chart_version}.tgz oci://localhost:8080/zot-chart 281 [ "$status" -eq 0 ] 282 end=`date +%s` 283 runtime=$((end-start)) 284 285 echo "helm push exec time: $runtime sec" >&3 286 } 287 288 @test "pull helm chart - dedupe running" { 289 local chart_version=$(awk '/version/{printf $2}' ${BATS_FILE_TMPDIR}/helm-charts/charts/zot/Chart.yaml) 290 start=`date +%s` 291 run helm pull oci://localhost:8080/zot-chart/zot --version ${chart_version} -d ${BATS_FILE_TMPDIR} 292 [ "$status" -eq 0 ] 293 end=`date +%s` 294 runtime=$((end-start)) 295 296 echo "helm pull exec time: $runtime sec" >&3 297 } 298 299 @test "push image with regclient - dedupe running" { 300 run regctl registry set localhost:8080 --tls disabled 301 [ "$status" -eq 0 ] 302 start=`date +%s` 303 run regctl image copy ocidir://${TEST_DATA_DIR}/alpine:1 localhost:8080/test-regclient 304 [ "$status" -eq 0 ] 305 end=`date +%s` 306 runtime=$((end-start)) 307 308 echo "regclient push exec time: $runtime" >&3 309 }