简体   繁体   English

在 Spring Boot Gradle 插件中指定额外的 CA 证书绑定

[英]Specifying additional CA certificate bindings in the Spring Boot Gradle plugin

Is it possible to show some examples of how to specify additional CA certificate bindings in the Spring Boot Gradle plugin?是否可以显示一些示例,说明如何在 Spring Boot Gradle 插件中指定其他 CA 证书绑定?

I have tried the following:我尝试了以下方法:

bootBuildImage {
  bindings = [ "${project.projectDir}/bindings/ca-certificates:/platform/bindings/ca-certificates" ]
}

And

bootBuildImage {
    bindings = ['./bindings/ca-certificates:/platform/bindings/ca-certificates']
}

The error I get is:我得到的错误是:

2023-01-09T16:28:11.799+0800 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] 
Execution failed for task ':ProjectA:bootBuildImage'.
> Docker API call to 'localhost/v1.24/containers/create' failed with status code 500 "Internal Server Error"

If I remove the bindings lines above the error is gone, but I hit another error with the TLS certificate which is expected because I am behind a corporate web proxy that replaces the certificate of the website with its own which is internal to our company.如果我删除上面的绑定行,错误就消失了,但是我遇到了 TLS 证书的另一个错误,这是预期的,因为我在一个公司 web 代理后面,该代理用我们公司内部的自己的网站证书替换了该证书。

The Docker version I uses is 4.8.2 (Docker 20.10.14).我使用的 Docker 版本是 4.8.2 (Docker 20.10.14)。 Spring Boot version is 3.0.1. Spring 引导版本为 3.0.1。 GraalVM plugin is org.graalvm.buildtools.native 0.9.19. GraalVM 插件是 org.graalvm.buildtools.native 0.9.19。

There's no example for setting bindings in the Spring Boot Build Tool docs (at the time I write this), but setting bindings is done in the same place .Spring Boot Build Tool文档中没有设置绑定的示例(在我写这篇文章时),但设置绑定是在同一个地方完成的

In addition, each binding in the list you specify is passed through to Docker, so the actual value should be set just like what you would pass to pack build --volume or docker run -v command.此外,您指定的列表中的每个绑定都会传递给 Docker,因此实际值应该像传递给pack build --volumedocker run -v命令一样设置。 The Paketo Docs provide an example using pack build . Paketo 文档提供了一个使用pack build的示例。

Putting this all together, this should work:把这一切放在一起,这应该有效:

tasks.named("bootBuildImage") {
    bindings = ["${project.projectDir}/ca-certficates/binding:/platform/bindings/ca-certificates"]
}

A few notes:一些注意事项:

  1. This will only add the binding during build time, so the CA certificates are only added during the build of the image.这只会在构建期间添加绑定,因此 CA 证书只会在构建映像期间添加。 You would need to docker run --volume "$(pwd)/ca-certficates/binding:/platform/bindings/ca-certificates"... (or equivalent for your orchestrator of choice) and pass the a CA certificate bindings in at run time as well.您需要docker run --volume "$(pwd)/ca-certficates/binding:/platform/bindings/ca-certificates"... (或等效于您选择的协调器)并传递 CA 证书绑定在运行时也是如此。 Alternatively, you can set BP_EMBED_CERTS=true at build time and it will embed your CA certificates into the container image so you don't need to include them at runtime.或者,您可以在构建时设置BP_EMBED_CERTS=true ,它会将您的 CA 证书嵌入到容器镜像中,因此您无需在运行时包含它们。

  2. If you are specifying a custom buildpack order, you need to ensure the paketo-buildpacks/ca-certificates buildpack runs before your JVM provider buildpack.如果您指定自定义 buildpack 顺序,则需要确保paketo-buildpacks/ca-certificates buildpack 在您的 JVM 提供程序 buildpack 之前运行。 Otherwise, the JVM provider won't have access to your CA certificates and won't be able to load them into the JVM. This often happens if you are using an alternative JVM provider, instead of the Paketo default Bellsoft Liberica.否则,JVM 提供商将无法访问您的 CA 证书,也无法将它们加载到 JVM 中。如果您使用替代的 JVM 提供商而不是 Paketo 默认的 Bellsoft Liberica,通常会发生这种情况。

  3. The above assumes you are not setting SERVICE_BINDING_ROOT at build time.以上假设您没有在构建时设置SERVICE_BINDING_ROOT This environment variable changes the location inside the container where the buildpack can expect your bindings.此环境变量更改容器内 buildpack 可以期待您的绑定的位置。 The default is /platform/bindings/... which is why I'm using that path above.默认是/platform/bindings/...这就是我使用上面那个路径的原因。 The Paketo docs set SERVICE_BINDING_ROOT=/bindings and then use the path /bindings/ca-certificates . Paketo 文档设置SERVICE_BINDING_ROOT=/bindings然后使用路径/bindings/ca-certificates You can do this, there is no real advantage.你可以这样做,没有真正的优势。 One way the path is slightly longer, one way you have to enter an extra env variable.一种方式是路径稍长,另一种方式是您必须输入一个额外的环境变量。 Totally your preference, you just need to make sure you're consistent.完全取决于您的偏好,您只需要确保您的偏好一致。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM