[英]Paketo BuildPacks Java JSON Log for Spring Boot Application
[英]Cloud Native Buildpacks/Paketo with Java/Spring Boot: How to configure different JDK download uri (e.g. no access to github.com)
擁有一個 Spring 引導應用程序,我嘗試使用spring-boot-maven-plugin
目標mvn spring-boot:build-image
它。 但是構建無法從 github.com 下載bellsoft-jre11.0.9.1+1-linux-amd64.tar.gz
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
有沒有辦法可以將bellsoft-jdk11.0.9.1+1-linux-amd64.tar.gz
下載到我的構建管道可訪問的位置並配置 bellsoft-liberica buildpack 以使用它?
根據文檔:
Paketo Buildpacks 可以從 Internet 下載依賴項。 例如,Java Buildpack 默認會從 Liberica github 版本下載 BellSoft Liberica JRE。 如果無法從構建環境訪問依賴項 URI,則可以使用綁定來 map 給給定依賴項的新 URI。
使用 spring-boot-maven-plugin(或 Gradle 插件)配置綁定需要 Spring Boot 2.5+。 如果您使用的是舊版本,則需要升級或切換到pack CLI 。
===使用帶有綁定的 pack CLI 來配置不同的 JDK 下載 uri ===
包文檔告訴我們綁定目錄的一般布局( /platform/bindings
稍后在包構建容器中創建):
/chooseYourBindingsName
├── key-name-of-our-buildpacks-binding-configuration
└── type-name-of-our-buildpacks-binding-configuration
1.創建綁定目錄
因此,讓我們嘗試創建一個完全運行的示例! 為了將綁定配置移交給pack
CLI,我們需要首先創建一個目錄:
mkdir bellsoft-jdk-config && cd bellsoft-jdk-config
2.創建文件類型,包含綁定鍵
現在我們需要在這個目錄中創建一個名為type
的文件,其中包含bellsoft-liberica 綁定類型dependency-mapping
的綁定鍵:
echo "dependency-mapping" >> type
一個新的文件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" ]
...
4.下載JDK
確定版本后,我們需要將 JDK 從uri
字段中提供的位置下載到我們稍后在構建環境中可以訪問的位置(因為我們無權訪問 github.com)。 假設,我們在http://your-accessible-uri-to/bellsoft-jdk11.0.9.1+1-linux-amd64.tar.gz
下載了 JDK。
5. 創建名為 sha256 的文件,包含 JDK uri
現在我們應該根據我們在buildpack.toml中選擇的 JDK 版本的[[metadata.dependencies]]
部分的sha256
摘要值創建另一個完全命名的文件。 此文件必須包含我們下載的 JDK 的 uri:
echo "http://your-accessible-uri-to/bellsoft-jdk11.0.9.1+1-linux-amd64.tar.gz" >> 786c48fa6429d6a3f0afb189a65f0a43772e42afbab836852b9a1fdfdb8fc502
最后,我們的目錄bellsoft-jdk-config
應該符合pack CLI bindings 目錄文檔,並且看起來像這樣:
/bellsoft-jdk-config
├── 786c48fa6429d6a3f0afb189a65f0a43772e42afbab836852b9a1fdfdb8fc502
└── type
6. 使用--volume for binding & BP_JVM_VERSION 執行pack CLI
最后,我們可以發出我們的pack
CLI 命令。 確保您的系統上安裝了 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
現在 bellsoft-liberica buildpack 將從http://your-accessible-uri-to/bellsoft-jdk11.0.9.1+1-linux-amd64.tar.gz
下載 JDK 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
...
@jonashackt我有一個解決這個問題的方法並且它有效
我創建綁定
/bindings/bellsoft-jdk-config
├── 786c48fa6429d6a3f0afb189a65f0a43772e42afbab836852b9a1fdfdb8fc502
├── a3092627b082cb3cdbbe4b255d35687126aa604e6b613dcda33be9f7e1277162
├── be27df8838a6d069a2212de5f46da4e39f33f087f2e77c8a725d0f7ec8b5273e
├── d9ff2d84528a2154ff669b85e6dbdee7f244194dcc64e0a8a1bedc470b3bcf56
└── type
然后創建了一個 Dockerfile 復制這些綁定並在前一個的基礎上構建一個新平台
FROM paketobuildpacks/builder:0.0.464-base-platform-api-0.3
COPY bindings /platform/bindings
CMD ["/bin/bash"]
docker build -t your-repo-url/java-builder-test:1 .
docker push your-repo-url/java-builder-test:1
然后我配置了 spring 插件來使用這個平台
<configuration>
<imageBuilder>your-repo-url/java-builder-test:1</imageBuilder>
<layers>
<enabled>true</enabled>
</layers>
<image>
<name>your-repo-url/${project.artifactId}:${project.version}</name>
</image>
</configuration>
此解決方法有效,但您必須使用正確的目錄權限
您是否嘗試過這樣的解決方案?
@jonashackt:- 我嘗試更改 JRE。 I want to use open JRE 15 as I face fonts issue in the default one - https://github.com/AdoptOpenJDK/openjdk15-binaries/releases/download/jdk15u-2021-01-22-02-31/OpenJDK15U-jre_x64_linux_hotspot_2021 -01-22-02-31.tar.gz
上面的uri在sha文件中
執行了以下命令
c:\Mine>pack build --clear-cache springbootapp-image --path myspringboot-app --volume bellsoft-jdk-config:/platform/bindings/bellsoft-jdk-config --env BP_JVM_VERSION=15 --builder paketobuildpacks /建設者:基地
它如何仍然下載 BellSoft Liberica JRE 15.0.2..
這是否意味着我無法覆蓋 Open JRE? 請分享您的想法。
這對我有幫助。 你可以試一試看看。 我將 pom.xml 中的 java 版本更改為 17
<properties>
<java.version>17</java.version>
<spring-cloud.version>2020.0.2</spring-cloud.version>
</properties>
我將 pom.xml 文件中的 java 版本更改為 17 並且它起作用了!
在 pom.xml 中更改 Java 版本,它將起作用。 我已將其更改為 java 17。它對我有用。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.