@@ -19,37 +19,41 @@ _attrs = {
19
19
"_windows_constraint" : attr .label (default = "@platforms//os:windows" ),
20
20
}
21
21
22
- CMD = """\
23
- #!/usr/bin/env bash
24
-
25
- {BASH_RLOCATION_FUNCTION}
22
+ CMD_HEAD = [
23
+ "#!/usr/bin/env bash" ,
24
+ "# This script generated by container_structure_test.bzl" ,
25
+ BASH_RLOCATION_FUNCTION ,
26
+ ]
26
27
28
+ CMD = """\
27
29
readonly st=$(rlocation {st_path})
28
30
readonly yq=$(rlocation {yq_path})
31
+ readonly image=$(rlocation {image_path})
29
32
30
33
# When the image points to a folder, we can read the index.json file inside
31
- if [[ -d "{image_path} " ]]; then
32
- readonly DIGEST=$("$yq" eval '.manifests[0].digest | sub(":"; "-")' "{image_path} /index.json")
33
- exec "$st" test {fixed_args} --default-image-tag "registry.structure_test.oci.local/image:$DIGEST" $@
34
+ if [[ -d "$image " ]]; then
35
+ readonly DIGEST=$("$yq" eval '.manifests[0].digest | sub(":"; "-")' "$image /index.json")
36
+ exec "$st" test --driver {driver} {fixed_args} --default-image-tag "registry.structure_test.oci.local/image:$DIGEST" $@
34
37
else
35
- exec "$st" test {fixed_args} $@
38
+ exec "$st" test --driver {driver} {fixed_args} $@
36
39
fi
37
40
"""
38
41
39
42
def _structure_test_impl (ctx ):
40
- fixed_args = ["--driver" , ctx . attr . driver ]
43
+ fixed_args = []
41
44
test_bin = ctx .toolchains ["@container_structure_test//bazel:structure_test_toolchain_type" ].st_info .binary
42
45
yq_bin = ctx .toolchains ["@aspect_bazel_lib//lib:yq_toolchain_type" ].yqinfo .bin
43
46
44
- image_path = ctx .file .image .short_path
47
+ image_path = to_rlocation_path (ctx , ctx .file .image )
48
+
45
49
# Prefer to use a tarball if we are given one, as it works with more 'driver' types.
46
50
if image_path .endswith (".tar" ):
47
- fixed_args .extend (["--image" , image_path ])
51
+ fixed_args .extend (["--image" , "$(rlocation %s)" % image_path ])
48
52
else :
49
53
# https://github.com/GoogleContainerTools/container-structure-test/blob/5e347b66fcd06325e3caac75ef7dc999f1a9b614/cmd/container-structure-test/app/cmd/test.go#L110
50
54
if ctx .attr .driver != "docker" :
51
55
fail ("when the 'driver' attribute is not 'docker', then the image must be a .tar file" )
52
- fixed_args .extend (["--image-from-oci-layout" , image_path ])
56
+ fixed_args .extend (["--image-from-oci-layout" , "$(rlocation %s)" % image_path ])
53
57
fixed_args .extend (["--default-image-tag" , "registry.structure_test.oci.local/image:$DIGEST" ])
54
58
55
59
for arg in ctx .files .configs :
@@ -58,10 +62,10 @@ def _structure_test_impl(ctx):
58
62
bash_launcher = ctx .actions .declare_file ("%s.sh" % ctx .label .name )
59
63
ctx .actions .write (
60
64
bash_launcher ,
61
- content = CMD .format (
62
- BASH_RLOCATION_FUNCTION = BASH_RLOCATION_FUNCTION ,
65
+ content = "\n " .join (CMD_HEAD ) + CMD .format (
63
66
st_path = to_rlocation_path (ctx , test_bin ),
64
67
yq_path = to_rlocation_path (ctx , yq_bin ),
68
+ driver = ctx .attr .driver ,
65
69
image_path = image_path ,
66
70
fixed_args = " " .join (fixed_args ),
67
71
),
@@ -70,11 +74,13 @@ def _structure_test_impl(ctx):
70
74
71
75
is_windows = ctx .target_platform_has_constraint (ctx .attr ._windows_constraint [platform_common .ConstraintValueInfo ])
72
76
launcher = create_windows_native_launcher_script (ctx , bash_launcher ) if is_windows else bash_launcher
73
-
74
77
runfiles = ctx .runfiles (
75
78
files = ctx .files .image + ctx .files .configs + [
76
- bash_launcher , test_bin , yq_bin
77
- ]).merge (ctx .attr ._runfiles .default_runfiles )
79
+ bash_launcher ,
80
+ test_bin ,
81
+ yq_bin ,
82
+ ],
83
+ ).merge (ctx .attr ._runfiles .default_runfiles )
78
84
79
85
return DefaultInfo (runfiles = runfiles , executable = launcher )
80
86
0 commit comments