Skip to content

Commit

Permalink
Added more e2e tests for new_container_push to account for legacy for…
Browse files Browse the repository at this point in the history
…mat (bazelbuild#966)

* Added e2e tests for legacy format

* Fix formatting with comments

* Fix typo in BUILD file

* Add reference for testing target

* Fix test names

* Fix typo in command
  • Loading branch information
xiaohegong authored and k8s-ci-robot committed Jul 9, 2019
1 parent 301f858 commit c2f7f81
Show file tree
Hide file tree
Showing 14 changed files with 105 additions and 9 deletions.
14 changes: 14 additions & 0 deletions container/go/pkg/compat/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,17 @@ go_library(
"@com_github_pkg_errors//:go_default_library",
],
)

# This is a three-layer legacy image layout pulled by container_pull from gcr.io/asci-toolchain-sandbox/small_img@sha256:4817a495758a70edcaa9ed6723cd927f21c44e2061313b03aaf5d5ae2c1bff46. This is a very small image created for testing purposes.
filegroup(
name = "legacy_test_index1",
srcs = [
"//container/go/pkg/compat/testdata/test_index1:000.tar.gz",
"//container/go/pkg/compat/testdata/test_index1:001.tar.gz",
"//container/go/pkg/compat/testdata/test_index1:002.tar.gz",
"//container/go/pkg/compat/testdata/test_index1:config.json",
"//container/go/pkg/compat/testdata/test_index1:digest",
"//container/go/pkg/compat/testdata/test_index1:manifest.json",
],
visibility = ["//visibility:public"],
)
1 change: 1 addition & 0 deletions container/go/pkg/compat/testdata/test_index1/000.sha256
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2cbd3e7a7cca7df9201e626abe080efe75e0588dda3c0188b1caf3a011f300ca
Binary file not shown.
1 change: 1 addition & 0 deletions container/go/pkg/compat/testdata/test_index1/001.sha256
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
26c668c40574f4fefe17ddfbc3a8744a5b83b8c00a03dff790cbe6a397f66d79
Binary file not shown.
1 change: 1 addition & 0 deletions container/go/pkg/compat/testdata/test_index1/002.sha256
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3d4d5ef7eb586de880424d1613e36bc25a1617239ff81d8cf961c6481e6193af
Binary file not shown.
11 changes: 11 additions & 0 deletions container/go/pkg/compat/testdata/test_index1/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package(default_visibility = ["//visibility:public"])

load("@io_bazel_rules_docker//container:import.bzl", "container_import")

container_import(
name = "image",
config = "config.json",
layers = glob(["*.tar.gz"]),
)

