zotregistry.io/zot@v1.4.4-0.20231124084042-02a8ed785457/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-dev", 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 wait_zot_reachable 8080 124 # deduping will now run in background (task scheduler) while we push images, shouldn't interfere 125 } 126 127 @test "push image - dedupe running" { 128 start=`date +%s` 129 run skopeo --insecure-policy copy --dest-tls-verify=false \ 130 oci:${TEST_DATA_DIR}/alpine:1 \ 131 docker://127.0.0.1:8080/dedupe/alpine:1 132 [ "$status" -eq 0 ] 133 end=`date +%s` 134 135 runtime=$((end-start)) 136 echo "push image exec time: $runtime sec" >&3 137 } 138 139 @test "pull image - dedupe running" { 140 local oci_data_dir=${BATS_FILE_TMPDIR}/oci 141 142 mkdir -p ${oci_data_dir}/dedupe/ 143 144 start=`date +%s` 145 run skopeo --insecure-policy copy --src-tls-verify=false \ 146 docker://127.0.0.1:8080/dedupe/alpine:1 \ 147 oci:${oci_data_dir}/dedupe/alpine:1 148 [ "$status" -eq 0 ] 149 end=`date +%s` 150 runtime=$((end-start)) 151 152 echo "pull image exec time: $runtime sec" >&3 153 } 154 155 @test "pull deduped image - dedupe running" { 156 local oci_data_dir=${BATS_FILE_TMPDIR}/oci 157 158 mkdir -p ${oci_data_dir}/dedupe/ 159 160 start=`date +%s` 161 run skopeo --insecure-policy copy --src-tls-verify=false \ 162 docker://127.0.0.1:8080/alpine2:1 \ 163 oci:${oci_data_dir}/dedupe/alpine2:1 164 [ "$status" -eq 0 ] 165 end=`date +%s` 166 runtime=$((end-start)) 167 168 echo "pull image exec time: $runtime sec" >&3 169 } 170 171 @test "push image index - dedupe running" { 172 # --multi-arch below pushes an image index (containing many images) instead 173 # of an image manifest (single image) 174 start=`date +%s` 175 run skopeo --insecure-policy copy --format=oci --dest-tls-verify=false --multi-arch=all \ 176 docker://public.ecr.aws/docker/library/busybox:latest \ 177 docker://127.0.0.1:8080/busybox:latest 178 [ "$status" -eq 0 ] 179 end=`date +%s` 180 runtime=$((end-start)) 181 182 echo "push image index exec time: $runtime sec" >&3 183 run curl http://127.0.0.1:8080/v2/busybox/tags/list 184 [ "$status" -eq 0 ] 185 [ $(echo "${lines[-1]}" | jq '.tags[]') = '"latest"' ] 186 } 187 188 @test "pull image index - dedupe running" { 189 local oci_data_dir=${BATS_FILE_TMPDIR}/oci 190 start=`date +%s` 191 run skopeo --insecure-policy copy --src-tls-verify=false --multi-arch=all \ 192 docker://127.0.0.1:8080/busybox:latest \ 193 oci:${oci_data_dir}/busybox:latest 194 [ "$status" -eq 0 ] 195 end=`date +%s` 196 runtime=$((end-start)) 197 198 echo "pull image index exec time: $runtime sec" >&3 199 run cat ${BATS_FILE_TMPDIR}/oci/busybox/index.json 200 [ "$status" -eq 0 ] 201 [ $(echo "${lines[-1]}" | jq '.manifests[].annotations."org.opencontainers.image.ref.name"') = '"latest"' ] 202 run skopeo --insecure-policy --override-arch=arm64 --override-os=linux copy --src-tls-verify=false --multi-arch=all \ 203 docker://127.0.0.1:8080/busybox:latest \ 204 oci:${oci_data_dir}/busybox:latest 205 [ "$status" -eq 0 ] 206 run cat ${BATS_FILE_TMPDIR}/oci/busybox/index.json 207 [ "$status" -eq 0 ] 208 [ $(echo "${lines[-1]}" | jq '.manifests[].annotations."org.opencontainers.image.ref.name"') = '"latest"' ] 209 run curl -X DELETE http://127.0.0.1:8080/v2/busybox/manifests/latest 210 [ "$status" -eq 0 ] 211 } 212 213 @test "push oras artifact - dedupe running" { 214 echo "{\"name\":\"foo\",\"value\":\"bar\"}" > config.json 215 echo "hello world" > artifact.txt 216 start=`date +%s` 217 run oras push --plain-http 127.0.0.1:8080/hello-artifact:v2 \ 218 --config config.json:application/vnd.acme.rocket.config.v1+json artifact.txt:text/plain -d -v 219 [ "$status" -eq 0 ] 220 end=`date +%s` 221 runtime=$((end-start)) 222 223 echo "push oras artifact exec time: $runtime sec" >&3 224 rm -f artifact.txt 225 rm -f config.json 226 } 227 228 @test "pull oras artifact - dedupe running" { 229 start=`date +%s` 230 run oras pull --plain-http 127.0.0.1:8080/hello-artifact:v2 -d -v 231 [ "$status" -eq 0 ] 232 end=`date +%s` 233 runtime=$((end-start)) 234 235 echo "pull oras artifact exec time: $runtime sec" >&3 236 grep -q "hello world" artifact.txt 237 rm -f artifact.txt 238 } 239 240 @test "attach oras artifacts - dedupe running" { 241 # attach signature 242 echo "{\"artifact\": \"\", \"signature\": \"pat hancock\"}" > ${BATS_FILE_TMPDIR}/signature.json 243 start=`date +%s` 244 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 245 [ "$status" -eq 0 ] 246 end=`date +%s` 247 runtime=$((end-start)) 248 249 echo "attach signature exec time: $runtime sec" >&3 250 # attach sbom 251 echo "{\"version\": \"0.0.0.0\", \"artifact\": \"'127.0.0.1:8080/alpine:1'\", \"contents\": \"good\"}" > ${BATS_FILE_TMPDIR}/sbom.json 252 start=`date +%s` 253 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 254 [ "$status" -eq 0 ] 255 end=`date +%s` 256 runtime=$((end-start)) 257 258 echo "attach sbom exec time: $runtime sec" >&3 259 } 260 261 @test "discover oras artifacts - dedupe running" { 262 start=`date +%s` 263 run oras discover --plain-http -o json 127.0.0.1:8080/alpine:1 264 [ "$status" -eq 0 ] 265 end=`date +%s` 266 runtime=$((end-start)) 267 268 echo "discover oras artifacts exec time: $runtime sec" >&3 269 [ $(echo "$output" | jq -r ".manifests | length") -eq 2 ] 270 } 271 272 @test "push helm chart - dedupe running" { 273 run helm package ${BATS_FILE_TMPDIR}/helm-charts/charts/zot -d ${BATS_FILE_TMPDIR} 274 [ "$status" -eq 0 ] 275 local chart_version=$(awk '/version/{printf $2}' ${BATS_FILE_TMPDIR}/helm-charts/charts/zot/Chart.yaml) 276 start=`date +%s` 277 run helm push ${BATS_FILE_TMPDIR}/zot-${chart_version}.tgz oci://localhost:8080/zot-chart 278 [ "$status" -eq 0 ] 279 end=`date +%s` 280 runtime=$((end-start)) 281 282 echo "helm push exec time: $runtime sec" >&3 283 } 284 285 @test "pull helm chart - dedupe running" { 286 local chart_version=$(awk '/version/{printf $2}' ${BATS_FILE_TMPDIR}/helm-charts/charts/zot/Chart.yaml) 287 start=`date +%s` 288 run helm pull oci://localhost:8080/zot-chart/zot --version ${chart_version} -d ${BATS_FILE_TMPDIR} 289 [ "$status" -eq 0 ] 290 end=`date +%s` 291 runtime=$((end-start)) 292 293 echo "helm pull exec time: $runtime sec" >&3 294 } 295 296 @test "push image with regclient - dedupe running" { 297 run regctl registry set localhost:8080 --tls disabled 298 [ "$status" -eq 0 ] 299 start=`date +%s` 300 run regctl image copy ocidir://${TEST_DATA_DIR}/alpine:1 localhost:8080/test-regclient 301 [ "$status" -eq 0 ] 302 end=`date +%s` 303 runtime=$((end-start)) 304 305 echo "regclient push exec time: $runtime" >&3 306 }