【问题标题】:Multiple tags for a Docker image built by Google Jib and Maven?由 Google Jib 和 Maven 构建的 Docker 映像的多个标签?
【发布时间】:2021-07-05 02:44:06
【问题描述】:

使用jib-maven-plugin 我想构建一个带有多个标签的图像。虽然mvn jib:build 基本上可以正常工作,但它“只”用latest 标记图像。

我的 Maven pom.xml 定义如下:

<plugin>
    <groupId>com.google.cloud.tools</groupId>
    <artifactId>jib-maven-plugin</artifactId>
    <version>2.8.0</version>
    <configuration>
        <to>
            <image>my-private-registry.org/my-image</image>
        </to>
    </configuration>
</plugin>

The docs 表明可以在 XML 中使用jib.to.tags 来定义标签列表。但是,我想在 Jenkins 管道中运行构建步骤,即我无法对 pom.xml 中的标签进行硬编码。

是否可以在运行mvn 命令时传递标签列表,例如通过设置一些-D 参数?

【问题讨论】:

    标签: jib maven-jib


    【解决方案1】:

    使用-Djib.to.tags=a,b,c

    $ mvn package jib:build -Djib.to.tags=a,b,c
    ...
    [INFO] --- jib-maven-plugin:2.8.0:dockerBuild (default-cli) @ hello-spring-boot ---
    [INFO] Tagging image with generated image reference hello-spring-boot:0.1.0. If you'd like to specify a different tag, you can set the <to><image> parameter in your pom.xml, or use the -Dimage=<MY IMAGE> commandline flag.
    [INFO] 
    [INFO] Containerizing application to Docker daemon as hello-spring-boot:0.1.0, hello-spring-boot:a, hello-spring-boot:b, hello-spring-boot:c...
    [WARNING] Base image 'gcr.io/distroless/java:8' does not use a specific image digest - build may not be reproducible
    [INFO] Using base image with digest: sha256:34c3598d83f0dba27820323044ebe79e63ad4f137b405676da75a3905a408adf
    [INFO] 
    [INFO] Container entrypoint set to [java, -Djava.security.egd=file:/dev/./urandom, -cp, /app/resources:/app/classes:/app/libs/*, hello.Application]
    [INFO] 
    [INFO] Built image to Docker daemon as hello-spring-boot:0.1.0, hello-spring-boot:a, hello-spring-boot:b, hello-spring-boot:c
    [INFO] 
    [INFO] A new version of Jib (3.0.0) is available (currently using 2.8.0). Update your build configuration to use the latest features and fixes!
    [INFO] https://github.com/GoogleContainerTools/jib/blob/master/jib-maven-plugin/CHANGELOG.md
    [INFO] Please see https://github.com/GoogleContainerTools/jib/blob/master/docs/privacy.md for info on disabling this update check.
    [INFO] 
    [INFO] Executing tasks:
    [INFO] [==============================] 100.0% complete
    [INFO] 
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD SUCCESS
    [INFO] ------------------------------------------------------------------------
    

    【讨论】:

    • 我有这个命令:./mvnw package -Pprod verify -DskipTests jib:build -Dimage=registry.gitlab.com/me/myproject:master 在使用 -Djib.to.tags=master 时, v1.14 会直接推送两个标签吗?
    猜你喜欢
    • 2021-05-28
    • 1970-01-01
    • 2021-03-21
    • 2016-12-22
    • 1970-01-01
    • 2020-11-14
    • 2021-11-13
    • 2019-04-10
    • 2020-07-06
    相关资源
    最近更新 更多