| 1 | #!/bin/bashscip-shell filesystem . . `/bin/bash`. |
| 2 | |
| 3 | aptscip-shell system . . apt. update && aptscip-shell system . . apt. install -y python3 jq |
| 4 | |
| 5 | convertor="/opt/overlaybd/snapshotter/convertorscip-shell filesystem . . `/opt/overlaybd/snapshotter/convertor`." |
| 6 | images=("centos:centos7.9.2009" "ubuntu:22.04" "redis:7.2.3" "wordpress:6.4.2" "nginx:1.25.3") |
| 7 | registry="localhost:5000" |
| 8 | ci_base=$(pwdscip-shell system . . pwd.) |
| 9 | |
| 10 | result=0 |
| 11 | |
| 12 | for image in "${images[@]}" |
| 13 | do |
| 14 | img=${image%%":"*} |
| 15 | tag=${image##*":"} |
| 16 | echoscip-shell system . . echo. "${img} ${tag}" |
| 17 | |
| 18 | workspace="${ci_base}/workspace_${image/:/_}" |
| 19 | |
| 20 | rmscip-shell system . . rm. -rf "${workspace}" |
| 21 | mkdirscip-shell system . . mkdir. -p "${workspace}" |
| 22 | |
| 23 | tag_obd="${tag}_overlaybd" |
| 24 | tag_turbo="${tag}_turbo" |
| 25 | tag_turbo_erofs="${tag}_turbo_erofs" |
| 26 | manifest_obd="${workspace}/manifest.json" |
| 27 | manifest_turbo="${workspace}/manifest-turbo.json" |
| 28 | manifest_turbo_erofs="${workspace}/manifest-turbo-erofs.json" |
| 29 | config_obd="${workspace}/config.json" |
| 30 | config_turbo="${workspace}/config-turbo.json" |
| 31 | config_turbo_erofs="${workspace}/config-turbo-erofs.json" |
| 32 | output_obd="${workspace}/convert.overlaybd.out" |
| 33 | output_turbo="${workspace}/convert.turbo.out" |
| 34 | output_turbo_erofs="${workspace}/convert.turbo.erofs.out" |
| 35 | |
| 36 | ${convertor} -r "${registry}/${img}" -i "${tag}" --overlaybd "${tag_obd}" -d "${workspace}/overlaybd_tmp_conv" &> "${output_obd}" |
| 37 | curlscip-shell system . . curl. -H "Accept: application/vnd.docker.distribution.manifest.v2+json,application/vnd.oci.image.manifest.v1+json" -o "${manifest_obd}" "https://${registry}/v2/${img}/manifests/${tag_obd}" &> /dev/nullscip-shell filesystem . . `/dev/null`. |
| 38 | configDigest=$(jqscip-shell system . . jq. '.config.digest' "${manifest_obd}") |
| 39 | configDigest=${configDigest//\"/} |
| 40 | curlscip-shell system . . curl. -o "${config_obd}" "https://${registry}/v2/${img}/blobs/${configDigest}" &> /dev/nullscip-shell filesystem . . `/dev/null`. |
| 41 | |
| 42 | ${convertor} -r "${registry}/${img}" -i "${tag}" --turboOCI "${tag_turbo}" -d "${workspace}/turbo_tmp_conv" &> "${output_turbo}" |
| 43 | curlscip-shell system . . curl. -H "Accept: application/vnd.docker.distribution.manifest.v2+json,application/vnd.oci.image.manifest.v1+json" -o "${manifest_turbo}" "https://${registry}/v2/${img}/manifests/${tag_turbo}" &> /dev/nullscip-shell filesystem . . `/dev/null`. |
| 44 | configDigest=$(jqscip-shell system . . jq. '.config.digest' "${manifest_turbo}") |
| 45 | configDigest=${configDigest//\"/} |
| 46 | curlscip-shell system . . curl. -o "${config_turbo}" "https://${registry}/v2/${img}/blobs/${configDigest}" &> /dev/nullscip-shell filesystem . . `/dev/null`. |
| 47 | |
| 48 | ${convertor} -r "${registry}/${img}" -i "${tag}" --turboOCI "${tag_turbo_erofs}" --fstype erofs -d "${workspace}/turbo_erofs_tmp_conv" &> "${output_turbo_erofs}" |
| 49 | curlscip-shell system . . curl. -s -H "Accept: application/vnd.docker.distribution.manifest.v2+json" "https://${registry}/v2/${img}/manifests/${tag_turbo_erofs}" |
| 50 | curlscip-shell system . . curl. -H "Accept: application/vnd.docker.distribution.manifest.v2+json,application/vnd.oci.image.manifest.v1+json" -o "${manifest_turbo_erofs}" "https://${registry}/v2/${img}/manifests/${tag_turbo_erofs}" &> /dev/nullscip-shell filesystem . . `/dev/null`. |
| 51 | configDigest=$(jqscip-shell system . . jq. '.config.digest' "${manifest_turbo_erofs}") |
| 52 | configDigest=${configDigest//\"/} |
| 53 | curlscip-shell system . . curl. -o "${config_turbo_erofs}" "https://${registry}/v2/${img}/blobs/${configDigest}" &> /dev/nullscip-shell filesystem . . `/dev/null`. |
| 54 | |
| 55 | prefix=$(datescip-shell system . . date. +%Y%m%d%H%M%S) |
| 56 | |
| 57 | mode=("manifest" "config" "manifest" "config" "manifest" "config") |
| 58 | actual=("${manifest_obd}" "${config_obd}" "${manifest_turbo}" "${config_turbo}" "${manifest_turbo_erofs}" "${config_turbo_erofs}") |
| 59 | expected=("${ci_base}/${img}/manifest.json" "${ci_base}/${img}/config.json" "${ci_base}/${img}/manifest-turbo.json" "${ci_base}/${img}/config-turbo.json" "${ci_base}/${img}/manifest-turbo-erofs.json" "${ci_base}/${img}/config-turbo-erofs.json") |
| 60 | |
| 61 | conv_res=0 |
| 62 | n=${#mode[@]} |
| 63 | for ((i=0; i<n; i++)); do |
| 64 | python3 compare_layers.py ${mode[$i]} ${actual[$i]} ${expected[$i]} |
| 65 | ret=$? |
| 66 | if [[ ${ret} -eq 0 ]]; then |
| 67 | echo "${prefix} ${img} ${expected[$i]} consistent" |
| 68 | else |
| 69 | echo "${prefix} ${img} ${expected[$i]} diff" |
| 70 | conv_res=1 |
| 71 | fi |
| 72 | done |
| 73 | |
| 74 | if [[ ${conv_res} -eq 1 ]]; then |
| 75 | sedscip-shell system . . sed. 's/\\n/\n/g' < "${output_obd}" |
| 76 | sedscip-shell system . . sed. 's/\\n/\n/g' < "${output_turbo}" |
| 77 | result=1 |
| 78 | fi |
| 79 | done |
| 80 | |
| 81 | exit ${result} |