当前位置: 首页 > 知识库问答 >
问题:

运行mvn spring boot时使用Artifactory:构建映像

郑嘉年
2023-03-14

我希望能够运行SpringBoot:build映像,并让它从本地Artifactory服务器而不是docker中提取paketobuildpack。木卫一。我希望插件使用docker配置文件作为我的凭证,而不是在pom文件中硬编码。

这个作品:

            <docker>
                <builderRegistry>
                    <username>username</username>
                    <password>password</password>
                    <url>https://artifactory.mycompany.com/v2/</url>
                </builderRegistry>
            </docker>

当我在没有上面的docker块的情况下运行mvn Spring-boot: build-Image时,我得到以下错误:

[ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:2.4.2:build-image (default-cli) on project demo: Execution default-cli of goal org.springframework.boot:spring-boot-maven-plugin:2.4.2:build-image failed: Docker API call to 'localhost/v1.24/images/create?fromImage=artifactory.mycompany.com%2Fcommon-docker-virtual%2Fpaketobuildpacks%2Fbuilder%3Abase' 
failed with status code 500 "Internal Server Error" and message "Head https://artifactory.mycompany.com/v2/common-docker-virtual/paketobuildpacks/builder/manifests/base: 
unknown: Authentication is required" -> [Help 1]

我的docker/config。json具有以下配置:

{
  "auths": {
    "artifactory.mycompany.com": {
      "auth": "**token**",
      "email": "myemail@mycompany.com"
    }
  },
  "credStore": "desktop",
  "credsStore": "desktop"
}

我可以成功地运行docker build,它成功地将我们的Artifactory用于其他不相关的映像。

我的pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.4.2</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.penske.architecture</groupId>
    <artifactId>myapp</artifactId>
    <version>1.0.0.RELEASE</version>
    <name>myapp</name>

    <properties>
        <maven.compiler.target>14</maven.compiler.target>
        <maven.compiler.source>14</maven.compiler.source>
        <java.version>14</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-ldap</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-mongodb</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <scope>runtime</scope>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-configuration-processor</artifactId>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-lang3</artifactId>
            <version>3.11</version>
        </dependency>
    </dependencies>

    <build>
        <finalName>${project.artifactId}</finalName>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <layers>
                        <enabled>true</enabled>
                    </layers>
                    <image>
                        <name>artifactory.mycompany.com/common-docker-virtual/library/${project.artifactId}</name>
                        <builder>artifactory.mycompany.com/common-docker-virtual/paketobuildpacks/builder:base</builder>
                        <env>
                            <BP_JVM_VERSION>14</BP_JVM_VERSION>
                        </env>
                        </image>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>build-image</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

完整的maven输出

[INFO] Scanning for projects...
[INFO] 
[INFO] ----------< my.group:myapp >-----------
[INFO] Building myapp 1.0.0.RELEASE
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] >>> spring-boot-maven-plugin:2.4.2:build-image (default-cli) > package @ myapp >>>
[INFO] 
[INFO] --- maven-resources-plugin:3.2.0:resources (default-resources) @ myapp ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Using 'UTF-8' encoding to copy filtered properties files.
[INFO] Copying 3 resources
[INFO] Copying 1 resource
[INFO] 
[INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) @ myapp ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-resources-plugin:3.2.0:testResources (default-testResources) @ myapp ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Using 'UTF-8' encoding to copy filtered properties files.
[INFO] skip non existing resourceDirectory C:\myapp\src\test\resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.8.1:testCompile (default-testCompile) @ myapp ---
[INFO] No sources to compile
[INFO] 
[INFO] --- maven-surefire-plugin:2.22.2:test (default-test) @ myapp ---
[INFO] No tests to run.
[INFO] 
[INFO] --- maven-jar-plugin:3.2.0:jar (default-jar) @ myapp ---
[INFO] Building jar: C:\myapp\target\ldap-changelog-exporter.jar
[INFO] 
[INFO] --- spring-boot-maven-plugin:2.4.2:repackage (repackage) @ myapp ---
[INFO] Replacing main artifact with repackaged archive
[INFO] 
[INFO] <<< spring-boot-maven-plugin:2.4.2:build-image (default-cli) < package @ myapp <<<
[INFO] 
[INFO] 
[INFO] --- spring-boot-maven-plugin:2.4.2:build-image (default-cli) @ myapp ---
[INFO] Building image 'artifactory.mycompany.com/common-docker-virtual/library/myapp:latest'
[INFO] 
[INFO]  > Pulling builder image 'artifactory.mycompany.com/common-docker-virtual/paketobuildpacks/builder:base' 100%
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  9.024 s
[INFO] Finished at: 2021-02-11T16:48:27-05:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:2.4.2:build-image (default-cli) on project myapp: Execution default-cli of goal org.springframework.boot:spring-boot-maven-plugin:2.4.2:build-image failed: Docker API call to 'localhost/v1.24/images/create?fromImage=artifactory.mycompany.com%2Fcommon-docker-virtual%2Fpaketobuildpacks%2Fbuilder%3Abase' failed with status code 500 "Internal Server Error" and message "Head https://artifactory.mycompany.com/v2/common-docker-virtual/paketobuildpacks/builder/manifests/base: unknown: Authentication is required" -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginExecutionException

