spring时使用artifactory-boot:build-image

ldfqzlk8  于 2021-07-23  发布在  Java
关注(0)|答案(0)|浏览(336)

我想能跑Spring-boot:build-image and 让它从我们的本地artifactory服务器而不是docker.io中提取paketobuildpack。我希望插件使用docker配置文件为我的凭据,而不是硬编码在pom文件中。
这样做有效:

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

当我跑的时候 mvn spring-boot:build-image ,没有上面的docker块,我得到以下错误:

[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]

my.docker/config.json具有以下配置:

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

我可以成功地运行docker构建,它成功地将我们的人工制品用于其他不相关的图像。
我的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

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题