Skip to content

Commit

Permalink
Properly set cmd from args in lang images. (#624)
Browse files Browse the repository at this point in the history
Fixes #618.
  • Loading branch information
xingao267 authored Dec 17, 2018
1 parent 9fcb3a7 commit e29affb
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 3 deletions.
3 changes: 3 additions & 0 deletions lang/image.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
49 changes: 47 additions & 2 deletions tests/docker/nodejs/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand All @@ -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",
)
13 changes: 13 additions & 0 deletions tests/docker/nodejs/configs/nodejs_image_empty_list_args.yaml
Original file line number Diff line number Diff line change
@@ -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"
Original file line number Diff line number Diff line change
@@ -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"
2 changes: 1 addition & 1 deletion tests/docker/nodejs/configs/nodejs_image_no_args.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
schemaVersion: 2.0.0

metadataTest:
cmd: [""]
cmd: Null
env:
- key: PORT
value: "8080"
Expand Down
13 changes: 13 additions & 0 deletions tests/docker/nodejs/configs/nodejs_image_none_args.yaml
Original file line number Diff line number Diff line change
@@ -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"

0 comments on commit e29affb

Please sign in to comment.