Closed xnerhu closed 3 years ago
I think you may be missing the other WORKSPACE rules for JS: https://rules-proto-grpc.aliddell.com/en/latest/lang/js.html#id20
If you already have a “npm” rule, you need to add the required packages to the package.json at the top of that page.
I already have these rules in my WORKSPACE and also needed dependencies.
# Bazel workspace created by @bazel/create 4.0.0
# Declares that this directory is the root of a Bazel workspace.
# See https://docs.bazel.build/versions/main/build-ref.html#workspace
workspace(
# How this workspace would be referenced with absolute labels from another workspace
name = "init",
# Map the @npm bazel workspace to the node_modules directory.
# This lets Bazel use the same node_modules as other local tooling.
managed_directories = {"@npm": ["node_modules"]},
)
load("//:tools/bazel_deps.bzl", "fetch_dependencies")
fetch_dependencies()
load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace")
bazel_skylib_workspace()
load("@rules_proto_grpc//js:repositories.bzl", rules_proto_grpc_js_repos = "js_repos")
rules_proto_grpc_js_repos()
load("@build_bazel_rules_nodejs//:index.bzl", "yarn_install")
yarn_install(
name = "npm",
package_json = "//:package.json",
yarn_lock = "//:yarn.lock",
# quiet = False,
)
load(
"@io_bazel_rules_docker//repositories:repositories.bzl",
container_repositories = "repositories",
)
container_repositories()
load("@io_bazel_rules_docker//repositories:deps.bzl", container_deps = "deps")
container_deps()
load("@io_bazel_rules_docker//nodejs:image.bzl", nodejs_image_repos = "repositories")
nodejs_image_repos()
load("@npm//@bazel/labs:package.bzl", "npm_bazel_labs_dependencies")
npm_bazel_labs_dependencies()
load("@rules_proto//proto:repositories.bzl", "rules_proto_dependencies", "rules_proto_toolchains")
rules_proto_dependencies()
rules_proto_toolchains()
load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps")
protobuf_deps()
# load("@rules_typescript_proto//:index.bzl", "rules_typescript_proto_dependencies")
# rules_typescript_proto_dependencies()
load("@rules_proto_grpc//:repositories.bzl", "rules_proto_grpc_repos", "rules_proto_grpc_toolchains")
rules_proto_grpc_toolchains()
rules_proto_grpc_repos()
"dependencies": {
"@grpc/grpc-js": "^1.3.7",
"@nestjs/common": "^8.0.6",
"@nestjs/core": "^8.0.6",
"@nestjs/platform-fastify": "^8.0.6",
"express": "^4.17.1",
"fastify": "^3.20.2",
"google-protobuf": "^3.18.0",
"grpc-tools": "^1.11.2",
"grpc-web": "^1.2.1",
"nodemon": "^2.0.12",
"reflect-metadata": "^0.1.13",
"rxjs": "^7.3.0",
"socket.io": "^4.2.0",
"socket.io-client": "^4.2.0",
"ts-protoc-gen": "^0.15.0",
"winston": "^3.3.3",
"ws": "^8.2.1"
},
Gotcha, I’ll see if I can recreate the issue with that
On normal Linux it does work, but it doesn't on Github actions.
name: CI/CD
on:
pull_request:
push:
jobs:
build:
runs-on: ubuntu-latest
- name: Check out Git repository
uses: actions/checkout@v2
- name: Install Node.js
uses: actions/setup-node@v2
with:
node-version: 16
- name: Install dependencies
run: yarn install --frozen-lockfile
env:
ADBLOCK: true
- name: Build
run: npx bazel build //backend/questions-proto:components_proto
Also here is tools/bazel_deps.bzl
# This provides the basic tools for running and packaging nodejs programs in Bazel
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
def fetch_dependencies():
http_archive(
name = "bazel_skylib",
urls = [
"https://github.com/bazelbuild/bazel-skylib/releases/download/1.0.3/bazel-skylib-1.0.3.tar.gz",
"https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.0.3/bazel-skylib-1.0.3.tar.gz",
],
sha256 = "1c531376ac7e5a180e0237938a2536de0c54d93f5c278634818e0efc952dd56c",
)
http_archive(
name = "build_bazel_rules_nodejs",
sha256 = "b32a4713b45095e9e1921a7fcb1adf584bc05959f3336e7351bcf77f015a2d7c",
urls = ["https://github.com/bazelbuild/rules_nodejs/releases/download/4.1.0/rules_nodejs-4.1.0.tar.gz"],
)
http_archive(
name = "io_bazel_rules_docker",
sha256 = "1f4e59843b61981a96835dc4ac377ad4da9f8c334ebe5e0bb3f58f80c09735f4",
strip_prefix = "rules_docker-0.19.0",
urls = ["https://github.com/bazelbuild/rules_docker/releases/download/v0.19.0/rules_docker-v0.19.0.tar.gz"],
)
http_archive(
name = "com_google_protobuf",
sha256 = "c6003e1d2e7fefa78a3039f19f383b4f3a61e81be8c19356f85b6461998ad3db",
strip_prefix = "protobuf-3.17.3",
urls = ["https://github.com/protocolbuffers/protobuf/archive/v3.17.3.tar.gz"],
)
http_archive(
name = "rules_proto",
sha256 = "bc12122a5ae4b517fa423ea03a8d82ea6352d5127ea48cb54bc324e8ab78493c",
strip_prefix = "rules_proto-af6481970a34554c6942d993e194a9aed7987780",
urls = [
"https://github.com/bazelbuild/rules_proto/archive/af6481970a34554c6942d993e194a9aed7987780.tar.gz",
],
)
http_archive(
name = "rules_proto_grpc",
sha256 = "7954abbb6898830cd10ac9714fbcacf092299fda00ed2baf781172f545120419",
strip_prefix = "rules_proto_grpc-3.1.1",
urls = ["https://github.com/rules-proto-grpc/rules_proto_grpc/archive/3.1.1.tar.gz"],
)
I have made a reproduction repo and it seems it has something to do with Bazel cache. On completely new repo it does work. I don't know why, because I have changed cache versions in my official repo and everything was built again. https://github.com/xnerhu/grpc_node_plugin-repro
I've seen it before where the node_modules directory can do odd things with the cache like this. i.e Bazel thinks it exists but it's cached just an empty directory, so trying to open files in it fails. If you test removing managed_directories
here, does it still fail or can you no longer reproduce the failure?
It still fails.
I overlooked that I override node_modules folder in a different workflow step. The issue is totally on me. Thank you.
No problem, it's useful to have the issue documented in case someone has the same problem in the future 👍
Hello!
I have an issue where nodejs grpc rules don't work on Ubuntu on Github actions where on my WSL Ubuntu 20 they do work. It seems that grpc_node_plugin can't be found.