[spring-projects/spring-boot]当位于防火墙后面时,使用 Spring Boot 2.4.1 构建 docker 映像失败,并出现“Missing 'io.buildpacks.stack.id' stack label”

2024-05-14 190 views
4

我正在尝试./mvnw -DskipTests spring-boot:build-image在 RHEL7 上使用 spring boot 2.4.1 和 java 11(openjdk 版本“11.0.9”2020-10-20 LTS)构建 docker 映像。

我在严格防火墙后面的主机上执行此操作,因此我必须从私人存储库中获取构建和运行映像。我已配置 spring-boot-maven-plugin 来使用此存储库:

<plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
    <configuration>
        <docker>
            <builderRegistry>
                <username>my-username</username>
                <password>xxx</password>
                <url>https://my-mirror.com</url>
                <email>kaj.hejer@usit.uio.no</email>
            </builderRegistry>
        </docker>

        <image>
            <builder>my-mirror.com/library/docker.io-paketobuildpacks-builder:base</builder>
            <runImage>my-mirror.com/library/docker.io-paketobuildpacks-run:base</runImage>
            <name>my-mirror.com/my-group/my-app:latest</name>
            <verboseLogging>true</verboseLogging>
        </image>
    </configuration>
</plugin>

构建失败

[INFO]  > Pulling builder image 'my-mirror.com/library/docker.io-paketobuildpacks-builder:base' 100%
[INFO]  > Pulled builder image 'my-mirror.com/library/docker.io-paketobuildpacks-builder@sha256:cf90221a33966e42f8b1960123dea4406c65fc6a410142ded573ed850ccc313b'
[INFO]  > Pulling run image 'my-mirror.com/library/docker.io-paketobuildpacks-run:base' 100%
[INFO]  > Pulled run image 'my-mirror.com/library/docker.io-paketobuildpacks-run@sha256:56fb7587103da155db6d4f9434fd7e2f9e45d7540a062847fd84e9132a28101b'
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  6.090 s
[INFO] Finished at: 2020-12-17T08:36:48+01:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:2.4.1:build-image (default-cli) on project my-app: Execution default-cli of goal org.springframework.boot:spring-boot-maven-plugin:2.4.1:build-image failed: Missing 'io.buildpacks.stack.id' stack label -> [Help 1]
[ERROR] 

sudo journalctl -f运行 mvnw 命令时不要列出任何内容。

当我尝试以相同的方式构建 docker 映像,但在我的 mac 上没有 spring-boot-maven-plugin 的配置块(不在防火墙后面)时,它工作得很好。

我在https://stackoverflow.com/questions/65336624/building-docker-image-with-spring-boot-2-4-1-failes-with-missing-io-buildpacks上提出了有关此问题的问题,并找到了一个在https://stackoverflow.com/questions/65344886/unable-to-build-image-using-gradle-bootbuildimage-in-offline-environment上使用 gradle 的类似问题。

回答

2

看起来您的私人存储库中的图像已丢失其io.buildpacks.stack.id 标签。您可以使用 检查它是否存在docker inspect。您能否仔细检查一下您的私有存储库中的图像是否具有与公开可用的图像相同的元数据?

4

@wilkinsona 感谢您的回复!似乎存在“io.buildpacks.stack.id”:

$ docker inspect myrepo.com/library/docker.io-paketobuildpacks-builder:base | grep io.buildpacks.stack.id
                "io.buildpacks.stack.id": "io.buildpacks.stacks.bionic",

docker inspect对我的私人仓库中的镜像与 dockerhub 中的镜像进行了比较。存在一些差异,但我不确定它们是否相关。我在https://www.dropbox.com/s/ri46btqyn25ws8j/diff.txt?dl=0上放置了一个带有差异的文本文件。

0

@scottfrederick 感谢您的回复!builder据我所知,这是复制到我们的私人存储库中的图像。我们有一个从 dockerhub 同步的镜像列表。

7

谢谢,@kajh。也可能是运行映像缺少堆栈 ID。您能仔细检查一下它的元数据吗?如果这看起来是正确的,失败的堆栈跟踪(在使用 -X 运行 Maven 时可用)可能会有所帮助。

9

@wilkinsona 谢谢!我已经比较了运行图像,并且可以在https://www.dropbox.com/s/fwv65ovpho0mfup/diff-run.txt?dl=0上找到差异。两个图像都不包含任何标签。这是来自我的防火墙之外的 Mac:

