Cloud Native Buildpacks

Dockerfiles 只是构建 docker 镜像的一种方式。另一种方式是直接从 Maven 或 Gradle 插件构建 docker 镜像,可以使用 buildpack。如果您曾经使用过 Cloud Foundry 或 Heroku 等应用程序平台,那么您可能已经使用过 buildpack。Buildpack 是平台的一部分,它获取您的应用程序并将其转换为平台实际可以运行的内容。例如,Cloud Foundry 的 Java buildpack 会注意到您正在推送 .jar 文件,并自动添加相关 JRE。

Dockerfiles are just one way to build docker images. Another way to build docker images is directly from your Maven or Gradle plugin, using buildpacks. If you’ve ever used an application platform such as Cloud Foundry or Heroku then you’ve probably used a buildpack. Buildpacks are the part of the platform that takes your application and converts it into something that the platform can actually run. For example, Cloud Foundry’s Java buildpack will notice that you’re pushing a .jar file and automatically add a relevant JRE.

通过云原生构建包,你可以创建与 Docker 兼容并在任何地方运行的映像。Spring Boot 为 Maven 和 Gradle 直接提供构建包支持。这意味着你仅需键入一个命令,即可快速将合理映像放入本地运行的 Docker 守护程序中。

With Cloud Native Buildpacks, you can create Docker compatible images that you can run anywhere. Spring Boot includes buildpack support directly for both Maven and Gradle. This means you can just type a single command and quickly get a sensible image into your locally running Docker daemon.

请参阅各个插件文档,了解如何将构建包与 MavenGradle 一起使用。

See the individual plugin documentation on how to use buildpacks with Maven and Gradle.

Paketo Spring Boot buildpack 支持 layers.idx 文件,因此应用于该文件的任何自定义都将反映在构建包创建的映像中。

The Paketo Spring Boot buildpack supports the layers.idx file, so any customization that is applied to it will be reflected in the image created by the buildpack.

为了实现可重现的构建和容器映像缓存,构建包可以操纵应用程序资源元数据(例如文件“最近修改”信息)。你应当确保你的应用程序在运行时不依赖该元数据。Spring Boot 在提供静态资源时可使用该信息,但这可以通过 configprop:spring.web.resources.cache.use-last-modified[] 禁用。

In order to achieve reproducible builds and container image caching, Buildpacks can manipulate the application resources metadata (such as the file "last modified" information). You should ensure that your application does not rely on that metadata at runtime. Spring Boot can use that information when serving static resources, but this can be disabled with configprop:spring.web.resources.cache.use-last-modified[].