• springbootmavenplugin 发布镜像至私服


    前提条件

    1. 云端有个私服
    2. 本地有 docker 环境,并配置了国内仓库
    3. 可以上网(镜像构建过程可能会从 github 下载文件)

    版本说明

    • OS: Windows10
    • jdk:openjdk-17
    • spring-boot:2.6.6
    • maven:3.8.4 (默认 spring-boot 项目搭建时的包装版本)

    使用步骤

    docker 配置

    image

    {
      "builder": {
        "gc": {
          "defaultKeepStorage": "20GB",
          "enabled": true
        }
      },
      "experimental": false,
      "features": {
        "buildkit": true
      },
      "registry-mirrors": [
        "http://hub-mirror.c.163.com",
        "https://docker.mirrors.ustc.edu.cn"
      ],
      "insecure-registries": [
        "如果私服使用的证书没有经过备份,则需要添加忽略安全检查仓库配置,例如:127.0.0.1:9990"
      ]
    }
    

    项目 pom.xml 文件

    <build>
            <plugins>
                <plugin>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-maven-plugin</artifactId>
                    <configuration>
                        <!--热刷新资源-->
                        <addResources>true</addResources>
                        <excludes>
                            <exclude>
                                <groupId>org.projectlombok</groupId>
                                <artifactId>lombok</artifactId>
                            </exclude>
                        </excludes>
                        <image>
                            <name>私服项目名称/${project.artifactId}:${project.version}</name>
                            <publish>true</publish>
                        </image>
                        <docker>
                            <publishRegistry>
                                <username>私服账号</username>
                                <password>私服密码</password>
                                <url>docker私服地址</url>
                                <email>dewen.jiang@chinacreator.com</email>
                            </publishRegistry>
                        </docker>
                    </configuration>
                </plugin>
            </plugins>
        </build>
    

    打包发布脚本指令

    // 如果 jar 包下载很慢的话,可以考虑修改 maven 配置
    // 需要确保 jdk 环境与项目的 jdk 环境一致
    .\mvnw spring-boot:build-image
    

    开发可以偷懒
    image

    疑难问题

    1. 打包出错
      90% 都是网络问题,多 jdk 的话,检查 jdk 环境;检查 maven 配置;检查本地 docker 的镜像源配置与安全检查配置。
    2. 发布出错
      检查 docker 仓库安全检查配置

    参考网址

    spring-boot-maven-plugin
    docker reference

  • 相关阅读:
    form表单生成的简单理解
    drupal里面的ajax最粗浅的理解-流程
    #array_parents #parents的区别
    hook_schema 小总结
    多语言的sitemap xml
    做百度竞价的步骤 不断总结
    为什么要baidu/Google问题 尽量少在群里问问题
    JavaScript Window对象
    JavaScript 3种内置对象
    图片轮播
  • 原文地址:https://www.cnblogs.com/listjiang/p/16129762.html
Copyright © 2020-2023  润新知