jib源码分析及应用

栏目: 编程工具 · 发布时间: 6年前

内容简介:阅读本文前,建议事先了解下

简介

阅读本文前,建议事先了解下 docker环境下的持续构建

jib

基本使用

Google开源其 Java 容器化工具Jib,简化镜像构建全流程

mvn compile jib:build 从中可以看到

[INFO] Retrieving registry credentials for harbor.test.ximalaya.com...
[INFO] Getting base image harbor.test.ximalaya.com/test/jdk8-tomcat8...
[INFO] Building dependencies layer...
[INFO] Building resources layer...
[INFO] Building classes layer...
[INFO] Retrieving registry credentials for harbor.test.ximalaya.com...
[INFO] Finalizing...
[INFO] 
[INFO] Container entrypoint set to [java, -cp, /app/libs/*:/app/resources/:/app/classes/, org.apache.catalina.startup.Bootstrap]
[INFO] 
[INFO] Built and pushed image as harbor.xx/test/jib-demo
  1. 与常规的将代码及依赖 打成一个jar 包作为一个layer 不同,jib 将dependencies、resources、 classes(即项目代码) 分别打成一个layer, 在项目实践中,dependencies、resources 变化不多 ,因此能够复用相当一部分空间。

  2. maven pom.xml 配置 针对插件的 0.9.9 版本

    <plugin>
         <groupId>com.google.cloud.tools</groupId>
         <artifactId>jib-maven-plugin</artifactId>
         <version>0.9.9</version>
         <configuration>
             <allowInsecureRegistries>false</allowInsecureRegistries>
             <from>
                 <image>harbor.test.xxx.com/test/jdk8</image>
                 <auth>
                     <username>xxx</username>
                     <password>xxx</password>
                 </auth>
             </from>
             <to>
                 <image>harbor.test.xxx.com/test/jib-springboot-demo</image>
                 <auth>
                     <username>xxx</username>
                     <password>xxx</password>
                 </auth>
             </to>
             <container>
                 <mainClass>com.xxx.springboot.demo.DockerSpringbootDemoApplication</mainClass>
             </container>
         </configuration>
     </plugin>

还有一种方案 Optimizing Spring Boot apps for Docker

打tag

To tag the image with a simple timestamp, add the following to your pom.xml:

<properties>
  <maven.build.timestamp.format>yyyyMMdd-HHmmssSSS</maven.build.timestamp.format>
</properties>
Then in the jib-maven-plugin configuration, set the tag to:

<configuration>
  <to>
    <image>my-image-name:${maven.build.timestamp}</image>
  </to>
</configuration>

jib 优化

从目前来看,我们感觉针对 java 项目来说,jib 是最优的。jib 貌似可以做到,不用非得在 pom.xml 中体现。 mvn compile com.google.cloud.tools:jib-maven-plugin:0.10.0:build -Dimage=<MY IMAGE>

对以后的多语言,可以项目中 弄一个deploy.yaml 文件。这个yaml 文件应该是 跨语言的,yaml 文件的执行器 应能根据 yaml 配置 自动完成 代码 到 镜像的所有工作。

language:java
param:
creator: zhangsan

然后,编写一个 build 程序

  1. 碰到java 执行 mvn compile com.google.cloud.tools:jib-maven-plugin:0.10.0:build -Dimage=<MY IMAGE> 。这里 build 程序要做的工作 是根据 deploy.yaml 文件的用户参数 拼凑 mvn compile com.google.cloud.tools:jib-maven-plugin:0.10.0:build -Dimage=<MY IMAGE> 命令 并执行。 本质上还是用maven,只是在jenkins 和 maven 之间加了一层 ,加了一层之后,就可以更方便的支持用户的个性化(或者说,用户可以在项目代码上 而不是jenkins 上做个性化配置)
  2. 碰到golang 执行 go build。 go 语言中 一定有类似 jib 的框架在。

个人微信订阅号

jib源码分析及应用


以上所述就是小编给大家介绍的《jib源码分析及应用》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

数据结构与算法

数据结构与算法

Michael McMillan / 吕秀峰、崔睿 / 人民邮电出版社 / 2009-5 / 49.00元

《数据结构与算法C#语言描述》是在.NET框架下用C#语言实现数据结构和算法的第一本全面的参考书。《数据结构与算法C#语言描述》介绍的方法非常实用,采用了时间测试而非大O表示法来分析算法性能。内容涵盖了数据结构和算法的基本原理,涉及数组、广义表、链表、散列表、树、图、排序搜索算法以及更多概率算法和动态规则等高级算法。此外,书中还提供了.NET框架类库中的C#语言实现的数据结构和算法。 《数据......一起来看看 《数据结构与算法》 这本书的介绍吧!

JS 压缩/解压工具
JS 压缩/解压工具

在线压缩/解压 JS 代码

JSON 在线解析
JSON 在线解析

在线 JSON 格式化工具

URL 编码/解码
URL 编码/解码

URL 编码/解码