通过代理使用 mvn 和 jib 构建 docker 镜像

如何解决通过代理使用 mvn 和 jib 构建 docker 镜像

我正在运行此命令以使用 dockermaven
构建 jib 映像 mvn compile jib:dockerBuild -Djib.to.image="$IMAGE_NAME"
此命令在我的机器上运行良好,因为它将从 Internet 下载一些内容,但是,当我尝试在管道(在 AWS 上)中运行它时,情况并非如此,该管道将在需要在公司网络中运行的代理
我已经尝试过这个命令:
export MAVEN_OPTS="-DsocksProxyHost=<host> -DsocksProxyPort=<port>"
但它不起作用,我不想触摸 settings.xml 文件,因为我无权访问它,所以我正在寻找的唯一解决方案是提供一个带有列出的命令的代理以上。
这是命令的整个日志:

[INFO] Scanning for projects...
Downloading from central: https://repo.maven.apache.org/maven2/kr/motd/maven/os-maven-plugin/1.6.2/os-maven-plugin-1.6.2.pom
[ERROR] [ERROR] Some problems were encountered while processing the POMs:
[ERROR] Unresolveable build extension: Plugin kr.motd.maven:os-maven-plugin:1.6.2 or one of its dependencies Could not be resolved: Failed to read artifact descriptor for kr.motd.maven:os-maven-plugin:jar:1.6.2 @ 
 @ 
[ERROR] The build Could not read 1 project -> [Help 1]
[ERROR]   
[ERROR]   The project com.bmw.relyze:backend:1.0-SNAPSHOT (/codebuild/output/src794035415/src/backend/pom.xml) has 1 error
[ERROR]     Unresolveable build extension: Plugin kr.motd.maven:os-maven-plugin:1.6.2 or one of its dependencies Could not be resolved: Failed to read artifact descriptor for kr.motd.maven:os-maven-plugin:jar:1.6.2: Could not transfer artifact kr.motd.maven:os-maven-plugin:pom:1.6.2 from/to central (https://repo.maven.apache.org/maven2): Transfer Failed for https://repo.maven.apache.org/maven2/kr/motd/maven/os-maven-plugin/1.6.2/os-maven-plugin-1.6.2.pom: PKIX path building Failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target -> [Help 2]
[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/ProjectBuildingException
[ERROR] [Help 2] http://cwiki.apache.org/confluence/display/MAVEN/PluginManagerException

[Container] 2021/02/26 11:15:48 Command did not exit successfully cd backend && mvn compile jib:dockerBuild -Dhttp.proxyHost=http://proxy.ccc-ng-1.eu-central-1.aws.cloud.bmw -Dhttp.proxyPort=8080 -Djib.to.image="$JAVA_SERVICE_IMAGE_NAME" && cd .. exit status 1
[Container] 2021/02/26 11:15:48 Phase complete: BUILD State: Failed_WITH_ABORT
[Container] 2021/02/26 11:15:48 Phase context status code: COMMAND_EXECUTION_ERROR Message: Error while executing command: cd backend && mvn compile jib:dockerBuild -Dhttp.proxyHost=http://proxy.ccc-ng-1.eu-central-1.aws.cloud.bmw -Dhttp.proxyPort=8080 -Djib.to.image="$JAVA_SERVICE_IMAGE_NAME" && cd ... Reason: exit status 1

解决方法

有多种方式。首先,查看此 Oracle doc 以了解您可以设置哪些标准 Java 网络属性。

  1. settings.xml(Maven 设置文件)中设置代理配置。例如,

      <proxies>
        <proxy>
          <id>for-https-proxying</id> <!-- Make sure you use different IDs -->
          <!-- For HTTPS proxying. AFAIK,the Maven doc is wrong about this. -->
          <protocol>https</protocol>
          <host>my.company.proxy.com</host>
          <nonProxyHosts>localhost|srv-abc|*.int</nonProxyHosts>
        </proxy>
        <proxy>
          <id>for-http-proxying</id>
          <protocol>http</protocol>  <!-- for HTTP proxying  -->
          <host>my.company.proxy.com</host>
          <nonProxyHosts>localhost|srv-abc|*.int</nonProxyHosts>
        </proxy>
      </proxies>
    

    查看Maven Settings Reference了解更多详情。

  2. 在运行 Jib (JVM) 时设置网络系统属性。例如,一个命令行,

    $ mvn -Dhttp.proxyHost=my.company.proxy.com \
          -Dhttp.proxyPort=... \
          -Dhttp.nonProxyHosts=... \
          -Dhttps.proxyHost=... \
          -Dhttps.proxyPort=... \
          compile jib:build
    

参考:https://github.com/GoogleContainerTools/jib/issues/1403

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?
Java在半透明框架/面板/组件上重新绘画。
Java“ Class.forName()”和“ Class.forName()。newInstance()”之间有什么区别?
在此环境中不提供编译器。也许是在JRE而不是JDK上运行?
Java用相同的方法在一个类中实现两个接口。哪种接口方法被覆盖?
Java 什么是Runtime.getRuntime()。totalMemory()和freeMemory()?
java.library.path中的java.lang.UnsatisfiedLinkError否*****。dll
JavaFX“位置是必需的。” 即使在同一包装中
Java 导入两个具有相同名称的类。怎么处理?
Java 是否应该在HttpServletResponse.getOutputStream()/。getWriter()上调用.close()?
Java RegEx元字符(。)和普通点?