有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

使用Java/Spring引导的云本地BuildPack/Paketo:如何配置不同的JDK下载uri(例如,无法访问github.com)

有了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.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来使用它


共 (4) 个答案

  1. # 1 楼答案

    @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>
    

    此解决方法有效,但您必须使用正确的目录权限

    你试过这样的解决办法吗

  2. # 2 楼答案

    @jonashackt:-我试着改变JRE。我想使用OpenJRE 15,因为我在默认版本中面临字体问题-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文件中

    enter image description here

    执行以下命令

    c:\Mine>;包构建--清除缓存springbootapp映像--路径myspringboot应用--卷bellsoft jdk配置:/platform/bindings/bellsoft jdk配置--环境BP_JVM_VERSION=15--生成器PakeToBuildPack/builder:base

    但它仍然下载BellSoft Liberica JRE 15.0.2

    这是否意味着我无法覆盖以打开JRE?请分享你的想法

  3. # 3 楼答案

    According to the docs

    Paketo Buildpacks may download dependencies from the internet. For example, the Java Buildpack will download the BellSoft Liberica JRE from the Liberica github releases by default. If a dependency URI is inaccessible from the build environment, a binding can be used to map a new URI to a given dependency.

    使用SpringBootMaven插件(或Gradle插件)配置绑定需要SpringBoot2.5+。如果您使用的是旧版本,则需要升级或切换到pack CLI

    ==使用带有绑定的pack CLI来配置不同的JDK下载uri==

    The pack docs告诉我们绑定目录的总体布局(/platform/bindings稍后在包构建容器中创建):

    /chooseYourBindingsName
    ├── key-name-of-our-buildpacks-binding-configuration
    └── type-name-of-our-buildpacks-binding-configuration
    

    1。创建绑定目录

    因此,让我们尝试创建一个完全运行的示例!为了将绑定配置移交给packCLI,我们需要先创建一个目录:

    mkdir bellsoft-jdk-config && cd bellsoft-jdk-config
    

    2。创建包含绑定密钥的文件类型

    现在我们需要在这个目录中创建一个名为type的文件,其中包含the bellsoft-liberica binding type ^{}的绑定键:

    echo "dependency-mapping" >> type
    

    包含字符串dependency-mapping的目录中应存在一个新文件type

    3。从buildpack中选择JDK版本。汤姆

    当我们想要更改bellsoft liberica的JDK下载uri时,我们需要决定我们确实想要使用哪个JDK版本bellsoft liberica构建包的buildpack.toml概述了构建包中提供的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的权限)。让我们假设,我们已经下载了JDK,并且可以在http://your-accessible-uri-to/bellsoft-jdk11.0.9.1+1-linux-amd64.tar.gz上找到它

    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应该符合the pack CLI bindings directory docs的要求,并且看起来像这样:

    /bellsoft-jdk-config
    ├── 786c48fa6429d6a3f0afb189a65f0a43772e42afbab836852b9a1fdfdb8fc502
    └── type
    

    6。使用--volume for binding执行pack CLI&;BP_JVM_版本

    最后,我们可以发出packCLI命令。确保pack CLI is installed on your system。还要确保使用--env BP_JVM_VERSION=exactJDKversionNumberHere{a9}提供确切的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构建包将下载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 
    ...
    
  4. # 4 楼答案

    这对我有帮助。你可以试试看。 我在pom中更改了java版本。xml到17

    <properties>
            <java.version>17</java.version>
            <spring-cloud.version>2020.0.2</spring-cloud.version>
        </properties>