3

我正在尝试使用 Skaffold、Dekorate 和 Spring Boot。

我找不到任何使用 Spring Boot 2.3+ 的新 buildpack 功能的示例

apiVersion: skaffold/v2beta9
kind: Config
metadata:
  name: tellus-upgrade
build:
  artifacts:
    - image: tellus-admin
      custom:
        buildCommand: ./mvnw -pl tellus-admin org.springframework.boot:spring-boot-maven-plugin:2.4.0:build-image -Dspring-boot.build-image.imageName=$IMAGE -Drevision=dev-SNAPSHOT -DskipTests=true
        dependencies:
          paths:
            - tellus-admin/src
            - tellus-admin/pom.xml
    - image: tellus-config-server
      custom:
        buildCommand: ./mvnw -pl tellus-config-server org.springframework.boot:spring-boot-maven-plugin:2.4.0:build-image -Dspring-boot.build-image.imageName=$IMAGE -Drevision=dev-SNAPSHOT -DskipTests=true
        dependencies:
          paths:
            - tellus-config-server/src
            - tellus-config-server/pom.xml
deploy:
  kubectl:
    manifests:
    - kubernetes/defaults.yml
    - kubernetes/db/kubernetes.yml
    - kubernetes/dev/dnsutils.yml
    - kubernetes/kafka-connect/kubernetes.yml
    - tellus-admin/target/classes/META-INF/dekorate/kubernetes.yml
    - tellus-config-server/target/classes/META-INF/dekorate/kubernetes.yml

当我运行 skaffold dev 时出现错误:exiting dev mode because first build failed: the custom script didn't generate an image with tag [tellus-config-server:RELEASE_2020_2_0-226-g9be76a373-dirty]

然而,从日志看来,图像是构建的......

[INFO] Successfully built image 'docker.io/library/tellus-config-server:RELEASE_2020_2_0-226-g9be76a373-dirty'
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  17.004 s
[INFO] Finished at: 2020-11-15T22:31:59+11:00
[INFO] ------------------------------------------------------------------------
Building [tellus-admin]...
exiting dev mode because first build failed: the custom script didn't produce an image with tag [tellus-config-server:RELEASE_2020_2_0-226-g9be76a373-dirty]
4

2 回答 2

2

spring-boot-maven-plugin:build-image图像加载到本地 Docker 守护程序中,但不会推送图像。我从未尝试过,但您也许可以使用com.spotify:dockerfile-maven-plugin:push目标。

更新:这是一个 Skaffold 自定义构建脚本,它应该做正确的事情:

#!/bin/sh
set -e
cd "$BUILD_CONTEXT"
mvn -pl "$1" -Drevision=dev-SNAPSHOT -DskipTests=true \
  org.springframework.boot:spring-boot-maven-plugin:build-image \
  -Dspring-boot.build-image.imageName="$IMAGE"
if [ "$PUSH_IMAGE" = true ]; then
    docker push "$IMAGE"
fi

您可以将其保存到文件中mvn-build-image.sh,然后修改 skaffold.yaml,如下所示:

artifacts:
- image: tellus-admin
  custom:
    buildCommand: ./mvn-build-image.sh tellus-admin 

您可能希望查看Skaffold 的 Jib 集成以简化此过程。

于 2020-11-16T19:49:40.900 回答
0

如果问题是基于 Paketo/spring-boot-maven-plugin 仅生成本地容器映像 - 而不是按照Brian de Alwis 概述的那样推送它- 那么spring-boot-maven-plugin 的映像发布能力应该可以解决问题. 因此,只需将以下内容附加到您的mvn spring-boot:build-image命令中:

mvn spring-boot:build-image -Dspring-boot.build-image.publish=true

您还可以像这样明确地配置图像名称:

mvn spring-boot:build-image -Dspring-boot.build-image.imageName=docker.example.com/library/tellus-config-server:latest -Dspring-boot.build-image.publish=true

正如文档所述,您还可以在以下配置中配置图像发布的各个方面pom.xml

<plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
    <configuration>
        <image>
            <name>docker.example.com/library/${project.artifactId}</name>
            <publish>true</publish>
        </image>
        <docker>
            <publishRegistry>
                <username>user</username>
                <password>secret</password>
                <url>https://docker.example.com/v1/</url>
                <email>user@example.com</email>
            </publishRegistry>
        </docker>
    </configuration>
</plugin>

有了该配置,您甚至不需要显式使用该-Dspring-boot.build-image.publish=true参数,因为我们配置<image><publish>true.

因此无需使用 Jib 或自定义构建脚本。Skaffold 目前甚至还有Cloud Native Buildpack 支持- 所以这可能是另一种选择(因为spring-boot-maven-plugin它也是 Cloud Native Buildpack / Paketo.io 集成的“唯一”抽象),如果你愿意的话喜欢切换到pack CLI

于 2020-12-09T09:28:44.467 回答