Skip to content

Commit f4c734c

Browse files
authored
Merge pull request #260 from WaberZhuang/main
[Enhance] Add CI for turbo and enhance other tests
2 parents 0b0fd15 + eef6936 commit f4c734c

22 files changed

+253
-38
lines changed

.github/workflows/ci-basic.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,17 @@ on:
55
image-tag:
66
required: true
77
type: string
8+
github-repository:
9+
required: true
10+
type: string
811

912
jobs:
1013
run-ci-basic:
1114
name: Run CI | Basic
1215
runs-on: ubuntu-22.04
1316
timeout-minutes: 10
1417
container:
15-
image: ghcr.io/${{ github.repository }}/overlaybd-ci-images:${{ inputs.image-tag }}
18+
image: ghcr.io/${{ inputs.github-repository }}/overlaybd-ci-images:${{ inputs.image-tag }}
1619
credentials:
1720
username: ${{ github.actor }}
1821
password: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/ci-build-image.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ on:
88
image-tag:
99
required: true
1010
type: string
11+
github-repository:
12+
required: true
13+
type: string
1114

1215
env:
1316
GO_VERSION: "1.19"
@@ -51,7 +54,7 @@ jobs:
5154
- name: Build and Push
5255
uses: docker/build-push-action@v4
5356
with:
54-
tags: ghcr.io/${{ github.repository }}/overlaybd-ci-images:${{ inputs.image-tag }}
57+
tags: ghcr.io/${{ inputs.github-repository }}/overlaybd-ci-images:${{ inputs.image-tag }}
5558
push: true
5659
context: .
5760
platforms: linux/amd64

.github/workflows/ci-e2e.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ on:
88
image-tag:
99
required: true
1010
type: string
11+
github-repository:
12+
required: true
13+
type: string
1114

1215
concurrency:
1316
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
@@ -19,13 +22,15 @@ jobs:
1922
with:
2023
commit-hash: ${{ inputs.commit-hash }}
2124
image-tag: ${{ inputs.image-tag }}
25+
github-repository: ${{ inputs.github-repository }}
2226
secrets: inherit
2327

2428
run-ci-basic:
2529
needs: build-test-image-amd64
2630
uses: ./.github/workflows/ci-basic.yml
2731
with:
2832
image-tag: ${{ inputs.image-tag }}
33+
github-repository: ${{ inputs.github-repository }}
2934
secrets: inherit
3035

3136
run-ci-userspace-convertor:
@@ -34,4 +39,5 @@ jobs:
3439
with:
3540
commit-hash: ${{ inputs.commit-hash }}
3641
image-tag: ${{ inputs.image-tag }}
42+
github-repository: ${{ inputs.github-repository }}
3743
secrets: inherit

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

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,17 @@ on:
88
image-tag:
99
required: true
1010
type: string
11+
github-repository:
12+
required: true
13+
type: string
1114

1215
jobs:
1316
run-ci-userspace-convertor:
1417
name: Run CI | Userspace Convertor
1518
runs-on: ubuntu-22.04
1619
timeout-minutes: 10
1720
container:
18-
image: ghcr.io/${{ github.repository }}/overlaybd-ci-images:${{ inputs.image-tag }}
21+
image: ghcr.io/${{ inputs.github-repository }}/overlaybd-ci-images:${{ inputs.image-tag }}
1922
credentials:
2023
username: ${{ github.actor }}
2124
password: ${{ secrets.GITHUB_TOKEN }}
@@ -25,6 +28,8 @@ jobs:
2528
- /sys/kernel/config:/sys/kernel/config
2629
- /mnt:/var/lib/containerd
2730
options: --privileged
31+
env:
32+
DOCKER_HOST: "unix:///app/dockerd/docker.sock"
2833

2934
steps:
3035
- name: Checkout
@@ -40,8 +45,27 @@ jobs:
4045
bash start_services.sh
4146
sleep 5s
4247
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
58+
4359
- name: CI - uconv reproduce
4460
working-directory: ci/uconv_reproduce
4561
shell: bash
4662
run: |
4763
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

.github/workflows/ci.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,23 @@ jobs:
4545
run: |
4646
sudo GO_TESTFLAGS=-v make test
4747
48+
lowercase-repo:
49+
name: Lowercase Repo
50+
runs-on: ubuntu-22.04
51+
timeout-minutes: 10
52+
outputs:
53+
repository: ${{ steps.lowercase_repository.outputs.repository }}
54+
steps:
55+
- id: lowercase_repository
56+
run: echo "repository=${GITHUB_REPOSITORY,,}" >> "$GITHUB_OUTPUT"
57+
4858
e2e-test:
59+
needs: lowercase-repo
4960
name: E2E Test
5061
if: ${{ contains(github.event.pull_request.labels.*.name, 'ok-to-test') || github.event_name == 'push' }}
5162
uses: ./.github/workflows/ci-e2e.yml
5263
with:
5364
commit-hash: ${{ github.event.pull_request.head.sha || github.sha }}
5465
image-tag: ${{ github.event.pull_request.number || 'default' }}
66+
github-repository: ${{ needs.lowercase-repo.outputs.repository }}
5567
secrets: inherit

