jon*_*ckt 0 java spring buildpack spring-boot paketo
拥有一个 Spring Boot 应用程序,我尝试使用spring-boot-maven-plugin目标来构建它mvn spring-boot:build-image。但是构建无法下载bellsoft-jre11.0.9.1+1-linux-amd64.tar.gzfrom github.com,因为我无法从构建管道访问它:
...
Paketo BellSoft Liberica Buildpack 5.2.1
https://github.com/paketo-buildpacks/bellsoft-liberica
Build Configuration:
$BP_JVM_VERSION 11.0.9 the Java version
Launch Configuration:
$BPL_JVM_HEAD_ROOM 0 the headroom in memory calculation
$BPL_JVM_LOADED_CLASS_COUNT 35% of classes the number of loaded classes in memory calculation
$BPL_JVM_THREAD_COUNT 250 the number of threads in memory calculation
$JAVA_TOOL_OPTIONS the JVM launch flags
BellSoft Liberica JDK 11.0.9: Contributing to layer
Downloading from https://github.com/bell-sw/Liberica/releases/download/11.0.9.1+1/bellsoft-jdk11.0.9.1+1-linux-amd64.tar.gz
unable to invoke layer creator
unable to get dependency jdk
unable to download https://github.com/bell-sw/Liberica/releases/download/11.0.9.1+1/bellsoft-jdk11.0.9.1+1-linux-amd64.tar.gz
unable to request https://github.com/bell-sw/Liberica/releases/download/11.0.9.1+1/bellsoft-jdk11.0.9.1+1-linux-amd64.tar.gz
ERROR: failed to build: exit status 1
Run Code Online (Sandbox Code Playgroud)
有没有办法可以将其下载bellsoft-jdk11.0.9.1+1-linux-amd64.tar.gz到我的构建管道可访问的位置并配置 bellsoft-liberica buildpack 以使用它?
根据文档:
Paketo Buildpacks 可以从 Internet 下载依赖项。例如,Java Buildpack 默认会从 Liberica github 版本下载 BellSoft Liberica JRE。如果无法从构建环境访问依赖项 URI,则可以使用绑定将新的 URI 映射到给定的依赖项。
使用 spring-boot-maven-plugin(或 Gradle 插件)配置绑定需要 Spring Boot 2.5+。如果您使用的是旧版本,则需要升级或切换到打包 CLI。
===使用带有绑定的 pack CLI 来配置不同的 JDK 下载 uri ===
包文档告诉我们绑定目录的一般布局(/platform/bindings稍后在包构建容器中创建):
/chooseYourBindingsName
??? key-name-of-our-buildpacks-binding-configuration
??? type-name-of-our-buildpacks-binding-configuration
Run Code Online (Sandbox Code Playgroud)
1. 创建绑定目录
因此,让我们尝试创建一个完全运行的示例!为了将绑定配置移交给packCLI,我们需要先创建一个目录:
mkdir bellsoft-jdk-config && cd bellsoft-jdk-config
Run Code Online (Sandbox Code Playgroud)
2. 创建文件类型,包含绑定密钥
现在我们需要type在此目录中创建一个文件,其中包含bellsoft-liberica 绑定类型dependency-mapping的绑定密钥:
echo "dependency-mapping" >> type
Run Code Online (Sandbox Code Playgroud)
type包含字符串的目录中应该存在一个新文件dependency-mapping。
3.从buildpack.toml中选择JDK版本
由于我们要更改 JDK 的 bellsoft-liberica 下载 uri,因此我们需要决定我们要使用的 JDK 版本。bellsoft-liberica buildpack 的buildpack.toml概述了 buildpack 中可用的 JRE/JDK 版本。对于这里的这个例子,我使用了最新的 JDK 版本11,它的配置buildpack.toml如下:
...
[[metadata.dependencies]]
id = "jdk"
name = "BellSoft Liberica JDK"
version = "11.0.9"
uri = "https://github.com/bell-sw/Liberica/releases/download/11.0.9.1+1/bellsoft-jdk11.0.9.1+1-linux-amd64.tar.gz"
sha256 = "786c48fa6429d6a3f0afb189a65f0a43772e42afbab836852b9a1fdfdb8fc502"
stacks = [ "io.buildpacks.stacks.bionic", "org.cloudfoundry.stacks.cflinuxfs3" ]
...
Run Code Online (Sandbox Code Playgroud)
4.下载JDK
确定版本后,我们需要从uri字段内提供的位置下载 JDK到我们稍后在构建环境中可以访问的位置(因为我们无法访问 github.com)。假设我们已经下载了 JDK 并且可以在http://your-accessible-uri-to/bellsoft-jdk11.0.9.1+1-linux-amd64.tar.gz.
5. 创建名为 sha256 的文件,其中包含 JDK uri
现在我们应该创建另一个根据准确命名的文件sha256的摘要值中的[[metadata.dependencies]],我们选择的是里面的JDK版本部分buildpack.toml。此文件必须包含我们下载的 JDK 的 uri:
echo "http://your-accessible-uri-to/bellsoft-jdk11.0.9.1+1-linux-amd64.tar.gz" >> 786c48fa6429d6a3f0afb189a65f0a43772e42afbab836852b9a1fdfdb8fc502
Run Code Online (Sandbox Code Playgroud)
最后,我们的目录bellsoft-jdk-config应该符合pack CLI 绑定目录 docs并且看起来像这样:
/bellsoft-jdk-config
??? 786c48fa6429d6a3f0afb189a65f0a43772e42afbab836852b9a1fdfdb8fc502
??? type
Run Code Online (Sandbox Code Playgroud)
6. 使用 --volume 执行 pack CLI 进行绑定 & BP_JVM_VERSION
最后,我们可以发出packCLI 命令。确保您的系统上安装了pack CLI。还要确保使用--env BP_JVM_VERSION=exactJDKversionNumberHere 环境变量配置提供准确的 JDK 版本号,它与您下载的 JDK 版本和buildpack.toml 中的部分相匹配:
pack build your-application-name-here \
--path . \
--volume $(pwd)/bellsoft-jdk-config:/platform/bindings/bellsoft-jdk-config \
--env BP_JVM_VERSION=11.0.9 \
--builder paketobuildpacks/builder:base
Run Code Online (Sandbox Code Playgroud)
现在 bellsoft-liberica buildpack 将从以下位置下载 JDK tar.gz http://your-accessible-uri-to/bellsoft-jdk11.0.9.1+1-linux-amd64.tar.gz:
...
Paketo BellSoft Liberica Buildpack 5.2.1
https://github.com/paketo-buildpacks/bellsoft-liberica
Build Configuration:
$BP_JVM_VERSION 11.0.9 the Java version
Launch Configuration:
$BPL_JVM_HEAD_ROOM 0 the headroom in memory calculation
$BPL_JVM_LOADED_CLASS_COUNT 35% of classes the number of loaded classes in memory calculation
$BPL_JVM_THREAD_COUNT 250 the number of threads in memory calculation
$JAVA_TOOL_OPTIONS the JVM launch flags
BellSoft Liberica JDK 11.0.9: Contributing to layer
Downloading from http://your-accessible-uri-to/bellsoft-jdk11.0.9.1+1-linux-amd64.tar.gz
...
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1680 次 |
| 最近记录: |