- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我是 Bazel 新手,无法找到有关为 Node.Js 构建 Docker 镜像的足够资源。
所以我有一个用 Typescript 编写的 Node.js 应用程序,具体取决于另外两个 Typescript 包。我的目标是构建一个 Docker 镜像,然后可以将其部署到 Kubernetes。
我已经有一个可用的 Dockerfile
:
FROM node:10-alpine
WORKDIR /usr/app/src
COPY package.json .
COPY yarn.lock .
COPY ./packages ./packages
COPY ./services/gateway ./services/gateway
RUN yarn install
COPY ./tsconfig.settings.json ./
COPY ./tsconfig.json ./
WORKDIR /usr/app/src/services/gateway
CMD yarn start
但我正在努力通过 Bazel 复制它。
<小时/>WORKSPACE.bazel
文件:
workspace(name = "learning_bazel_monorepo")
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
###############################
# NOEJS #
###############################
http_archive(
name = "build_bazel_rules_nodejs",
sha256 = "16fc00ab0d1e538e88f084272316c0693a2e9007d64f45529b82f6230aedb073",
urls = ["https://github.com/bazelbuild/rules_nodejs/releases/download/0.42.2/rules_nodejs-0.42.2.tar.gz"],
)
# Setup the NodeJS toolchain
load("@build_bazel_rules_nodejs//:defs.bzl", "node_repositories", "yarn_install")
node_repositories()
# Setup Bazel managed npm dependencies with the `yarn_install` rule.
# The name of this rule should be set to `npm` so that `ts_library` and `ts_web_test_suite`
# can find your npm dependencies by default in the `@npm` workspace. You may
# also use the `npm_install` rule with a `package-lock.json` file if you prefer.
# See https://github.com/bazelbuild/rules_nodejs#dependencies for more info.
yarn_install(
name = "npm",
package_json = "//:package.json",
yarn_lock = "//:yarn.lock",
)
###############################
# TYPESCRIPT #
###############################
http_archive(
name = "build_bazel_rules_typescript",
url = "https://github.com/bazelbuild/rules_typescript/archive/0.20.3.zip",
strip_prefix = "rules_typescript-0.20.3",
)
load("@npm//:install_bazel_dependencies.bzl", "install_bazel_dependencies")
install_bazel_dependencies()
# Set up TypeScript toolchain
load("@npm_bazel_typescript//:index.bzl", "ts_setup_workspace")
ts_setup_workspace()
###############################
# DOCKER #
###############################
http_archive(
name = "io_bazel_rules_docker",
sha256 = "14ac30773fdb393ddec90e158c9ec7ebb3f8a4fd533ec2abbfd8789ad81a284b",
strip_prefix = "rules_docker-0.12.1",
urls = ["https://github.com/bazelbuild/rules_docker/releases/download/v0.12.1/rules_docker-v0.12.1.tar.gz"],
)
load("@io_bazel_rules_docker//repositories:repositories.bzl", container_repositories = "repositories")
container_repositories()
load("@io_bazel_rules_docker//nodejs:image.bzl", _nodejs_image_repos = "repositories")
_nodejs_image_repos()
BUILD.bazel
在 Node.Js 应用程序的目录中:
package(default_visibility=["//visibility:public"])
load("@npm_bazel_typescript//:index.bzl", "ts_library")
ts_library(
name = "gateway",
srcs = [":src/index.ts"],
module_name = "@learning-bazel-monorepo/gateway",
deps = [
"@npm//express"
],
)
load("@io_bazel_rules_docker//nodejs:image.bzl", "nodejs_image")
nodejs_image(
name = "gateway_image",
entry_point = "services/gateway/dist/index.js",
node_modules = "@npm//:node_modules",
data = [":gateway"],
)
运行 bazel build//...
时出现错误:
ERROR: /home/flo/.cache/bazel/_bazel_flo/0eadfacb2a20f703f8711dd83de17c79/external/npm/BUILD.bazel:9:1: Label '@npm//:node_modules/@learning-bazel-monorepo/gateway/BUILD.bazel' is invalid because '@npm//node_modules/@learning-bazel-monorepo/gateway' is a subpackage; perhaps you meant to put the colon here: '@npm//node_modules/@learning-bazel-monorepo/gateway:BUILD.bazel'?
ERROR: /home/flo/.cache/bazel/_bazel_flo/0eadfacb2a20f703f8711dd83de17c79/external/npm/BUILD.bazel:9:1: Label '@npm//:node_modules/@learning-bazel-monorepo/gateway/dev.Dockerfile' is invalid because '@npm//node_modules/@learning-bazel-monorepo/gateway' is a subpackage; perhaps you meant to put the colon here: '@npm//node_modules/@learning-bazel-monorepo/gateway:dev.Dockerfile'?
ERROR: /home/flo/.cache/bazel/_bazel_flo/0eadfacb2a20f703f8711dd83de17c79/external/npm/BUILD.bazel:9:1: Label '@npm//:node_modules/@learning-bazel-monorepo/gateway/dist/index.d.ts' is invalid because '@npm//node_modules/@learning-bazel-monorepo/gateway' is a subpackage; perhaps you meant to put the colon here: '@npm//node_modules/@learning-bazel-monorepo/gateway:dist/index.d.ts'?
ERROR: /home/flo/.cache/bazel/_bazel_flo/0eadfacb2a20f703f8711dd83de17c79/external/npm/BUILD.bazel:9:1: Label '@npm//:node_modules/@learning-bazel-monorepo/gateway/dist/index.d.ts.map' is invalid because '@npm//node_modules/@learning-bazel-monorepo/gateway' is a subpackage; perhaps you meant to put the colon here: '@npm//node_modules/@learning-bazel-monorepo/gateway:dist/index.d.ts.map'?
ERROR: /home/flo/.cache/bazel/_bazel_flo/0eadfacb2a20f703f8711dd83de17c79/external/npm/BUILD.bazel:9:1: Label '@npm//:node_modules/@learning-bazel-monorepo/gateway/dist/index.js' is invalid because '@npm//node_modules/@learning-bazel-monorepo/gateway' is a subpackage; perhaps you meant to put the colon here: '@npm//node_modules/@learning-bazel-monorepo/gateway:dist/index.js'?
ERROR: /home/flo/.cache/bazel/_bazel_flo/0eadfacb2a20f703f8711dd83de17c79/external/npm/BUILD.bazel:9:1: Label '@npm//:node_modules/@learning-bazel-monorepo/gateway/dist/server.d.ts' is invalid because '@npm//node_modules/@learning-bazel-monorepo/gateway' is a subpackage; perhaps you meant to put the colon here: '@npm//node_modules/@learning-bazel-monorepo/gateway:dist/server.d.ts'?
ERROR: /home/flo/.cache/bazel/_bazel_flo/0eadfacb2a20f703f8711dd83de17c79/external/npm/BUILD.bazel:9:1: Label '@npm//:node_modules/@learning-bazel-monorepo/gateway/dist/server.d.ts.map' is invalid because '@npm//node_modules/@learning-bazel-monorepo/gateway' is a subpackage; perhaps you meant to put the colon here: '@npm//node_modules/@learning-bazel-monorepo/gateway:dist/server.d.ts.map'?
ERROR: /home/flo/.cache/bazel/_bazel_flo/0eadfacb2a20f703f8711dd83de17c79/external/npm/BUILD.bazel:9:1: Label '@npm//:node_modules/@learning-bazel-monorepo/gateway/dist/server.js' is invalid because '@npm//node_modules/@learning-bazel-monorepo/gateway' is a subpackage; perhaps you meant to put the colon here: '@npm//node_modules/@learning-bazel-monorepo/gateway:dist/server.js'?
ERROR: /home/flo/.cache/bazel/_bazel_flo/0eadfacb2a20f703f8711dd83de17c79/external/npm/BUILD.bazel:9:1: Label '@npm//:node_modules/@learning-bazel-monorepo/gateway/node_modules/.bin/nodemon' is invalid because '@npm//node_modules/@learning-bazel-monorepo/gateway' is a subpackage; perhaps you meant to put the colon here: '@npm//node_modules/@learning-bazel-monorepo/gateway:node_modules/.bin/nodemon'?
ERROR: /home/flo/.cache/bazel/_bazel_flo/0eadfacb2a20f703f8711dd83de17c79/external/npm/BUILD.bazel:9:1: Label '@npm//:node_modules/@learning-bazel-monorepo/gateway/node_modules/.bin/ts-node' is invalid because '@npm//node_modules/@learning-bazel-monorepo/gateway' is a subpackage; perhaps you meant to put the colon here: '@npm//node_modules/@learning-bazel-monorepo/gateway:node_modules/.bin/ts-node'?
ERROR: /home/flo/.cache/bazel/_bazel_flo/0eadfacb2a20f703f8711dd83de17c79/external/npm/BUILD.bazel:9:1: Label '@npm//:node_modules/@learning-bazel-monorepo/gateway/node_modules/.bin/tsc' is invalid because '@npm//node_modules/@learning-bazel-monorepo/gateway' is a subpackage; perhaps you meant to put the colon here: '@npm//node_modules/@learning-bazel-monorepo/gateway:node_modules/.bin/tsc'?
ERROR: /home/flo/.cache/bazel/_bazel_flo/0eadfacb2a20f703f8711dd83de17c79/external/npm/BUILD.bazel:9:1: Label '@npm//:node_modules/@learning-bazel-monorepo/gateway/node_modules/.bin/tsserver' is invalid because '@npm//node_modules/@learning-bazel-monorepo/gateway' is a subpackage; perhaps you meant to put the colon here: '@npm//node_modules/@learning-bazel-monorepo/gateway:node_modules/.bin/tsserver'?
ERROR: /home/flo/.cache/bazel/_bazel_flo/0eadfacb2a20f703f8711dd83de17c79/external/npm/BUILD.bazel:9:1: Label '@npm//:node_modules/@learning-bazel-monorepo/gateway/package.json' is invalid because '@npm//node_modules/@learning-bazel-monorepo/gateway' is a subpackage; perhaps you meant to put the colon here: '@npm//node_modules/@learning-bazel-monorepo/gateway:package.json'?
ERROR: /home/flo/.cache/bazel/_bazel_flo/0eadfacb2a20f703f8711dd83de17c79/external/npm/BUILD.bazel:9:1: Label '@npm//:node_modules/@learning-bazel-monorepo/gateway/prod.Dockerfile' is invalid because '@npm//node_modules/@learning-bazel-monorepo/gateway' is a subpackage; perhaps you meant to put the colon here: '@npm//node_modules/@learning-bazel-monorepo/gateway:prod.Dockerfile'?
ERROR: /home/flo/.cache/bazel/_bazel_flo/0eadfacb2a20f703f8711dd83de17c79/external/npm/BUILD.bazel:9:1: Label '@npm//:node_modules/@learning-bazel-monorepo/gateway/src/index.ts' is invalid because '@npm//node_modules/@learning-bazel-monorepo/gateway' is a subpackage; perhaps you meant to put the colon here: '@npm//node_modules/@learning-bazel-monorepo/gateway:src/index.ts'?
ERROR: /home/flo/.cache/bazel/_bazel_flo/0eadfacb2a20f703f8711dd83de17c79/external/npm/BUILD.bazel:9:1: Label '@npm//:node_modules/@learning-bazel-monorepo/gateway/src/server.ts' is invalid because '@npm//node_modules/@learning-bazel-monorepo/gateway' is a subpackage; perhaps you meant to put the colon here: '@npm//node_modules/@learning-bazel-monorepo/gateway:src/server.ts'?
ERROR: /home/flo/.cache/bazel/_bazel_flo/0eadfacb2a20f703f8711dd83de17c79/external/npm/BUILD.bazel:9:1: Label '@npm//:node_modules/@learning-bazel-monorepo/gateway/tsconfig.json' is invalid because '@npm//node_modules/@learning-bazel-monorepo/gateway' is a subpackage; perhaps you meant to put the colon here: '@npm//node_modules/@learning-bazel-monorepo/gateway:tsconfig.json'?
ERROR: /home/flo/.cache/bazel/_bazel_flo/0eadfacb2a20f703f8711dd83de17c79/external/npm/BUILD.bazel:9:1: Label '@npm//:node_modules/@learning-bazel-monorepo/gateway/tsconfig.tsbuildinfo' is invalid because '@npm//node_modules/@learning-bazel-monorepo/gateway' is a subpackage; perhaps you meant to put the colon here: '@npm//node_modules/@learning-bazel-monorepo/gateway:tsconfig.tsbuildinfo'?
ERROR: /home/flo/.cache/bazel/_bazel_flo/0eadfacb2a20f703f8711dd83de17c79/external/npm/BUILD.bazel:9:1: Label '@npm//:node_modules/@learning-bazel-monorepo/gateway/yarn-error.log' is invalid because '@npm//node_modules/@learning-bazel-monorepo/gateway' is a subpackage; perhaps you meant to put the colon here: '@npm//node_modules/@learning-bazel-monorepo/gateway:yarn-error.log'?
ERROR: /home/flo/.cache/bazel/_bazel_flo/0eadfacb2a20f703f8711dd83de17c79/external/npm/express/BUILD.bazel:167:1: Target '@npm//:node_modules/express/History.md' contains an error and its package is in error and referenced by '@npm//express:express__files'
ERROR: /home/flo/.cache/bazel/_bazel_flo/0eadfacb2a20f703f8711dd83de17c79/external/npm/express/BUILD.bazel:167:1: Target '@npm//:node_modules/express/LICENSE' contains an error and its package is in error and referenced by '@npm//express:express__files'
ERROR: /home/flo/.cache/bazel/_bazel_flo/0eadfacb2a20f703f8711dd83de17c79/external/npm/express/BUILD.bazel:167:1: Target '@npm//:node_modules/express/Readme.md' contains an error and its package is in error and referenced by '@npm//express:express__files'
ERROR: /home/flo/.cache/bazel/_bazel_flo/0eadfacb2a20f703f8711dd83de17c79/external/npm/express/BUILD.bazel:167:1: Target '@npm//:node_modules/express/index.js' contains an error and its package is in error and referenced by '@npm//express:express__files'
ERROR: /home/flo/.cache/bazel/_bazel_flo/0eadfacb2a20f703f8711dd83de17c79/external/npm/express/BUILD.bazel:167:1: Target '@npm//:node_modules/express/lib/application.js' contains an error and its package is in error and referenced by '@npm//express:express__files'
ERROR: /home/flo/.cache/bazel/_bazel_flo/0eadfacb2a20f703f8711dd83de17c79/external/npm/express/BUILD.bazel:167:1: Target '@npm//:node_modules/express/lib/express.js' contains an error and its package is in error and referenced by '@npm//express:express__files'
ERROR: /home/flo/.cache/bazel/_bazel_flo/0eadfacb2a20f703f8711dd83de17c79/external/npm/express/BUILD.bazel:167:1: Target '@npm//:node_modules/express/lib/middleware/init.js' contains an error and its package is in error and referenced by '@npm//express:express__files'
ERROR: /home/flo/.cache/bazel/_bazel_flo/0eadfacb2a20f703f8711dd83de17c79/external/npm/express/BUILD.bazel:167:1: Target '@npm//:node_modules/express/lib/middleware/query.js' contains an error and its package is in error and referenced by '@npm//express:express__files'
ERROR: /home/flo/.cache/bazel/_bazel_flo/0eadfacb2a20f703f8711dd83de17c79/external/npm/express/BUILD.bazel:167:1: Target '@npm//:node_modules/express/lib/request.js' contains an error and its package is in error and referenced by '@npm//express:express__files'
ERROR: /home/flo/.cache/bazel/_bazel_flo/0eadfacb2a20f703f8711dd83de17c79/external/npm/express/BUILD.bazel:167:1: Target '@npm//:node_modules/express/lib/response.js' contains an error and its package is in error and referenced by '@npm//express:express__files'
ERROR: /home/flo/.cache/bazel/_bazel_flo/0eadfacb2a20f703f8711dd83de17c79/external/npm/express/BUILD.bazel:167:1: Target '@npm//:node_modules/express/lib/router/index.js' contains an error and its package is in error and referenced by '@npm//express:express__files'
ERROR: /home/flo/.cache/bazel/_bazel_flo/0eadfacb2a20f703f8711dd83de17c79/external/npm/express/BUILD.bazel:167:1: Target '@npm//:node_modules/express/lib/router/layer.js' contains an error and its package is in error and referenced by '@npm//express:express__files'
ERROR: /home/flo/.cache/bazel/_bazel_flo/0eadfacb2a20f703f8711dd83de17c79/external/npm/express/BUILD.bazel:167:1: Target '@npm//:node_modules/express/lib/router/route.js' contains an error and its package is in error and referenced by '@npm//express:express__files'
ERROR: /home/flo/.cache/bazel/_bazel_flo/0eadfacb2a20f703f8711dd83de17c79/external/npm/express/BUILD.bazel:167:1: Target '@npm//:node_modules/express/lib/utils.js' contains an error and its package is in error and referenced by '@npm//express:express__files'
ERROR: /home/flo/.cache/bazel/_bazel_flo/0eadfacb2a20f703f8711dd83de17c79/external/npm/express/BUILD.bazel:167:1: Target '@npm//:node_modules/express/lib/view.js' contains an error and its package is in error and referenced by '@npm//express:express__files'
ERROR: /home/flo/.cache/bazel/_bazel_flo/0eadfacb2a20f703f8711dd83de17c79/external/npm/express/BUILD.bazel:167:1: Target '@npm//:node_modules/express/package.json' contains an error and its package is in error and referenced by '@npm//express:express__files'
ERROR: /home/flo/Desktop/learning-bazel-monorepo/services/gateway/BUILD.bazel:14:1: Target '@npm//:node_modules' contains an error and its package is in error and referenced by '//services/gateway:gateway_image.binary'
ERROR: Analysis of target '//services/gateway:gateway' failed; build aborted: Analysis failed
INFO: Elapsed time: 0.105s
INFO: 0 processes.
FAILED: Build did NOT complete successfully (1 packages loaded, 0 targets configured)
Fetching @nodejs_image_base; Restarting.
如果您想要/需要查看文件结构,可以在此处执行此操作:https://github.com/flolude/learning-bazel-monorepo .
最佳答案
您无法确定目标,因为您的两条规则都被命名为“网关”。将nodejs_image规则的名称更改为“foo”,然后尝试bazel build//...
尝试在构建文件中使用此导入:
load("@npm_bazel_typescript//:index.bzl", "ts_library")
,取自rules_nodejs示例存储库:
https://github.com/bazelbuild/rules_nodejs/blob/master/examples/app/BUILD.bazel
此外,请确保您的 package.json 具有以下开发依赖项。
"devDependencies": {
"@bazel/bazel": "latest",
"@bazel/ibazel": "latest",
"@bazel/buildifier": "latest",
"@bazel/typescript": "latest",
"typescript": "~3.4.0"
},
此外,在您的 WORKSPACE 文件中,尝试复制示例的 WORKSPACE 文件:
http_archive(
name = "build_bazel_rules_nodejs",
sha256 = "16fc00ab0d1e538e88f084272316c0693a2e9007d64f45529b82f6230aedb073",
urls = ["https://github.com/bazelbuild/rules_nodejs/releases/download/0.42.2/rules_nodejs-0.42.2.tar.gz"],
)
load("@build_bazel_rules_nodejs//:index.bzl", "yarn_install")
yarn_install(
name = "npm",
package_json = "//:package.json",
yarn_lock = "//:yarn.lock",
)
load("@npm//:install_bazel_dependencies.bzl", "install_bazel_dependencies")
install_bazel_dependencies()
load("@npm_bazel_typescript//:index.bzl", "ts_setup_workspace")
ts_setup_workspace()
https://github.com/bazelbuild/rules_nodejs/blob/master/examples/app/WORKSPACE
更新:
查看我构建 ts_library 和 nodejs_image 的最小存储库: https://github.com/mancini0/minimal_bazel_docker_nodejs
请注意,工作区文件的yarn_install规则应指向package.json、yarn.lock等...如果它们位于项目的根目录,则为“:package.json”;如果它们位于mysubproject中,则为“//mysubproject:package.json”/“//mysubproject:yarn.lock”。
关于node.js - 使用 Bazel 构建 Node.Js Docker 镜像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59119010/
当我调用 Bazel 命令并出现分析错误时,它只显示其中之一。例如: ERROR: /Users/oliver/src/github.com/monzo/wearedev/service.transa
我们正在生成许多 Go 源文件作为我们构建的一部分。以前我们使用了 genrule ( example here ) 导致生成的文件存储在 bazel-genfiles/ . 我们最近切换到使用自定义
有没有办法在 Bazel 中指定可选依赖项? 我想制定一个规则来在某种程度上反射(reflect) Kitware 的 ExternalData , 但我想看看我是否可以启用开发人员在树中编辑文件的工
我想知道特定于平台的默认 Bazel 构建标志是否可能。 例如,我们想要使用 --workspace_status_command,但这必须是 Linux 上的 shell 脚本,并且必须指向 Win
具体来说,我想从 Mac 主机对 Windows 工作人员运行测试。 评论 running bazel remote executor test on separate machines表明这是 Ba
我想知道特定于平台的默认 Bazel 构建标志是否可能。 例如,我们想要使用 --workspace_status_command,但这必须是 Linux 上的 shell 脚本,并且必须指向 Win
有没有办法指示 bazel 列出它找到的所有目标而不构建或测试它们? 最佳答案 bazel query 可用于发现 bazel 工作区内的目标(无需构建/测试它们) 例如; 查找给定包中的所有标签:
(来自https://groups.google.com/d/msg/bazel-discuss/XrtKLhH1bgI/B9xZn_aVAAAJ) 在我们使用 Bazel 构建的项目中,我使用了远程
在 bazel 构建期间,有一堆文本飞过,暂时显示然后从屏幕上删除。这发生在整个构建过程中。我尝试了几种重定向技术,将 stderr 重定向到标准输出但无济于事。我还尝试了 bazel 的详细标志。
我是 Bazel 的新手,并在 CentOS 7 上安装了 Bazel。我使用版本为“0.14.0- (@non-git)”的“yum install bazel”安装了它 启动 bazel 时,它总
我有几段 C++ 代码(模板、宏等),它们在使用某些方式时无法编译。手动编写一段代码来完成不应该编译的事情并验证它是否编译是很容易的,但这不是自动化的。看起来 Bazel 应该能够编译一段代码并自动验
鉴于使用 bazel 构建的相当大的存储库和多种语言的大量第三方依赖项(包括重型 docker 容器),我遇到以下问题: 运行 Bazel 查询会触发下载许多这些依赖项,从而导致查询性能下降。因此,问
假设我有一个 Bazel 宏,它使用生成器规则在给定输入文件的情况下生成输出文件: def my_generator( name, input_file,
在我的代码库中,在多个目标(cc_binary、cc_library 等)中包含相同的源文件通常是错误的。我想检测这个。 我可以 bazel query labels(srcs, //target:n
您好,我想读取 .bzl 文件中本地文件的内容。 print(onefile.basename) #content = ctx.read #content=ctx.file.o
我确信这已记录在某处,但无法在任何地方找到答案。 如果我有: ```bazel_rule( name = "foo", srcs = ["foo.cpp"], attr_bar
我正在开始使用 Bazel,如果有一种简单的方法可以集成 buildifier,我就在运行每次运行 bazel build 时? 最佳答案 您可以将此实现为测试规则,其中 ctx.file_actio
bazel test命令对标记为 size = small 的测试使用默认超时 75 秒在我的设置中(版本 0.12.0)(而 documentation 提到这是 60 秒) 有没有办法在 baze
$ python gencpp.py 此命令生成一个 cpp 文件 foo.cpp在工作目录中。 我想在 bazel 中运行此命令建之前可以包含foo.cpp在 cc_binary的 srcs属性。
一遍又一遍地阅读 Bazel 文档,以至于没有什么新鲜的地方,但我似乎无法掌握如何为 native 以外的变体设置配置和变体,例如--cpu 和--compilation_mode。 为了解释我对配置
我是一名优秀的程序员,十分优秀!