| load("@build_bazel_rules_nodejs//:index.bzl", "nodejs_binary") |
| load("@io_bazel_rules_docker//contrib:test.bzl", "container_test") |
| load("@io_bazel_rules_docker//nodejs:image.bzl", "nodejs_image") |
| load("@bazel_skylib//rules:write_file.bzl", "write_file") |
| |
| nodejs_binary( |
| name = "main", |
| data = [ |
| "//foolib", |
| "@npm//date-fns", |
| ], |
| entry_point = "main.js", |
| ) |
| |
| # bazel run --platforms=@rules_nodejs//:linux_amd64 //:nodejs_image |
| nodejs_image( |
| name = "nodejs_image", |
| binary = ":main", |
| include_node_repo_args = False, |
| node_repository_name = "nodejs_linux_amd64", |
| ) |
| |
| container_test( |
| name = "nodejs_image_test", |
| configs = [":nodejs_image.yaml"], |
| image = ":nodejs_image", |
| ) |
| |
| # this creates: |
| # bazel run main_node15_linux_amd64 |
| # bazel run main_node16_linux_amd64 |
| # bazel run nodejs_image_node15_linux_amd64 |
| # bazel run nodejs_image_node16_linux_amd64 |
| # bazel test nodejs_image_test_node15_linux_amd64 |
| # bazel test nodejs_image_test_node16_linux_amd64 |
| [ |
| [ |
| # Trivial test fixture: a nodejs program that writes to a file |
| write_file( |
| name = "test_" + id, |
| out = "image_%s.yaml" % id, |
| content = [ |
| "schemaVersion: 2.0.0", |
| "metadataTest:", |
| " entrypoint: ['/app//main_%s']" % id, |
| """ workdir: "/app//main_%s.runfiles/e2e_nodejs_image" """ % id, |
| ], |
| ), |
| nodejs_binary( |
| name = "main_" + id, |
| data = [ |
| "//foolib", |
| "@npm//date-fns", |
| ], |
| entry_point = "binary_version.js", |
| toolchain = toolchain, |
| ), |
| nodejs_image( |
| name = "nodejs_image_" + id, |
| binary = ":main_" + id, |
| include_node_repo_args = False, |
| node_repository_name = id, |
| ), |
| container_test( |
| name = "nodejs_image_test_" + id, |
| configs = ["test_" + id], |
| image = ":nodejs_image_" + id, |
| ), |
| ] |
| for id, toolchain in zip( |
| [ |
| "node15_linux_amd64", |
| "node16_linux_amd64", |
| ], |
| [ |
| "@node15_linux_amd64//:node_toolchain", |
| "@node16_linux_amd64//:node_toolchain", |
| ], |
| ) |
| ] |