问题描述
拥有一个 Spring Boot 应用程序,我尝试使用 spring-boot-maven-plugin
目标 mvn spring-boot:build-image
构建它.但是构建无法从 github.com
下载 bellsoft-jre11.0.9.1+1-linux-amd64.tar.gz
,因为我无法访问它来自我的构建管道:
:...Paketo BellSoft Liberica Buildpack 5.2.1https://github.com/paketo-buildpacks/bellsoft-liberica构建配置:$BP_JVM_VERSION 11.0.9 Java 版本启动配置:$BPL_JVM_HEAD_ROOM 0 内存计算空间$BPL_JVM_LOADED_CLASS_COUNT 35% of classes 内存计算中加载的类数$BPL_JVM_THREAD_COUNT 250 内存计算中的线程数$JAVA_TOOL_OPTIONS JVM 启动标志BellSoft Liberica JDK 11.0.9:对层的贡献从 http://your-accessible-uri-to/bellsoft-jdk11.0.9.1+1-linux-amd64.tar.gz 下载...Having a Spring Boot app I tried to build it using the
spring-boot-maven-plugin
goalmvn spring-boot:build-image
. But the build fails downloading thebellsoft-jre11.0.9.1+1-linux-amd64.tar.gz
fromgithub.com
, since I don't have access to it from my build pipeline:... 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
Is there a way I can download the
bellsoft-jdk11.0.9.1+1-linux-amd64.tar.gz
to a location accessible to my build pipeline and configure the bellsoft-liberica buildpack to use this instead?解决方案Configuring bindings using the spring-boot-maven-plugin (or the Gradle plugin) requires Spring Boot 2.5+. If you are on an older version, you need to upgrade or switch over to pack CLI.
=== Use pack CLI with bindings to configure a different JDK download uri ===
The pack docs tell us about the general layout of a binding directory (
/platform/bindings
is later created inside the pack build container):/chooseYourBindingsName ├── key-name-of-our-buildpacks-binding-configuration └── type-name-of-our-buildpacks-binding-configuration
1. Create bindings directory
So let's try to create a fully running example! In order to hand over the binding configuration to
pack
CLI we need to create a directory first:mkdir bellsoft-jdk-config && cd bellsoft-jdk-config
2. Create file type, containing the binding key
Now we need to create a file called
type
inside this directory containing the binding key for the bellsoft-liberica binding typedependency-mapping
:echo "dependency-mapping" >> type
A new file
type
should be present in the directory containing the stringdependency-mapping
.3. Choose JDK version from buildpack.toml
As we want to change the bellsoft-liberica's download uri of the JDK, we need to decide which JDK version we exaclty want to use. The bellsoft-liberica buildpack's buildpack.toml gives an overview on which JRE/JDK versions are available inside the buildpack. For this example here I used the latest JDK version
11
which is configured inside thebuildpack.toml
like this:... [[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. Download JDK
Having decided on the version, we need to download the JDK from the location provided inside the
uri
field to a location we have access to later inside our build environment (since we don't have access to github.com). Let's assume, we have the JDK downloaded and available athttp://your-accessible-uri-to/bellsoft-jdk11.0.9.1+1-linux-amd64.tar.gz
.5. Create file named as the sha256, containing the JDK uri
Now we should create another file named exactly according to the
sha256
digest value of the[[metadata.dependencies]]
section of the JDK version we chose inside the buildpack.toml. This file must contain the uri of our downloaded JDK:echo "http://your-accessible-uri-to/bellsoft-jdk11.0.9.1+1-linux-amd64.tar.gz" >> 786c48fa6429d6a3f0afb189a65f0a43772e42afbab836852b9a1fdfdb8fc502
In the end our directory
bellsoft-jdk-config
should comply to the pack CLI bindings directory docs and looks somehow like this:/bellsoft-jdk-config ├── 786c48fa6429d6a3f0afb189a65f0a43772e42afbab836852b9a1fdfdb8fc502 └── type
6. Execute pack CLI with --volume for binding & BP_JVM_VERSION
Finally we can issue our
pack
CLI command. Ensure that pack CLI is installed on your system. Be also sure to also provide the exact JDK version number using the--env BP_JVM_VERSION=exactJDKversionNumberHere
environment variable configuration, which matches your downloaded JDK version and the section in the 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
Now the bellsoft-liberica buildpack will download the JDK tar.gz from
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 ...
这篇关于Cloud Native Buildpacks/Paketo with Java/Spring Boot:如何配置不同的 JDK 下载 uri(例如无法访问 github.com)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!