From e29affb8294a1b50c3b10a2dc2ba8ab0c6c4c9bb Mon Sep 17 00:00:00 2001 From: Xin Date: Mon, 17 Dec 2018 15:53:11 -0500 Subject: [PATCH] Properly set `cmd` from `args` in lang images. (#624) Fixes #618. --- lang/image.bzl | 3 ++ tests/docker/nodejs/BUILD | 49 ++++++++++++++++++- .../configs/nodejs_image_empty_list_args.yaml | 13 +++++ ...ejs_image_list_with_empty_string_args.yaml | 13 +++++ .../nodejs/configs/nodejs_image_no_args.yaml | 2 +- .../configs/nodejs_image_none_args.yaml | 13 +++++ 6 files changed, 90 insertions(+), 3 deletions(-) create mode 100644 tests/docker/nodejs/configs/nodejs_image_empty_list_args.yaml create mode 100644 tests/docker/nodejs/configs/nodejs_image_list_with_empty_string_args.yaml create mode 100644 tests/docker/nodejs/configs/nodejs_image_none_args.yaml diff --git a/lang/image.bzl b/lang/image.bzl index 3152daf34..7b93e945b 100644 --- a/lang/image.bzl +++ b/lang/image.bzl @@ -196,6 +196,9 @@ def app_layer_impl(ctx, runfiles = None, emptyfiles = None): # we should use the "exec" (list) form of entrypoint. entrypoint = entrypoint, cmd = args, + # If `args` is set to [], None or not set, Docker config will have + # a null `Cmd` value. + null_cmd = args == [], ) _app_layer = rule( diff --git a/tests/docker/nodejs/BUILD b/tests/docker/nodejs/BUILD index 4e3686cca..5cad0505d 100644 --- a/tests/docker/nodejs/BUILD +++ b/tests/docker/nodejs/BUILD @@ -16,6 +16,7 @@ package(default_visibility = ["//visibility:public"]) load("//nodejs:image.bzl", "nodejs_image") load("//contrib:test.bzl", "container_test") +# Docker Cmd value should be `["arg0", "arg1"]`. nodejs_image( name = "nodejs_image", args = [ @@ -27,23 +28,67 @@ nodejs_image( node_modules = "@npm_deps//:node_modules", ) +# Docker Cmd value should be `[""]`. nodejs_image( - name = "nodejs_image_no_args", - # this should work without having to set args to empty list + name = "nodejs_image_list_with_empty_string_args", args = [""], data = ["//testdata:nodejs_image.js"], entry_point = "io_bazel_rules_docker/testdata/nodejs_image.js", node_modules = "@npm_deps//:node_modules", ) +# Docker Cmd value should be `null`. +nodejs_image( + name = "nodejs_image_no_args", + data = ["//testdata:nodejs_image.js"], + entry_point = "io_bazel_rules_docker/testdata/nodejs_image.js", + node_modules = "@npm_deps//:node_modules", +) + +# Docker Cmd value should be `null`. +nodejs_image( + name = "nodejs_image_empty_list_args", + args = [], + data = ["//testdata:nodejs_image.js"], + entry_point = "io_bazel_rules_docker/testdata/nodejs_image.js", + node_modules = "@npm_deps//:node_modules", +) + +# Docker Cmd value should be `null`. +nodejs_image( + name = "nodejs_image_none_args", + args = None, + data = ["//testdata:nodejs_image.js"], + entry_point = "io_bazel_rules_docker/testdata/nodejs_image.js", + node_modules = "@npm_deps//:node_modules", +) + container_test( name = "nodejs_image_test", configs = ["//tests/docker/nodejs/configs:nodejs_image.yaml"], image = ":nodejs_image", ) +container_test( + name = "nodejs_image_list_with_empty_string_args_test", + configs = ["//tests/docker/nodejs/configs:nodejs_image_list_with_empty_string_args.yaml"], + image = ":nodejs_image_list_with_empty_string_args", +) + container_test( name = "nodejs_image_no_args_test", configs = ["//tests/docker/nodejs/configs:nodejs_image_no_args.yaml"], image = ":nodejs_image_no_args", ) + +container_test( + name = "nodejs_image_empty_list_args_test", + configs = ["//tests/docker/nodejs/configs:nodejs_image_empty_list_args.yaml"], + image = ":nodejs_image_empty_list_args", +) + +container_test( + name = "nodejs_image_none_args_test", + configs = ["//tests/docker/nodejs/configs:nodejs_image_none_args.yaml"], + image = ":nodejs_image_none_args", +) diff --git a/tests/docker/nodejs/configs/nodejs_image_empty_list_args.yaml b/tests/docker/nodejs/configs/nodejs_image_empty_list_args.yaml new file mode 100644 index 000000000..355a2809c --- /dev/null +++ b/tests/docker/nodejs/configs/nodejs_image_empty_list_args.yaml @@ -0,0 +1,13 @@ +schemaVersion: 2.0.0 + +metadataTest: + cmd: Null + env: + - key: PORT + value: "8080" + - key: DEBIAN_FRONTEND + value: "noninteractive" + - key: PATH + value: "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" + entrypoint: ['/app/tests/docker/nodejs/nodejs_image_empty_list_args.binary'] + workdir: "/app/tests/docker/nodejs/nodejs_image_empty_list_args.binary.runfiles/io_bazel_rules_docker" diff --git a/tests/docker/nodejs/configs/nodejs_image_list_with_empty_string_args.yaml b/tests/docker/nodejs/configs/nodejs_image_list_with_empty_string_args.yaml new file mode 100644 index 000000000..fa3773682 --- /dev/null +++ b/tests/docker/nodejs/configs/nodejs_image_list_with_empty_string_args.yaml @@ -0,0 +1,13 @@ +schemaVersion: 2.0.0 + +metadataTest: + cmd: [""] + env: + - key: PORT + value: "8080" + - key: DEBIAN_FRONTEND + value: "noninteractive" + - key: PATH + value: "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" + entrypoint: ['/app/tests/docker/nodejs/nodejs_image_list_with_empty_string_args.binary'] + workdir: "/app/tests/docker/nodejs/nodejs_image_list_with_empty_string_args.binary.runfiles/io_bazel_rules_docker" diff --git a/tests/docker/nodejs/configs/nodejs_image_no_args.yaml b/tests/docker/nodejs/configs/nodejs_image_no_args.yaml index b52ea58a6..063e26942 100644 --- a/tests/docker/nodejs/configs/nodejs_image_no_args.yaml +++ b/tests/docker/nodejs/configs/nodejs_image_no_args.yaml @@ -1,7 +1,7 @@ schemaVersion: 2.0.0 metadataTest: - cmd: [""] + cmd: Null env: - key: PORT value: "8080" diff --git a/tests/docker/nodejs/configs/nodejs_image_none_args.yaml b/tests/docker/nodejs/configs/nodejs_image_none_args.yaml new file mode 100644 index 000000000..cd8e559f3 --- /dev/null +++ b/tests/docker/nodejs/configs/nodejs_image_none_args.yaml @@ -0,0 +1,13 @@ +schemaVersion: 2.0.0 + +metadataTest: + cmd: Null + env: + - key: PORT + value: "8080" + - key: DEBIAN_FRONTEND + value: "noninteractive" + - key: PATH + value: "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" + entrypoint: ['/app/tests/docker/nodejs/nodejs_image_none_args.binary'] + workdir: "/app/tests/docker/nodejs/nodejs_image_none_args.binary.runfiles/io_bazel_rules_docker"