Skip to content

Commit

Permalink
rules_r: fix binary_image and write tests
Browse files Browse the repository at this point in the history
binary_image rule has been broken after the flag
incompatible_depset_is_not_iterable was flipped.

This change fixes the implementation and also introduces some tests for
images. In writing these tests, another breakage has been discovered
because of the flag flip of experimental_remap_main_repo. This bug will
be fixed at a later date.
  • Loading branch information
Siddhartha Bagaria committed Mar 6, 2020
1 parent 51386cf commit ec66be6
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 6 deletions.
2 changes: 1 addition & 1 deletion R/container/binary.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def _binary_layer_impl(ctx):
directory = "/",
file_map = {
_layer_file_path(ctx, f): f
for f in ctx.attr.binary[OutputGroupInfo][ctx.attr.layer_type]
for f in ctx.attr.binary[OutputGroupInfo][ctx.attr.layer_type].to_list()
},
)

Expand Down
4 changes: 2 additions & 2 deletions tests/container/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ sh_test(
size = "small",
srcs = ["image_test.sh"],
data = [
":binary_image",
":binary_image_explicit_layers",
":library_archive",
":library_image",
],
)

# TODO: Introduce tests for binary_image after moving to rules_docker.

r_binary_image(
name = "binary_image",
base = "@r_base//image",
Expand Down
44 changes: 41 additions & 3 deletions tests/container/image_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,13 @@ check() {
echo "${TAR}" not found.
exit 1
fi
echo "Looking for file ${FILE_TO_CHECK} in ${TAR}:"
printf "Looking for file %s in %s: " "${FILE_TO_CHECK}" "${TAR}"
if tar -tf "${TAR}" "${FILE_TO_CHECK}" >/dev/null 2>/dev/null; then
$EXPECT || (echo "Found but not expecting!" && exit 1)
($EXPECT && echo "Found and expecting") || (echo "Found but not expecting!" && exit 1)
elif $EXPECT; then
echo "Not found!" && exit 1
else
echo "Not found and not expecting"
fi
}

Expand All @@ -49,4 +51,40 @@ check "library_image_internal-layer.tar" "./grail/r-libs/bitops/DESCRIPTION" "fa
check "library_archive.tar.gz" "./grail/r-libs/exampleC/DESCRIPTION" "false"
check "library_archive.tar.gz" "./grail/r-libs/bitops/DESCRIPTION" "true"

echo "Found!"
# TODO: Making an image by repo is not working as intended because all files
# are also present in the topmost layer.

# Check binary script and R library packages.
check "binary_image-layer.tar" "/app/binary/binary" "true"
check "binary_image-layer.tar" "./app/binary/binary.runfiles/com_grail_rules_r_tests/binary/binary.R" "true"
check "binary_image-layer.tar" "./app/binary/binary.runfiles/com_grail_rules_r_tests/exampleA/lib/exampleA/DESCRIPTION" "true"
check "binary_image-layer.tar" "./app/binary/binary.runfiles/com_grail_rules_r_tests/exampleB/lib/exampleB/DESCRIPTION" "true"
check "binary_image-layer.tar" "./app/binary/binary.runfiles/com_grail_rules_r_tests/exampleC/lib/exampleC/DESCRIPTION" "true"
check "binary_image-layer.tar" "./app/binary/binary.runfiles/R_bitops/lib/bitops/DESCRIPTION" "true"
check "binary_image-layer.tar" "./app/binary/binary.runfiles/R_R6/lib/R6/DESCRIPTION" "true"

# TODO: Making an image by explicit layers is currently broken because the
# package files are not symlinked correctly because of change in behavior re
# remap_main_repo.

# Check that explicitly layered packages are not in the top layer, but in one layer below.
check "binary_image_explicit_layers-layer.tar" "/app/binary/binary" "true"
check "binary_image_explicit_layers-layer.tar" "./app/binary/binary.runfiles/com_grail_rules_r_tests/binary/binary.R" "true"
check "binary_image_explicit_layers-layer.tar" "./app/binary/binary.runfiles/com_grail_rules_r_tests/exampleA/lib/exampleA/DESCRIPTION" "true"
check "binary_image_explicit_layers-layer.tar" "./app/binary/binary.runfiles/com_grail_rules_r_tests/exampleB/lib/exampleB/DESCRIPTION" "true"
check "binary_image_explicit_layers-layer.tar" "./app/binary/binary.runfiles/com_grail_rules_r_tests/exampleC/lib/exampleC/DESCRIPTION" "true"
check "binary_image_explicit_layers-layer.tar" "./app/binary/binary.runfiles/R_bitops/lib/bitops/DESCRIPTION" "false"
check "binary_image_explicit_layers-layer.tar" "./app/binary/binary.runfiles/R_R6/lib/R6/DESCRIPTION" "false"
#check "binary_image_explicit_layers.0-layer.tar" "./app/binary/binary.runfiles/R_bitops/lib/bitops/DESCRIPTION" "true"
check "binary_image_explicit_layers.0-layer.tar" "./app/binary/binary.runfiles/R_R6/lib/R6/DESCRIPTION" "false"
check "binary_image_explicit_layers.1-layer.tar" "./app/binary/binary.runfiles/R_bitops/lib/bitops/DESCRIPTION" "false"
#check "binary_image_explicit_layers.1-layer.tar" "./app/binary/binary.runfiles/R_R6/lib/R6/DESCRIPTION" "true"

# TODO: fix image by explicit layers (see also TODO above).

if docker --version; then
binary_image.executable
# binary_image_explicit_layers.executable
fi

echo "SUCCESS!"

0 comments on commit ec66be6

Please sign in to comment.