$ docker pull docker.io/paketobuildpacks/run:base 
base: Pulling from paketobuildpacks/run
Digest: sha256:15d03f2ceb34ddedf8be3654d2e1e8ff2f60aa43e1b4f60d0d6b3624b34162dc
Status: Image is up to date for paketobuildpacks/run:base
docker.io/paketobuildpacks/run:base

$ docker inspect  docker.io/paketobuildpacks/run:base | grep Label
            "Labels": null
            "Labels": null

我运行了 a ./mvnw -X spring-boot:build-image,构建日志可在https://www.dropbox.com/s/iwwglb0vv8a6djq/build-image.txt?dl=0上找到

4

我认为这是错误的跑步形象。运行映像在io.buildpacks.builder.metadata构建器的标签中进行标识。的元数据将docker.io/paketobuildpacks/builder:base其运行映像列为index.docker.io/paketobuildpacks/run:base-cnb.请注意,这是 it'sbase-cnb而不是base

$ docker inspect index.docker.io/paketobuildpacks/run:base-cnb | grep -C 1 Labels
            "OnBuild": null,
            "Labels": {
                "io.buildpacks.stack.id": "io.buildpacks.stacks.bionic",
--
--
            "OnBuild": null,
            "Labels": {
                "io.buildpacks.stack.id": "io.buildpacks.stacks.bionic",
5

@wilkinsona 啊哈,我明白了。谢谢你!我会尝试一下,然后让你知道进展如何。

9

你好,

我是从SO重定向的。我希望也可以在此问题中发布信息,但如果最好创建一个单独的问题,请告诉我。

根据上面的转换,我检查了我自己的私人仓库,与我的在线机器中的相比,来自Labels(io.buildpacks.stack.*)的所有信息具有完全相同的信息。

像这样的东西

"Labels": {
                "io.buildpacks.stack.description": "ubuntu:bionic + openssl + CA certs",
                "io.buildpacks.stack.distro.name": "Ubuntu",
                "io.buildpacks.stack.distro.version": "18.04",
                "io.buildpacks.stack.homepage": "https://github.com/paketo-buildpacks/stacks",
                "io.buildpacks.stack.id": "io.buildpacks.stacks.bionic",
                "io.buildpacks.stack.maintainer": "Paketo Buildpacks",
                "io.buildpacks.stack.metadata": "{\"base-image\": \"paketobuildpacks/run@sha256:15d03f2ceb34ddedf8be3654d2e1e8ff2f60aa43e1b4f60d0d6b3624b34162dc\"}",
                "io.buildpacks.stack.mixins": "[\"adduser\",\"apt\",\"base-files\",\"base-passwd\",\"bash\",\"bsdutils\",\"bzip2\",\"ca-certificates\",\"coreutils\",\"dash\",\"debconf\",\"debianutils\",\"diffutils\",\"dpkg\",\"e2fsprogs\",\"fdisk\",\"findutils\",\"gcc-8-base\",\"gpgv\",\"grep\",\"gzip\",\"hostname\",\"init-system-helpers\",\"libacl1\",\"libapt-pkg5.0\",\"libattr1\",\"libaudit-common\",\"libaudit1\",\"libblkid1\",\"libbz2-1.0\",\"libc-bin\",\"libc6\",\"libcap-ng0\",\"libcom-err2\",\"libdb5.3\",\"libdebconfclient0\",\"libext2fs2\",\"libfdisk1\",\"libffi6\",\"libgcc1\",\"libgcrypt20\",\"libgmp10\",\"libgnutls30\",\"libgpg-error0\",\"libhogweed4\",\"libidn2-0\",\"liblz4-1\",\"liblzma5\",\"libmount1\",\"libncurses5\",\"libncursesw5\",\"libnettle6\",\"libp11-kit0\",\"libpam-modules\",\"libpam-modules-bin\",\"libpam-runtime\",\"libpam0g\",\"libpcre3\",\"libprocps6\",\"libseccomp2\",\"libselinux1\",\"libsemanage-common\",\"libsemanage1\",\"libsepol1\",\"libsmartcols1\",\"libss2\",\"libssl1.1\",\"libstdc++6\",\"libsystemd0\",\"libtasn1-6\",\"libtinfo5\",\"libudev1\",\"libunistring2\",\"libuuid1\",\"libyaml-0-2\",\"libzstd1\",\"locales\",\"login\",\"lsb-base\",\"mawk\",\"mount\",\"ncurses-base\",\"ncurses-bin\",\"openssl\",\"passwd\",\"perl-base\",\"procps\",\"sed\",\"sensible-utils\",\"sysvinit-utils\",\"tar\",\"tzdata\",\"ubuntu-keyring\",\"util-linux\",\"zlib1g\"]",
                "io.buildpacks.stack.released": "2020-12-20"
            }

输出gradle是这样的(从SO复制)

Gradle Test Executor 6 finished executing tests.

> Task :test
Finished generating test XML results (0.008 secs) into: C:\Users\joseph\Desktop\demo (9)\demo\build\test-results\test
Generating HTML test report...
Finished generating test html results (0.004 secs) into: C:\Users\joseph\Desktop\demo (9)\demo\build\reports\tests\test
:test (Thread[Execution worker for ':' Thread 7,5,main]) completed. Took 2.708 secs.
:check (Thread[Execution worker for ':' Thread 7,5,main]) started.

> Task :check
Skipping task ':check' as it has no actions.
:check (Thread[Execution worker for ':' Thread 7,5,main]) completed. Took 0.0 secs.
:build (Thread[Execution worker for ':' Thread 7,5,main]) started.

> Task :build
Skipping task ':build' as it has no actions.
:build (Thread[Execution worker for ':' Thread 7,5,main]) completed. Took 0.0 secs.
:bootBuildImage (Thread[Execution worker for ':' Thread 7,5,main]) started.

> Task :bootBuildImage
Caching disabled for task ':bootBuildImage' because:
  Build cache is disabled
Task ':bootBuildImage' is not up-to-date because:
  Task has not declared any outputs despite executing actions.
Building image 'docker.io/library/demo:0.0.1-SNAPSHOT'

 > Pulling builder image 'cr.io/paketobuildpacks/builder:base' ..................................................
 > Pulled builder image 'cr.io/paketobuildpacks/builder@sha256:dfbd2831033f37161f5027dfa46d5a658b29a3302c33aaf0219160a05fe5c12e'

> Task :bootBuildImage FAILED
:bootBuildImage (Thread[Execution worker for ':' Thread 7,5,main]) completed. Took 2.298 secs.

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':bootBuildImage'.
> No 'io.buildpacks.builder.metadata' label found in image config labels 'io.buildpacks.stack.description,io.buildpacks.stack.distro.name,io.buildpacks.stack.distro.version,io.buildpacks.stack.homepage,io.buildpacks.stack.id,io.buildpacks.stack.maintainer,io.buildpacks.stack.metadata,io.buildpacks.stack.mixins,io.buildpacks.stack.released'

* Try:
Run with --stacktrace option to get the stack trace. Run with --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/6.7/userguide/command_line_interface.html#sec:command_line_warnings

BUILD FAILED in 7s
8 actionable tasks: 8 executed

如果我可以提供任何信息,请告诉我。谢谢!

4

@wilkinsona 只是为了确定......base构建器映像的标签是否正确?

2

@bwgjoseph 您的图像标签也不正确。正如错误消息所示,构建器映像应具有io.buildpacks.builder.metadata与公共paketobuildpacks/builder:base映像相同的标签。

1

@kajh 是的,base是构建器映像的正确标签。

6

@wilkinsona 谢谢:)

8

@wilkinsona 谢谢!我将再次检查我的私人回购标签以进行验证

知道为什么它会丢失吗?我从在线机器导出图像 tar,然后复制到离线机器并加载然后推送到我的私人存储库

0

@bwgjoseph 我想不出为什么有些标签会保留而另一些标签现在却消失了。我想知道这是否可能是一个大小限制(io.buildpacks.builder.metadata的值相当大),但也缺少其他具有较小值的标签。例如,io.buildpacks.buildpack.order看起来缺失并且其值比io.buildpacks.stack.mixins存在的值短。

2

@wilkinsona 关于这一点,我该怎么做才能恢复丢失的标签?我可以尝试进行另一次导出,但不确定是否会再次发生同样的情况

4

抱歉,我不确定,因为我不是导出和导入 Docker 镜像的专家。此时,关于 Stack Overflow 的以 Docker 为中心的问题将是一个更好的方法,因为您的问题与 Spring Boot 并不特别相关。

3

同意,谢谢指点。会尝试弄清楚

8

你好,只是想提供更新

在尝试找出问题所在(缺少标签等)后,我意识到我在图像上标记了错误的图像名称。将两个图像重新加载到正确的名称和标签后,我就能够运行该过程。但似乎这个过程必须从互联网上下载一些额外的东西,它再次中断。

> Task :bootBuildImage
Building image 'docker.io/library/service:0.0.1-SNAPSHOT'

 > Pulling builder image 'm.cr.io/paketobuildpacks/builder:base' ..................................................
 > Pulled builder image 'm.cr.io/paketobuildpacks/builder@sha256:7de2396a3b3c135c7638e695a2cd83f0594f9fb8db039be207f2a6e17bd8e00a'
 > Pulling run image 'm.cr.io/paketobuildpacks/run:base-cnb' ..................................................
 > Pulled run image 'm.cr.io/paketobuildpacks/run@sha256:dfbd2831033f37161f5027dfa46d5a658b29a3302c33aaf0219160a05fe5c12e'
 > Executing lifecycle version v0.9.3
 > Using build cache volume 'pack-cache-c5e5d281afed.build'

 > Running creator
    [creator]     ===> DETECTING
    [creator]     5 of 18 buildpacks participating
    [creator]     paketo-buildpacks/ca-certificates   1.0.1
    [creator]     paketo-buildpacks/bellsoft-liberica 6.0.0
    [creator]     paketo-buildpacks/executable-jar    3.1.3
    [creator]     paketo-buildpacks/dist-zip          2.2.2
    [creator]     paketo-buildpacks/spring-boot       3.5.0
    [creator]     ===> ANALYZING
    [creator]     Previous image with name "docker.io/library/service:0.0.1-SNAPSHOT" not found
    [creator]     ===> RESTORING
    [creator]     ===> BUILDING
    [creator]
    [creator]     Paketo CA Certificates Buildpack 1.0.1
    [creator]       https://github.com/paketo-buildpacks/ca-certificates
    [creator]       Launch Helper: Contributing to layer
    [creator]         Creating /layers/paketo-buildpacks_ca-certificates/helper/exec.d/ca-certificates-helper
    [creator]         Writing profile.d/helper
    [creator]
    [creator]     Paketo BellSoft Liberica Buildpack 6.0.0
    [creator]       https://github.com/paketo-buildpacks/bellsoft-liberica
    [creator]       Build Configuration:
    [creator]         $BP_JVM_VERSION              11.*            the Java version
    [creator]       Launch Configuration:
    [creator]         $BPL_JVM_HEAD_ROOM           0               the headroom in memory calculation
    [creator]         $BPL_JVM_LOADED_CLASS_COUNT  35% of classes  the number of loaded classes in memory calculation
    [creator]         $BPL_JVM_THREAD_COUNT        250             the number of threads in memory calculation
    [creator]         $JAVA_TOOL_OPTIONS                           the JVM launch flags
    [creator]       BellSoft Liberica JRE 11.0.9: Contributing to layer
    [creator]         Downloading from https://github.com/bell-sw/Liberica/releases/download/11.0.9.1+1/bellsoft-jre11.0.9.1+1-linux-amd64.tar.gz
    [creator]     unable to invoke layer creator
    [creator]     unable to get dependency jre
    [creator]     unable to download https://github.com/bell-sw/Liberica/releases/download/11.0.9.1+1/bellsoft-jre11.0.9.1+1-linux-amd64.tar.gz
    [creator]     unable to request https://github.com/bell-sw/Liberica/releases/download/11.0.9.1+1/bellsoft-jre11.0.9.1+1-linux-amd64.tar.gz
    [creator]     Get "https://github.com/bell-sw/Liberica/releases/download/11.0.9.1+1/bellsoft-jre11.0.9.1+1-linux-amd64.tar.gz": dial tcp: lookup github.com on 192.168.65.1:53: no such host
    [creator]     ERROR: failed to build: exit status 1

> Task :bootBuildImage FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':bootBuildImage'.
> Builder lifecycle 'creator' failed with status code 145

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/6.7/userguide/command_line_interface.html#sec:command_line_warnings

BUILD FAILED in 25s
18 actionable tasks: 17 executed, 1 up-to-date

这与 spring-boot 无关,并且有一些方法可以覆盖它。为了以后的参考,可以参考bellsoft-liberica,虽然看起来目前的重写方式还是挺麻烦的。将尝试这样做。

但再次感谢您的帮助。

0

@wilkinsona 使用标签base-cnb效果很好,所以你可以为我关闭这个问题。现在我得到了一个[creator] ERROR: failed to initialize docker client: failed to connect to docker socket: dial unix /var/run/docker.sock: connect: permission denied,但与这个问题无关。感谢你们对我的帮助! :)

7

没问题。感谢您让我们知道。

9

ERROR: failed to initialize docker client: failed to connect to docker socket: dial unix /var/run/docker.sock: connect: permission deniedfwiw在 Kubernetes pod 中运行构建时我也会遇到这种情况。我可以访问 docker unix 套接字。我可以docker很好地运行命令。 (Java 11、Spring Boot 2.5.1、k8s 1.19、maven 3.6、docker 20.10.3)