jib-maven-plugin構建鏡像


序言

在本次期末設計當中,應為需要做部署腳本,我們采用的是dockerfile+docker-compose的部署方式,這種方式對vue項目是沒有問題的,因為vue下載依賴與打包是分離開來的,即使修改了代碼,只要沒有安裝新的包都不會重新去下載包。而在SpringBoot項目中,也許是個人技術原因,沒有找到下載依賴與打包分離開的方法,導致每次修改代碼打包的時候都需要下載一堆的東西,導致運行時長過長。在咨詢一些大佬后得知jib插件。

准備工作

在阿里雲的容器鏡像服務中創建兩個鏡像倉庫,一個用於部署,一個用於創建自己的jdk鏡像(不用應該也是可以的)。

image.png

一、設置jdk鏡像

在管理鏡像中參考官方給的demo進行設置即可
image.png

二、設置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

image.png

image.png


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM