Skip to content

Commit eef6936

Browse files
committed
ci: add userspace convertor E2E
Signed-off-by: Bowei Zhuang <zhuangbowei.zbw@alibaba-inc.com>
1 parent a03d841 commit eef6936

File tree

9 files changed

+173
-31
lines changed

9 files changed

+173
-31
lines changed

.github/workflows/ci-userspace-convertor.yml

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ jobs:
2828
- /sys/kernel/config:/sys/kernel/config
2929
- /mnt:/var/lib/containerd
3030
options: --privileged
31+
env:
32+
DOCKER_HOST: "unix:///app/dockerd/docker.sock"
3133

3234
steps:
3335
- name: Checkout
@@ -41,12 +43,29 @@ jobs:
4143
shell: bash
4244
run: |
4345
bash start_services.sh
44-
sleep 3s
45-
docker run -d -p 5000:5000 --restart always --name registry registry:2
46-
sleep 3s
46+
sleep 5s
47+
48+
- name: Prepare Local Registry
49+
working-directory: ci/scripts
50+
shell: bash
51+
run: |
52+
bash new_registry.sh
53+
bash prepare_image.sh registry.hub.docker.com/overlaybd/centos:centos7.9.2009 localhost:5000/centos:centos7.9.2009 && \
54+
bash prepare_image.sh registry.hub.docker.com/overlaybd/ubuntu:22.04 localhost:5000/ubuntu:22.04 && \
55+
bash prepare_image.sh registry.hub.docker.com/overlaybd/redis:7.2.3 localhost:5000/redis:7.2.3 && \
56+
bash prepare_image.sh registry.hub.docker.com/overlaybd/wordpress:6.4.2 localhost:5000/wordpress:6.4.2 && \
57+
bash prepare_image.sh registry.hub.docker.com/overlaybd/nginx:1.25.3 localhost:5000/nginx:1.25.3
4758
4859
- name: CI - uconv reproduce
4960
working-directory: ci/uconv_reproduce
5061
shell: bash
5162
run: |
5263
bash ci-uconv-reproduce.sh
64+
65+
- name: CI - uconv E2E
66+
working-directory: ci/scripts
67+
shell: bash
68+
run: |
69+
/opt/overlaybd/snapshotter/convertor -r localhost:5000/redis -i 7.2.3 --overlaybd 7.2.3_overlaybd --turboOCI 7.2.3_turbo
70+
bash run_container.sh localhost:5000/redis:7.2.3_overlaybd
71+
bash run_container.sh localhost:5000/redis:7.2.3_turbo

ci/build_image/Dockerfile

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,8 @@ RUN apt-get update && apt-get install -y apt-transport-https ca-certificates cur
4848
"deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu \
4949
$(lsb_release -cs) stable" | tee /etc/apt/sources.list.d/docker.list > /dev/null && \
5050
apt-get update && apt-get install -y docker-ce docker-ce-cli containerd.io && \
51-
apt-get clean && rm -rf /var/lib/apt/lists/*
52-
53-
RUN \
54-
apt update && apt install -y libnl-3-200 libnl-genl-3-200 libcurl4-openssl-dev libaio-dev wget less kmod && \
51+
apt-get install -y libnl-3-200 libnl-genl-3-200 libcurl4-openssl-dev libaio-dev wget less kmod && \
52+
apt-get clean && rm -rf /var/lib/apt/lists/* && \
5553
wget https://github.com/containerd/overlaybd/releases/download/v${OBD_VERSION}/overlaybd-${OBD_VERSION}-0ubuntu1.22.04.x86_64.deb && \
5654
dpkg -i overlaybd-${OBD_VERSION}-0ubuntu1.22.04.x86_64.deb && \
5755
dpkg -i overlaybd-snapshotter_${RELEASE_VERSION}_amd64.deb && \

ci/build_image/start_services.sh

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,3 @@ fi
2020
/opt/overlaybd/snapshotter/overlaybd-snapshotter &>/var/log/overlaybd-snapshotter.log &
2121

2222
/sbin/modprobe overlay && /usr/bin/containerd &>/var/log/containerd.log &
23-
24-
dockerd &>/var/log/dockerd.log &

ci/scripts/new_registry.sh

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
#!/bin/bash
2+
#
3+
# run a HTTPS registry
4+
5+
set -x
6+
7+
mkdir -p /app/dockerd/
8+
echo '{ "hosts": ["unix:///app/dockerd/docker.sock"] }' > /etc/docker/daemon.json
9+
dockerd &>/var/log/dockerd.log &
10+
11+
sleep 3
12+
13+
rm -rf /etc/registry/
14+
mkdir -p /etc/registry/certs/
15+
mkdir -p /etc/registry/config/
16+
17+
# generate server certifications
18+
cat << EOF > /etc/registry/openssl.cnf
19+
[req]
20+
distinguished_name = req_distinguished_name
21+
x509_extensions = v3_req
22+
prompt = no
23+
24+
[req_distinguished_name]
25+
C = CN
26+
ST = Beijing
27+
L = Beijing City
28+
O = Alibaba
29+
CN = localhost
30+
31+
[v3_req]
32+
basicConstraints = CA:FALSE
33+
keyUsage = nonRepudiation, digitalSignature, keyEncipherment
34+
subjectAltName = @alt_names
35+
36+
[alt_names]
37+
DNS.1 = localhost
38+
IP.1 = 127.0.0.1
39+
EOF
40+
41+
openssl req -new -x509 -newkey rsa:2048 -sha256 -nodes -config /etc/registry/openssl.cnf \
42+
-days 365 -out /etc/registry/certs/server.crt -keyout /etc/registry/certs/server.key
43+
44+
ls /etc/registry/certs/
45+
cp /etc/registry/certs/server.crt /usr/local/share/ca-certificates/registry.crt
46+
update-ca-certificates
47+
48+
# start registry
49+
cat << EOF > /etc/registry/config/config.yml
50+
version: 0.1
51+
log:
52+
fields:
53+
service: registry
54+
storage:
55+
cache:
56+
blobdescriptor: inmemory
57+
filesystem:
58+
rootdirectory: /var/lib/registry
59+
http:
60+
addr: :5000
61+
headers:
62+
X-Content-Type-Options: [nosniff]
63+
tls:
64+
certificate: /certs/server.crt
65+
key: /certs/server.key
66+
health:
67+
storagedriver:
68+
enabled: true
69+
interval: 10s
70+
threshold: 3
71+
EOF
72+
73+
docker run -d --restart=always --name registry -p 5000:5000 \
74+
-v /etc/registry/certs:/certs \
75+
-v /etc/registry/config:/etc/docker/registry/ \
76+
registry:2
77+
78+
sleep 5s
79+
80+
docker ps -a
81+
apt-get update && apt-get install -y lsof
82+
lsof -i :5000
83+
curl http://localhost:5000/v2/_catalog
84+
lsof -i :5000
85+
curl https://localhost:5000/v2/_catalog

ci/scripts/prepare_image.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/bash
2+
3+
from=${1:?}
4+
to=${2:?}
5+
6+
set -x
7+
8+
ctr i pull "${from}"
9+
ctr i tag "${from}" "${to}"
10+
ctr i push "${to}"
11+
ctr i rm "${from}" "${to}"

ci/scripts/run_container.sh

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/bin/bash
2+
#
3+
# rpull and run on-demand
4+
5+
image=$1
6+
container_name=${2:-test}
7+
8+
exit_code=0
9+
10+
/opt/overlaybd/snapshotter/ctr rpull "${image}"
11+
if ! ctr run -d --net-host --snapshotter=overlaybd "${image}" "${container_name}"; then
12+
exit_code=1
13+
fi
14+
if ! ctr t ls | grep "${container_name}"; then
15+
exit_code=1
16+
fi
17+
ctr t kill -s 9 "${container_name}" && sleep 5s && ctr t ls
18+
ctr c rm "${container_name}" && ctr c ls
19+
ctr i rm "${image}"
20+
21+
if [[ ${exit_code} -ne 0 ]]; then
22+
cat /var/log/overlaybd.log
23+
fi
24+
25+
exit ${exit_code}

ci/uconv_reproduce/ci-uconv-reproduce.sh

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/bash
22

3-
apt install -y python3 jq
3+
apt update && apt install -y python3 jq
44

55
convertor="/opt/overlaybd/snapshotter/convertor"
66
images=("centos:centos7.9.2009" "ubuntu:22.04" "redis:7.2.3" "wordpress:6.4.2" "nginx:1.25.3")
@@ -11,11 +11,6 @@ result=0
1111

1212
for image in "${images[@]}"
1313
do
14-
from_img="registry.hub.docker.com/overlaybd/${image}"
15-
ctr i pull "${from_img}" &> /dev/null
16-
ctr i tag "${from_img}" "${registry}/${image}" &> /dev/null
17-
ctr i push "${registry}/${image}" &> /dev/null
18-
1914
img=${image%%":"*}
2015
tag=${image##*":"}
2116
echo "${img} ${tag}"
@@ -35,16 +30,16 @@ do
3530
output_turbo="${workspace}/convert.turbo.out"
3631

3732
${convertor} -r "${registry}/${img}" -i "${tag}" --overlaybd "${tag_obd}" -d "${workspace}/overlaybd_tmp_conv" &> "${output_obd}"
38-
curl -H "Accept: application/vnd.docker.distribution.manifest.v2+json,application/vnd.oci.image.manifest.v1+json" -o "${manifest_obd}" "${registry}/v2/${img}/manifests/${tag_obd}" &> /dev/null
33+
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/null
3934
configDigest=$(jq '.config.digest' "${manifest_obd}")
4035
configDigest=${configDigest//\"/}
41-
curl -o "${config_obd}" "${registry}/v2/${img}/blobs/${configDigest}" &> /dev/null
36+
curl -o "${config_obd}" "https://${registry}/v2/${img}/blobs/${configDigest}" &> /dev/null
4237

4338
${convertor} -r "${registry}/${img}" -i "${tag}" --turboOCI "${tag_turbo}" -d "${workspace}/turbo_tmp_conv" &> "${output_turbo}"
44-
curl -H "Accept: application/vnd.docker.distribution.manifest.v2+json,application/vnd.oci.image.manifest.v1+json" -o "${manifest_turbo}" "${registry}/v2/${img}/manifests/${tag_turbo}" &> /dev/null
39+
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/null
4540
configDigest=$(jq '.config.digest' "${manifest_turbo}")
4641
configDigest=${configDigest//\"/}
47-
curl -o "${config_turbo}" "${registry}/v2/${img}/blobs/${configDigest}" &> /dev/null
42+
curl -o "${config_turbo}" "https://${registry}/v2/${img}/blobs/${configDigest}" &> /dev/null
4843

4944
prefix=$(date +%Y%m%d%H%M%S)
5045

ci/uconv_reproduce/compare_layers.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,10 @@ def main():
4848
fb = sys.argv[3]
4949
if not os.path.exists(fa):
5050
print("file %s not exist" % fa)
51-
return -1
51+
sys.exit(-1)
5252
if not os.path.exists(fb):
5353
print("file %s not exist" % fb)
54-
return -1
54+
sys.exit(-1)
5555
fa_conf = json.load(open(fa, 'r'))
5656
fb_conf = json.load(open(fb, 'r'))
5757
if ftype == "manifest":

cmd/convertor/builder/builder.go

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -83,17 +83,28 @@ func NewOverlayBDBuilder(ctx context.Context, opt BuilderOptions) (Builder, erro
8383
TLSClientConfig: tlsConfig,
8484
ExpectContinueTimeout: 5 * time.Second,
8585
}
86+
client := &http.Client{Transport: transport}
8687
resolver := docker.NewResolver(docker.ResolverOptions{
87-
Credentials: func(s string) (string, string, error) {
88-
if i := strings.IndexByte(opt.Auth, ':'); i > 0 {
89-
return opt.Auth[0:i], opt.Auth[i+1:], nil
90-
}
91-
return "", "", nil
92-
},
93-
PlainHTTP: opt.PlainHTTP,
94-
Client: &http.Client{
95-
Transport: transport,
96-
},
88+
Hosts: docker.ConfigureDefaultRegistries(
89+
docker.WithAuthorizer(docker.NewDockerAuthorizer(
90+
docker.WithAuthClient(client),
91+
docker.WithAuthHeader(make(http.Header)),
92+
docker.WithAuthCreds(func(s string) (string, string, error) {
93+
if i := strings.IndexByte(opt.Auth, ':'); i > 0 {
94+
return opt.Auth[0:i], opt.Auth[i+1:], nil
95+
}
96+
return "", "", nil
97+
}),
98+
)),
99+
docker.WithClient(client),
100+
docker.WithPlainHTTP(func(s string) (bool, error) {
101+
if opt.PlainHTTP {
102+
return docker.MatchAllHosts(s)
103+
} else {
104+
return false, nil
105+
}
106+
}),
107+
),
97108
})
98109
engineBase, err := getBuilderEngineBase(ctx, resolver, opt.Ref, opt.TargetRef)
99110
if err != nil {

0 commit comments

Comments
 (0)