英文:
Bazel docker_image copy extra folder
问题
我目前正在使用bazel来构建我的GoLang应用程序。
container_image(
name = "my-golang-app",
base = "@ubuntu_base//image",
cmd = ["/bin/my-golang-app"],
directory = "/bin/",
files = [":my-golang-app"],
tags = [
"manual",
VERSION,
],
visibility = ["//visibility:public"],
)
除了my-golang-app文件夹之外,在构建这个镜像时,我需要复制另一个名为my-new-folder的文件夹及其内部的所有内容。
在bazel中如何实现这一点?我在bazel文档中找不到解决方案。
dockerfile {
run 'mkdir -p /usr/local/bin'
// 添加以下行
add {
from 'docker/my-new-folder/'
into '/'
}
}
英文:
I am currently using bazel for my GoLang app.
container_image(
name = "my-golang-app",
base = "@ubuntu_base//image",
cmd = ["/bin/my-golang-app"],
directory = "/bin/",
files = [":my-golang-app"],
tags = [
"manual",
VERSION,
],
visibility = ["//visibility:public"],
)
Except my-golang-app folder I need to copy, while building this image, another folder named my-new-folder and everything in it.
How does one do that with bazel? I can't seem to find the solution in the bazel docs.
dockerfile {
run 'mkdir -p /usr/local/bin'
// add the lines below
add {
from 'docker/my-new-folder/'
into '/'
}
答案1
得分: 2
使用pkg_tar
,就像container_image文档中的参考一样。类似这样的代码:
pkg_tar(
name = "my-files",
srcs = glob(["my-new-folder/**"]),
strip_prefix = ".",
)
container_image(
name = "my-golang-app",
files = [":my-golang-app"],
<你已经有的其他内容>,
tars = [":my-files"],
)
pkg_tar
有各种选项来控制文件的存放位置,如果你想要更复杂的安排,我发现通过deps
将多个目录链接在一起的多个pkg_tar
规则是一个有用的模式。
英文:
Use pkg_tar
like the container_image docs reference. Something like this:
pkg_tar(
name = "my-files",
srcs = glob(["my-new-folder/**"]),
strip_prefix = ".",
)
container_image(
name = "my-golang-app",
files = [":my-golang-app"],
<everything else you already have>,
tars = [":my-files"],
)
pkg_tar
has various options to control where your files end up, if you want something beyond just taking an entire directory. For more complicated arrangements, I find multiple pkg_tar
rules for various directories linked together via deps
a helpful pattern.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论