生成 Spring Webflux 优化的 OCI 图像的任何构建包吗?

Are the any buildpacks that generate Spring Webflux optiimized OCI Images?

我找不到适合 Spring Webflux 应用程序的构建包生成器。例如,Paketo 几乎没有定制空间,而且开箱即用包括典型 Webflux 应用程序不需要的构建包(例如 apache-tomcat)。是否有任何为 webflux/jvm-reactive 应用程序量身定制的构建包?

看起来你不需要在这里为 Spring Webflux 做任何具体的事情,Java 相关的 CNB 会做正确的事情。

我使用 Spring Initializer(刚刚添加了 Webflux 启动器)和 运行 pack build 创建了一个示例应用程序(如果你 运行 ./mvnw spring-boot:build-image,你应该得到非常相似的输出)。

这给了我以下输出:

===> DETECTING
[detector] 6 of 17 buildpacks participating
[detector] paketo-buildpacks/bellsoft-liberica 3.2.0
[detector] paketo-buildpacks/maven             3.1.0
[detector] paketo-buildpacks/executable-jar    3.1.0
[detector] paketo-buildpacks/apache-tomcat     2.2.0
[detector] paketo-buildpacks/dist-zip          2.2.0
[detector] paketo-buildpacks/spring-boot       3.2.0

乍一看,这似乎很奇怪。为什么 Tomcat 在那里?查看 Tomcat CNB,这是意料之中的。 Tomcat CNB 总是去 return a successful detection

请注意 pass 是如何硬编码为 true 的。

result := libcnb.DetectResult{
    Pass: true,
    Plans: []libcnb.BuildPlan{
        {
            Requires: []libcnb.BuildPlanRequire{
                {Name: "jre", Metadata: map[string]interface{}{"launch": true}},
                {Name: "jvm-application"},
            },
        },
    },
}

之所以可以,是因为在构建时,Tomcat CNB 将 immediately exit (no-op) if there is no WEB-INF directory,而对于 Spring WebFlux 应用程序,则不会。

file := filepath.Join(context.Application.Path, "WEB-INF")
if _, err := os.Stat(file); err != nil && !os.IsNotExist(err) {
    return libcnb.BuildResult{}, fmt.Errorf("unable to stat file %s\n%w", file, err)
} else if os.IsNotExist(err) {
    return libcnb.BuildResult{}, nil
}

您可以通过查看 pack build 的完整输出并查找 Paketo Apache Tomcat Buildpack x.x.x 的存在(其中 x.x.x 是版本号)来确认这一点。如果 Tomcat CNB 运行正在执行任何工作,you'd see that line output.

paketo-buildpack/dist-zip CNB 的工作方式相同,它只是在寻找 <APPLICATION_ROOT>/*/bin/* 存在。

总而言之,生成的图像应该特定于您的应用程序,不应包含不必要的内容。如果您正在 运行ning Spring WebFlux,那么您不应该将 Tomcat 安装到您的映像中。此外,您还可以获得使用 Cloud Native 构建包提供的所有优化。