ci/build_image/Dockerfile

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,15 @@ SHELL ["/bin/bash", "-c"]
4141
WORKDIR /app
4242
COPY --from=builder /tmp/overlaybd-snapshotter_${RELEASE_VERSION}_amd64.deb .
4343
COPY ./ci/build_image/start_services.sh .
44-
RUN \
45-
apt update && apt install -y containerd libnl-3-200 libnl-genl-3-200 libcurl4-openssl-dev libaio-dev wget less kmod && \
44+
45+
RUN apt-get update && apt-get install -y apt-transport-https ca-certificates curl gnupg lsb-release software-properties-common && \
46+
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg && \
47+
echo \
48+
"deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu \
49+
$(lsb_release -cs) stable" | tee /etc/apt/sources.list.d/docker.list > /dev/null && \
50+
apt-get update && apt-get install -y docker-ce docker-ce-cli containerd.io && \
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/* && \
4653
wget https://github.com/containerd/overlaybd/releases/download/v${OBD_VERSION}/overlaybd-${OBD_VERSION}-0ubuntu1.22.04.x86_64.deb && \
4754
dpkg -i overlaybd-${OBD_VERSION}-0ubuntu1.22.04.x86_64.deb && \
4855
dpkg -i overlaybd-snapshotter_${RELEASE_VERSION}_amd64.deb && \

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}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"created":"2021-09-15T18:20:23.99863383Z","architecture":"amd64","os":"linux","config":{"Env":["PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"],"Cmd":["/bin/bash"],"Labels":{"org.label-schema.build-date":"20201113","org.label-schema.license":"GPLv2","org.label-schema.name":"CentOS Base Image","org.label-schema.schema-version":"1.0","org.label-schema.vendor":"CentOS","org.opencontainers.image.created":"2020-11-13 00:00:00+00:00","org.opencontainers.image.licenses":"GPL-2.0-only","org.opencontainers.image.title":"CentOS Base Image","org.opencontainers.image.vendor":"CentOS"}},"rootfs":{"type":"layers","diff_ids":["sha256:a5cdf182bbffc6992b556633bbb275b559056b6e953133772a80fa261886c07b"]},"history":[{"created":"2021-09-15T18:20:23.417639551Z","created_by":"/bin/sh -c #(nop) ADD file:b3ebbe8bd304723d43b7b44a6d990cd657b63d93d6a2a9293983a30bfc1dfa53 in / "},{"created":"2021-09-15T18:20:23.819893035Z","created_by":"/bin/sh -c #(nop) LABEL org.label-schema.schema-version=1.0 org.label-schema.name=CentOS Base Image org.label-schema.vendor=CentOS org.label-schema.license=GPLv2 org.label-schema.build-date=20201113 org.opencontainers.image.title=CentOS Base Image org.opencontainers.image.vendor=CentOS org.opencontainers.image.licenses=GPL-2.0-only org.opencontainers.image.created=2020-11-13 00:00:00+00:00","empty_layer":true},{"created":"2021-09-15T18:20:23.99863383Z","created_by":"/bin/sh -c #(nop) CMD [\"/bin/bash\"]","empty_layer":true}]}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"schemaVersion":2,"mediaType":"application/vnd.docker.distribution.manifest.v2+json","config":{"mediaType":"application/vnd.docker.container.image.v1+json","digest":"sha256:bdeebc045cc88055079dd5ab899cf594614b2757d5b572ec7acc6f4a24031fb1","size":1476},"layers":[{"mediaType":"application/vnd.docker.image.rootfs.diff.tar.gzip","digest":"sha256:e91a425b0b5001fa96ae2909db392034ee9eccfdf9347410a1343719db83054e","size":2717102,"annotations":{"containerd.io/snapshot/overlaybd/blob-digest":"sha256:e91a425b0b5001fa96ae2909db392034ee9eccfdf9347410a1343719db83054e","containerd.io/snapshot/overlaybd/blob-size":"2717102","containerd.io/snapshot/overlaybd/turbo-oci/target-digest":"sha256:2d473b07cdd5f0912cd6f1a703352c82b512407db6b05b43f2553732b55df3bc","containerd.io/snapshot/overlaybd/turbo-oci/target-media-type":"application/vnd.docker.image.rootfs.diff.tar.gzip","containerd.io/snapshot/overlaybd/version":"0.1.0-turbo.ociv1"}}]}
Lines changed: 39 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,70 @@
11
#!/bin/bash
22

3-
apt install -y python3
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")
7-
repo="registry.hub.docker.com/overlaybd"
7+
registry="localhost:5000"
88
ci_base=$(pwd)
99

1010
result=0
1111

12-
for image in ${images[@]}
12+
for image in "${images[@]}"
1313
do
1414
img=${image%%":"*}
1515
tag=${image##*":"}
16-
echo ${img} ${tag}
16+
echo "${img} ${tag}"
1717

18-
o_tag="${tag}_obd"
19-
tmp_dir="${ci_base}/tmp_conv_${image/:/_}"
18+
workspace="${ci_base}/workspace_${image/:/_}"
2019

21-
rm -rf ${tmp_dir}
22-
mkdir -p ${tmp_dir}
20+
rm -rf "${workspace}"
21+
mkdir -p "${workspace}"
2322

24-
${convertor} -r ${repo}/${img} \
25-
--reserve --no-upload --dump-manifest \
26-
-i ${tag} -o ${o_tag} -d ${tmp_dir} &>${tmp_dir}/convert.out
23+
tag_obd="${tag}_overlaybd"
24+
tag_turbo="${tag}_turbo"
25+
manifest_obd="${workspace}/manifest.json"
26+
manifest_turbo="${workspace}/manifest-turbo.json"
27+
config_obd="${workspace}/config.json"
28+
config_turbo="${workspace}/config-turbo.json"
29+
output_obd="${workspace}/convert.overlaybd.out"
30+
output_turbo="${workspace}/convert.turbo.out"
31+
32+
${convertor} -r "${registry}/${img}" -i "${tag}" --overlaybd "${tag_obd}" -d "${workspace}/overlaybd_tmp_conv" &> "${output_obd}"
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
34+
configDigest=$(jq '.config.digest' "${manifest_obd}")
35+
configDigest=${configDigest//\"/}
36+
curl -o "${config_obd}" "https://${registry}/v2/${img}/blobs/${configDigest}" &> /dev/null
37+
38+
${convertor} -r "${registry}/${img}" -i "${tag}" --turboOCI "${tag_turbo}" -d "${workspace}/turbo_tmp_conv" &> "${output_turbo}"
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
40+
configDigest=$(jq '.config.digest' "${manifest_turbo}")
41+
configDigest=${configDigest//\"/}
42+
curl -o "${config_turbo}" "https://${registry}/v2/${img}/blobs/${configDigest}" &> /dev/null
2743

2844
prefix=$(date +%Y%m%d%H%M%S)
29-
files=("manifest" "config")
45+
46+
mode=("manifest" "config" "manifest" "config")
47+
actual=("${manifest_obd}" "${config_obd}" "${manifest_turbo}" "${config_turbo}")
48+
expected=("${ci_base}/${img}/manifest.json" "${ci_base}/${img}/config.json" "${ci_base}/${img}/manifest-turbo.json" "${ci_base}/${img}/config-turbo.json")
49+
3050
conv_res=0
31-
for file in ${files[@]}
32-
do
33-
fn="${file}.json"
34-
# diff ${tmp_dir}/${fn} ${ci_base}/${img}/${fn}
35-
python3 compare_layers.py ${file} ${tmp_dir}/${fn} ${ci_base}/${img}/${fn}
51+
n=${#mode[@]}
52+
for ((i=0; i<n; i++)); do
53+
python3 compare_layers.py ${mode[$i]} ${actual[$i]} ${expected[$i]}
3654
ret=$?
3755
if [[ ${ret} -eq 0 ]]; then
38-
echo "${prefix} ${img} ${file} consistent"
56+
echo "${prefix} ${img} ${expected[$i]} consistent"
3957
else
40-
echo "${prefix} ${img} ${file} diff"
58+
echo "${prefix} ${img} ${expected[$i]} diff"
4159
conv_res=1
4260
fi
4361
done
4462

4563
if [[ ${conv_res} -eq 1 ]]; then
46-
cat ${tmp_dir}/convert.out | sed 's/\\n/\n/g'
64+
sed 's/\\n/\n/g' < "${output_obd}"
65+
sed 's/\\n/\n/g' < "${output_turbo}"
4766
result=1
4867
fi
49-
rm -rf ${tmp_dir}
5068
done
5169

5270
exit ${result}

0 commit comments

Comments
 (0)