Process finished with exit code 1

共有1个答案

逑阳泽
2023-03-14

将凭据放入设置中。属性部分中的xml(~/.m2/settings.xml或由mvn命令中的-s指定的任何内容)(https://maven.apache.org/settings.html#Profiles)然后在你的pom里。xml用定义的变量名替换硬编码的值。

如果使用环境变量(${env.something}),甚至可以跳过设置。xml并从cli中定义它们。

 类似资料:
  • 目前,我发现谷歌云构建发生在构建docker图像的时候(不像我想象的那样,它会构建我的图像,然后执行我的图像来完成所有的构建)。那是在这篇文章里 谷歌云构建的快速启动 我有一个Dockerfile现在很简单 我有一个单一的下载和提取下载任何工件(zip文件)从最后的单构建运行构建(只有修改的服务器被构建或依赖于上一个CI构建的变化的服务器被构建,就像下游库可能被更改)。第一行只是列出了我需要在一个

  • 问题内容: 我尝试在构建映像的同时使用Docker安装软件,然后得到了。 我使用的Dockerfile 有没有一种方法可以在Dockerfile中运行docker命令来创建映像? 问题答案: 您的问题不在于Docker命令,因为它在错误消息中表示您的Docker守护程序未运行,或者由于某些配置问题而无法连接到它。 您刚刚安装了Docker吗?您是否完成了《安装指南》中的所有步骤? 您可以使用或来测

  • 我有以下构建文物在艺术工厂服务器。 http://artifactory.company.com:8081/artifactory/libs-snapshot-local/com/mycompany/projectA/service_y/2.75.0.1/service_y-2.75.0.1.jar http://artifactory.company.com:8081/artifactory/l

  • 我正在使用Micronaut,并使用它的cli创建一个java-cli-app。它没有额外的代码,通过运行main方法运行良好。当执行./gradlew构建时,它还创建了一个包含所有依赖项的jar。 我也可以使用GraalVM 19.1.1和19.2.0构建本地映像,而且运行良好。 当我通过手动运行以下任务来构建本机映像时 它也运行良好, 当创建jar时,它会自动运行。 我已经试过了, 这不起作用

  • 编译错误 此环境中未提供编译器。也许您正在运行 JRE 而不是 JDK?完成时间: 2018-02-06T12:16:07 05:30 最终内存: 9M/63M 无法执行目标组织.apache.maven.plugins:maven-编译器-插件:3.1:编译(默认编译) 编译失败 此环境中未提供编译器。也许您正在运行 JRE 而不是 JDK? 要查看错误的完整堆栈跟踪,请使用-e开关重新运行Ma

  • 在我的项目中,我有一个有问题的表(这里名为),其中包含一些始终存在的列(在模式中定义,例如:),当应用程序运行时,会动态添加或删除其他列。我可以通过一个简单的函数使用这些“动态”列,该函数返回适当的对象: 该函数运行良好,我可以使用它返回的对象创建jOOQ查询。 当我想添加一个运行时映射,在呈现的查询中重命名这个有问题的表时,问题就开始了。 当我使用jOOQ创建一个简单的查询时,映射部分工作。 呈