jib-maven-plugin构建镜像
序言
在本次期末设计当中,应为需要做部署脚本,我们采用的是dockerfile+docker-compose的部署方式,这种方式对vue项目是没有问题的,因为vue下载依赖与打包是分离开来的,即使修改了代码,只要没有安装新的包都不会重新去下载包。而在SpringBoot项目中,也许是个人技术原因,没有找到下载依赖与打包分离开的方法,导致每次修改代码打包的时候都需要下载一堆的东西,导致运行时长过长。在咨询一些大佬后得知jib插件。
准备工作
在阿里云的容器镜像服务中创建两个镜像仓库,一个用于部署,一个用于创建自己的jdk镜像(不用应该也是可以的)。
一、设置jdk镜像
在管理镜像中参考官方给的demo进行设置即可
二、设置pom.xml
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>com.google.cloud.tools</groupId>
<artifactId>jib-maven-plugin</artifactId>
<version>1.8.0</version>
<configuration>
<from>
<image>registry.cn-hangzhou.aliyuncs.com/yhhu/jdk8</image>
</from>
<to>
<image>registry.cn-hangzhou.aliyuncs.com/yhhu/ejile</image>
<tags>
<tag>0.01</tag>
</tags>
</to>
<container>
<ports>
<port>8080</port>
</ports>
<useCurrentTimestamp>true</useCurrentTimestamp>
<args>
<arg>--spring.profiles.active=prod</arg>
</args>
</container>
<allowInsecureRegistries>true</allowInsecureRegistries>
</configuration>
</plugin>
</plugins>
</build>
方法一:配置maven settings.xml
文件(推荐)
<pluginGroups>
<!-- pluginGroup | Specifies a further group identifier to use for plugin
lookup. <pluginGroup>com.your.plugins</pluginGroup> -->
<pluginGroup>com.google.cloud.tools</pluginGroup>
</pluginGroups>
<!--对应容器仓库权限的账号密码-->
<servers>
<server>
<id>registry.cn-hangzhou.aliyuncs.com</id>
<username>xxx</username>
<password>xxx</password>
</server>
</servers>
方法二:在pom.xml中添加认证信息(不推荐)
<from>
<image>registry.cn-hangzhou.aliyuncs.com/yhhu/jdk8</image>
<auth>
<username>my_username</username>
<password>my_password</password>
</auth>
</from>
<to>
<image>registry.cn-hangzhou.aliyuncs.com/yhhu/ejile</image>
<tags>
<tag>0.01</tag>
</tags>
<auth>
<username>my_username</username>
<password>my_password</password>
</auth>
</to>
三、构建并提交镜像
mvn compile jib:build