exports_files(glob(["**"]))
1 change: 1 addition & 0 deletions container/go/pkg/compat/testdata/test_index1/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"architecture": "amd64", "author": "Bazel", "config": {}, "created": "1970-01-01T00:00:00Z", "history": [{"author": "Bazel", "created": "1970-01-01T00:00:00Z", "created_by": "bazel build ..."}, {"author": "Bazel", "created": "1970-01-01T00:00:00Z", "created_by": "bazel build ..."}, {"author": "Bazel", "created": "1970-01-01T00:00:00Z", "created_by": "bazel build ..."}], "os": "linux", "rootfs": {"diff_ids": ["sha256:cfebe149e813482640cd5509f6c866bd83709a56aaa82bda6b05d633bd571591", "sha256:7bb7138798ce1c3019d6e2f306296ef3712a6ebd52368bf8ee3a2c97a6ffda41", "sha256:f2cc51d9aa9896cb1491b84be069511dccbe7140284c363c2223770aec9fcb74"], "type": "layers"}}
1 change: 1 addition & 0 deletions container/go/pkg/compat/testdata/test_index1/digest
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sha256:4817a495758a70edcaa9ed6723cd927f21c44e2061313b03aaf5d5ae2c1bff46
1 change: 1 addition & 0 deletions container/go/pkg/compat/testdata/test_index1/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"config": {"digest": "sha256:93cd8b73a9da05da6e1a9739e3610cbb0f19439d693931d3bf011d1d92b9e569", "mediaType": "application/vnd.docker.container.image.v1+json", "size": 658}, "layers": [{"digest": "sha256:2cbd3e7a7cca7df9201e626abe080efe75e0588dda3c0188b1caf3a011f300ca", "mediaType": "application/vnd.docker.image.rootfs.diff.tar.gzip", "size": 157}, {"digest": "sha256:26c668c40574f4fefe17ddfbc3a8744a5b83b8c00a03dff790cbe6a397f66d79", "mediaType": "application/vnd.docker.image.rootfs.diff.tar.gzip", "size": 135}, {"digest": "sha256:3d4d5ef7eb586de880424d1613e36bc25a1617239ff81d8cf961c6481e6193af", "mediaType": "application/vnd.docker.image.rootfs.diff.tar.gzip", "size": 135}], "mediaType": "application/vnd.docker.distribution.manifest.v2+json", "schemaVersion": 2}
2 changes: 1 addition & 1 deletion container/pull.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ container_import(
layers = glob(["*.tar.gz"]),
)
exports_files(["image.digest", "digest"])
exports_files(glob(["**"]))
""")

args = [
Expand Down
59 changes: 52 additions & 7 deletions testing/e2e.sh
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,48 @@ function test_new_container_push_oci() {
docker stop -t 0 $cid
}

function test_new_container_push_legacy() {
cd "${ROOT}"
clear_docker_full
cid=$(docker run --rm -d -p 5000:5000 --name registry registry:2)

EXPECT_CONTAINS "$(bazel run @io_bazel_rules_docker//tests/container:new_push_test_legacy 2>&1)" "Successfully pushed legacy image"
docker stop -t 0 $cid
}

function test_new_container_push_legacy_tag_file() {
cd "${ROOT}"
clear_docker_full
cid=$(docker run --rm -d -p 5000:5000 --name registry registry:2)
bazel build tests/container:new_push_test_legacy_tag_file
EXPECT_CONTAINS "$(cat bazel-bin/tests/container/new_push_test_legacy_tag_file)" '-dst localhost:5000/docker/test:$(cat ${RUNFILES}/io_bazel_rules_docker/tests/container/test.tag)'

docker stop -t 0 $cid
}

function test_new_container_push_legacy_with_auth() {
clear_docker_full
launch_private_registry_with_auth

# Run the new_container_push test in the Bazel workspace that configured
# the docker toolchain rule to use authentication.
cd "${ROOT}/testing/custom_toolchain_auth"
bazel_opts=" --override_repository=io_bazel_rules_docker=${ROOT}"
echo "Attempting authenticated new container_push..."

EXPECT_CONTAINS "$(bazel run $bazel_opts @io_bazel_rules_docker//tests/container:new_push_test_legacy 2>&1)" "Successfully pushed legacy image"
bazel clean

# Run the new_container_push test in the Bazel workspace that uses the default
# configured docker toolchain. The default configuration doesn't setup
# authentication and this should fail.
cd "${ROOT}/testing/default_toolchain"
bazel_opts=" --override_repository=io_bazel_rules_docker=${ROOT}"
echo "Attempting unauthenticated new container_push..."
EXPECT_CONTAINS "$(bazel run $bazel_opts @io_bazel_rules_docker//tests/container:new_push_test_legacy 2>&1)" "unable to push image to localhost:5000/docker/test:test: unsupported status code 401"
bazel clean
}

function test_new_container_push_tar() {
cd "${ROOT}"
clear_docker_full
Expand All @@ -139,12 +181,12 @@ function test_new_container_push_tar() {

docker stop -t 0 $cid
}
function test_new_container_push_tag_file() {
function test_new_container_push_oci_tag_file() {
cd "${ROOT}"
clear_docker_full
cid=$(docker run --rm -d -p 5000:5000 --name registry registry:2)
bazel build tests/container:new_push_tag_file_test
EXPECT_CONTAINS "$(cat bazel-bin/tests/container/new_push_tag_file_test)" '-dst localhost:5000/docker/test:$(cat ${RUNFILES}/io_bazel_rules_docker/tests/container/test.tag)'
bazel build tests/container:new_push_test_oci_tag_file
EXPECT_CONTAINS "$(cat bazel-bin/tests/container/new_push_test_oci_tag_file)" '-dst localhost:5000/docker/test:$(cat ${RUNFILES}/io_bazel_rules_docker/tests/container/test.tag)'

docker stop -t 0 $cid
}
Expand Down Expand Up @@ -199,7 +241,7 @@ function test_container_push_with_auth() {
}

# Test container push where the local registry requires htpsswd authentication
function test_new_container_push_with_auth() {
function test_new_container_push_oci_with_auth() {
clear_docker_full
launch_private_registry_with_auth

Expand All @@ -211,7 +253,7 @@ function test_new_container_push_with_auth() {
bazel_opts=" --override_repository=io_bazel_rules_docker=${ROOT}"
echo "Attempting authenticated new container_push..."

EXPECT_CONTAINS "$(bazel run $bazel_opts @io_bazel_rules_docker//tests/container:new_push_test_oci 2>&1)" "Successfully pushed oci image from"
EXPECT_CONTAINS "$(bazel run $bazel_opts @io_bazel_rules_docker//tests/container:new_push_test_oci 2>&1)" "Successfully pushed oci image"
bazel clean

# Run the new_container_push test in the Bazel workspace that uses the default
Expand Down Expand Up @@ -301,8 +343,11 @@ test_container_push_with_auth
test_container_push_with_stamp
test_new_container_push_oci
test_new_container_push_tar
test_new_container_push_tag_file
test_new_container_push_with_auth
test_new_container_push_oci_tag_file
test_new_container_push_oci_with_auth
test_new_container_push_legacy
test_new_container_push_legacy_tag_file
test_new_container_push_legacy_with_auth
test_container_pull_with_auth
test_container_pull_cache

Expand Down
22 changes: 21 additions & 1 deletion tests/container/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,16 @@ new_container_push(
tags = ["manual"],
)

new_container_push(
name = "new_push_test_legacy",
format = "legacy",
image = "//container/go/pkg/compat:legacy_test_index1",
registry = "localhost:5000",
repository = "docker/test",
tag = "test",
tags = ["manual"],
)

new_container_push(
name = "new_push_test_tar",
format = "docker",
Expand All @@ -381,14 +391,24 @@ new_container_push(
)

new_container_push(
name = "new_push_tag_file_test",
name = "new_push_test_oci_tag_file",
format = "oci",
image = "//container/go/pkg/oci:oci_test_index1",
registry = "localhost:5000",
repository = "docker/test",
tag_file = ":test.tag",
tags = ["manual"],
)

new_container_push(
name = "new_push_test_legacy_tag_file",
format = "legacy",
image = "//container/go/pkg/compat:legacy_test_index1",
registry = "localhost:5000",
repository = "docker/test",
tag_file = ":test.tag",
tags = ["manual"],
)
# END_DO_NOT_IMPORT

# The following targets are not imported.
Expand Down

0 comments on commit c2f7f81

Please sign in to comment.