Skip to content

Commit 63fd7c1

Browse files
alex1545k8s-ci-robot
authored andcommitted
container_repro_test rule to test for container reproducibility (#955)
* container_repro_test rule to test for container reproducibility * buildifier and disable tests on buildkite * test * test * buildifier * address some comments * test * test with buildkite * enable testing toolchain_container targets * test without remote cache * address comments * buildifier * test * test * address comments and use migrated base_image_docker rules * fix test script * address comments
1 parent 00a517f commit 63fd7c1

File tree

10 files changed

+416
-3
lines changed

10 files changed

+416
-3
lines changed

.bazelci/presubmit.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ platforms:
6666
build_targets:
6767
- "--"
6868
- "..."
69+
- "-//tests/contrib:derivative_with_volume_repro_test"
70+
- "-//tests/contrib:set_cmd_repro_test"
6971
build_flags:
7072
- "--extra_toolchains=@bazel_toolchains//configs/ubuntu16_04_clang/latest:toolchain_docker"
7173
- "--extra_execution_platforms=@bazel_toolchains//configs/ubuntu16_04_clang/latest:platform_docker"
@@ -81,6 +83,8 @@ platforms:
8183
- "--"
8284
- "//:structure_test_at_workspace_root"
8385
- "//tests/..."
86+
- "-//tests/contrib:derivative_with_volume_repro_test"
87+
- "-//tests/contrib:set_cmd_repro_test"
8488
- "-//tests/contrib:test_compare_ids_test_diff_ids_fails"
8589
- "-//tests/contrib:test_compare_ids_test_invalid_tar_fails"
8690
- "-//tests/contrib:test_compare_ids_test_invalid_tar_fails_multi_regex"

BUILD

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ licenses(["notice"]) # Apache 2.0
2121

2222
exports_files(["LICENSE"])
2323

24+
exports_files(["WORKSPACE"])
25+
2426
gazelle(
2527
name = "gazelle",
2628
prefix = "github.com/bazelbuild/rules_docker",

WORKSPACE

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ load("//repositories:deps.bzl", container_deps = "deps")
3737

3838
container_deps()
3939

40-
# pip deps are only needed for running tests.
40+
# pip deps are only needed for running tests.
4141
load("//repositories:pip_repositories.bzl", "pip_deps")
4242

4343
pip_deps()
@@ -47,7 +47,7 @@ load(
4747
"new_container_pull",
4848
)
4949

50-
# These are for testing the new container push
50+
# These are for testing the new container pull
5151
new_container_pull(
5252
name = "new_alpine_linux_armv6",
5353
architecture = "arm",
@@ -219,6 +219,14 @@ container_pull(
219219
repository = "google-appengine/debian9",
220220
)
221221

222+
# This image is used by tests/contrib tests.
223+
container_pull(
224+
name = "bazel_0271",
225+
digest = "sha256:436708ebb76c0089b94c46adac5d3332adb8c98ef8f24cb32274400d01bde9e3",
226+
registry = "l.gcr.io",
227+
repository = "google/bazel",
228+
)
229+
222230
# Have the py_image dependencies for testing.
223231
load(
224232
"//python:image.bzl",

contrib/BUILD

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ exports_files(["compare_ids_test.bzl"])
2525

2626
exports_files(["extract_image_id.py"])
2727

28+
exports_files(["cmp_images.sh.tpl"])
29+
2830
py_binary(
2931
name = "extract_image_id",
3032
srcs = [":extract_image_id.py"],

contrib/cmp_images.sh.tpl

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
#!/bin/bash
2+
#
3+
# Copyright 2017 The Bazel Authors. All rights reserved.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
# Testing script consumed by the container_repro_test rule that compares
18+
# two images.
19+
# Two images are considered to be identical when they both have the same
20+
# digest and ID. On a mismatch of one of those values, the test fails
21+
# and produces the summary of the images' differences.
22+
23+
set -e
24+
25+
imgs_differ=false
26+
27+
function cmp_sha_files() {
28+
local file1="${1}"
29+
local file2="${2}"
30+
local content_type="${3}"
31+
32+
local diff_ret=0
33+
diff $file1 $file2 || diff_ret=$?
34+
echo === Comparing image "${content_type}"s ===
35+
if [ $diff_ret = 0 ]; then
36+
echo Both images have the same SHA256 "${content_type}": "$(<$file1)"
37+
else
38+
echo Images have different SHA256 "${content_type}"s
39+
echo First image "${content_type}": "$(<$file1)"
40+
echo Reproduced image "${content_type}": "$(<$file2)"
41+
imgs_differ=true
42+
fi
43+
}
44+
45+
# Compare image digests.
46+
img1_digest_file=%{img1_path}/%{img_name}.digest
47+
img2_digest_file=%{img2_path}/%{img_name}.digest
48+
cmp_sha_files $img1_digest_file $img2_digest_file "digest"
49+
50+
# Compare image IDs
51+
img1_id_file="$(readlink -f %{img1_path}/%{img_name}.id)"
52+
img2_id_file="$(readlink -f %{img2_path}/%{img_name}.id)"
53+
cmp_sha_files "$img1_id_file" "$img2_id_file" "ID"
54+
55+
# Run the container_diff tool if images differ.
56+
if [ "$imgs_differ" = true ]; then
57+
echo === Images are different. Running container_diff tool ===
58+
img1_tar=%{img1_path}/%{img_name}.tar
59+
img2_tar=%{img2_path}/%{img_name}.tar
60+
%{container_diff_tool} diff $img1_tar $img2_tar %{container_diff_args}
61+
exit 1
62+
fi
63+
64+
exit 0

0 commit comments

Comments
 (0)