diff --git a/ci/uconv_reproduce/ci-uconv-reproduce.sh b/ci/uconv_reproduce/ci-uconv-reproduce.sh index 0ceb3258..abe67d4a 100644 --- a/ci/uconv_reproduce/ci-uconv-reproduce.sh +++ b/ci/uconv_reproduce/ci-uconv-reproduce.sh @@ -1,5 +1,7 @@ #!/bin/bash +apt install -y python3 + convertor="/opt/overlaybd/snapshotter/convertor" images=("centos:centos7.9.2009" "ubuntu:22.04" "redis:7.2.3" "wordpress:6.4.2" "nginx:1.25.3") repo="registry.hub.docker.com/overlaybd" @@ -29,7 +31,8 @@ do for file in ${files[@]} do fn="${file}.json" - diff ${tmp_dir}/${fn} ${ci_base}/${img}/${fn} + # diff ${tmp_dir}/${fn} ${ci_base}/${img}/${fn} + python3 compare_layers.py ${file} ${tmp_dir}/${fn} ${ci_base}/${img}/${fn} ret=$? if [[ ${ret} -eq 0 ]]; then echo "${prefix} ${img} ${file} consistent" diff --git a/ci/uconv_reproduce/compare_layers.py b/ci/uconv_reproduce/compare_layers.py new file mode 100644 index 00000000..29c04388 --- /dev/null +++ b/ci/uconv_reproduce/compare_layers.py @@ -0,0 +1,67 @@ +import os, sys +import json + + +def compare_manifest(fa_conf, fb_conf): + fa_layers = fa_conf["layers"] + fb_layers = fb_conf["layers"] + if len(fa_layers) != len(fb_layers): + print("layer size diff: %d %d" % (len(fa_layers), len(fb_layers))) + return -1 + ret = 0 + for idx in range(0, len(fa_layers)): + has_diff = 0 + if fa_layers[idx]["digest"] != fb_layers[idx]["digest"]: + print("layer %d digest diff: %s %s" % (idx, fa_layers[idx]["digest"], fb_layers[idx]["digest"])) + has_diff = -1 + if fa_layers[idx]["size"] != fb_layers[idx]["size"]: + print("layer %d size diff: %s %s" % (idx, fa_layers[idx]["size"], fb_layers[idx]["size"])) + has_diff = -1 + if has_diff == 0: + print("layer %d consistent" % idx) + else: + ret = -1 + return ret + + +def compare_config(fa_conf, fb_conf): + fa_diffs = fa_conf["rootfs"]["diff_ids"] + fb_diffs = fb_conf["rootfs"]["diff_ids"] + if len(fa_diffs) != len(fb_diffs): + print("diff_ids size diff: %d %d" % (len(fa_diffs), len(fb_diffs))) + return -1 + ret = 0 + for idx in range(0, len(fa_diffs)): + if fa_diffs[idx] != fb_diffs[idx]: + print("diff_ids %d diff: %s %s" % (idx, fa_diffs[idx], fb_diffs[idx])) + ret = -1 + else: + print("diff_ids %d consistent" % idx) + return ret + + +def main(): + if len(sys.argv) < 4: + print("Usage: python3 %s " % os.path.basename(sys.argv[0])) + ftype = sys.argv[1] + fa = sys.argv[2] + fb = sys.argv[3] + if not os.path.exists(fa): + print("file %s not exist" % fa) + return -1 + if not os.path.exists(fb): + print("file %s not exist" % fb) + return -1 + fa_conf = json.load(open(fa, 'r')) + fb_conf = json.load(open(fb, 'r')) + if ftype == "manifest": + sys.exit(compare_manifest(fa_conf, fb_conf)) + elif ftype == "config": + sys.exit(compare_config(fa_conf, fb_conf)) + else: + print("unknown type %s" % ftype) + sys.exit(-1) + + +if __name__ == '__main__': + main() diff --git a/cmd/ctr/main.go b/cmd/ctr/main.go index 6071c2d1..1735b6df 100644 --- a/cmd/ctr/main.go +++ b/cmd/ctr/main.go @@ -18,15 +18,16 @@ package main import ( "fmt" + "math/rand" "os" + "time" "github.com/containerd/containerd/cmd/ctr/app" - "github.com/containerd/containerd/pkg/seed" "github.com/urfave/cli" ) func init() { - seed.WithTimeAndRand() + rand.Seed(time.Now().UnixNano()) } var pluginCmds = []cli.Command{