美文网首页
mvn 打包并自动上传 jar/war docker 镜像

mvn 打包并自动上传 jar/war docker 镜像

作者: akka9 | 来源:发表于2018-12-13 15:04 被阅读0次

dockerfile-maven 打包

pom.xml
加到 这一段代码后面

<plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.0</version>
        <configuration>
                <source>1.7</source>
                <target>1.7</target>
                <encoding>UTF-8</encoding>
                <compilerArguments>
                        <bootclasspath>${java.home}/lib/rt.jar:${java.home}/lib/charsets.jar:${java.home}/lib/jce.jar</bootclasspath>
                </compilerArguments>
        </configuration>
</plugin>
<plugin>
    <groupId>pl.project13.maven</groupId>
    <artifactId>git-commit-id-plugin</artifactId>
    <version>2.2.5</version>
    <executions>
        <execution>
            <id>get-the-git-infos</id>
            <goals>
                <goal>revision</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <dotGitDirectory>${project.basedir}/.git</dotGitDirectory>
        <prefix>git</prefix>
        <verbose>false</verbose>
        <generateGitPropertiesFile>true</generateGitPropertiesFile>
        <generateGitPropertiesFilename>${project.build.outputDirectory}/git.properties</generateGitPropertiesFilename>
        <format>json</format>
        <gitDescribe>
            <skip>false</skip>
            <always>false</always>
            <dirty>-dirty</dirty>
        </gitDescribe>
        <failOnNoGitDirectory>false</failOnNoGitDirectory>
        <excludeProperties>
                <excludeProperty>git.user.*</excludeProperty>
                <excludeProperty>git.remote.*</excludeProperty>
                <excludeProperty>git.build.*</excludeProperty>
        </excludeProperties>
        <injectAllReactorProjects>true</injectAllReactorProjects>
    </configuration>
</plugin>

<plugin>
  <groupId>com.spotify</groupId>
  <artifactId>dockerfile-maven-plugin</artifactId>
  <version>1.4.9</version>
  <executions>
    <execution>
      <id>default</id>
      <goals>
        <goal>build</goal>
        <goal>push</goal>
      </goals>
    </execution>
  </executions>
  <configuration>
    <repository>register-domain-name/group-name/project-name</repository>
    <tag>${project.version}.${git.commit.id.abbrev}</tag>
    <buildArgs>
      <JAR_FILE>${project.build.finalName}.jar</JAR_FILE>
      <WAR_FILE>${project.build.finalName}.war</WAR_FILE>
    </buildArgs>
  </configuration>
</plugin>
mvn package  # 打包 war/jar ,并打包 docker image 
docker push register-domain-name/group-name/project-name:tag-name    # push image
## mvn deploy  # 需要提前配置 install 

注意:

  1. 镜像名称要全部小写,不然会报错 I/O exception https://github.com/spotify/dockerfile-maven/issues/123
  2. 需要在项目中准备Dockfile

ref:
https://itnext.io/tag-your-docker-images-while-building-with-maven-915c8043d2e0

jib 打包

      <plugin>
        <groupId>com.google.cloud.tools</groupId>
        <artifactId>jib-maven-plugin</artifactId>
        <version>0.10.0</version>
        <executions>
                <execution>
                <phase>install</phase>
                <goals>
                        <goal>build</goal>
                </goals>
                </execution>
        </executions>
        <configuration>
          <from><image>openjdk:8-jre-alpine</image></from>
          <to>
                <image>domain/group-name/project-name</image>
                <auth>
                <username>${env.REGISTRY_USERNAME}</username>
                <password>${env.REGISTRY_PASSWORD}</password>
                </auth>
                <tags>
                <tag>${project.version}-${git.commit.id.abbrev}</tag>
                <tag>latest</tag>
                </tags>
          </to>
        <allowInsecureRegistries>true</allowInsecureRegistries>
          <container>
            <!-- <args>WAR_FILE,JAR_FILE</args>  -->
            <appRoot>/usr/local/tomcat/webapps/${project.build.finalName}</appRoot>
            <ports>
                <port>8080</port>
                <port>8089</port>
            </ports>
            <entrypoint>
                <arg>/bin/sh</arg>
                <arg>-c</arg>
                <arg>catalina.sh run</arg>
            </entrypoint>
          </container>
        </configuration>
      </plugin>

jar 包自定义 entrypoint

 <entrypoint>
  <arg>/bin/sh</arg>
  <arg>-c</arg>
 <arg>java ${JAVA_OPTS} -cp /app/resources/:/app/classes/:/app/libs/* 
   com.example.JibDemoApplication</arg>
</entrypoint>


以上配置中, <phase>install</phase> ,只有在 mvn install 时才进行docker 镜像打包及上传。 mvn package 只进行war/jar 的打包。

#mvn compile jib:dockerBuild     # 打包本地镜像
#mvn clean compile package jib:dockerBuild        # 打包本地镜像并上传到仓库
 mvn install  # 打包本地镜像并上传到仓库

spotify/docker-maven-plugin

http://book.itmuch.com/3%20%E4%BD%BF%E7%94%A8Docker%E6%9E%84%E5%BB%BA%E5%BE%AE%E6%9C%8D%E5%8A%A1/3.7%20%E4%BD%BF%E7%94%A8Maven%E6%8F%92%E4%BB%B6%E6%9E%84%E5%BB%BADocker%E9%95%9C%E5%83%8F.html

bazel

相关文章

  • mvn 打包并自动上传 jar/war docker 镜像

    dockerfile-maven 打包 pom.xml加到 这一段代码后面 注意: 镜像名称要全部小写,不然会报错...

  • 【maven】常用命令

    mvn clean 清空该项目下的target文件 mvn package 把项目打包(jar包或war包) mv...

  • Docker入门

    Docker概述 Docker为什么会出现? 将项目打包并带上部署环境(镜像),上传到Docker 仓库,下载镜像...

  • 「Java面试必会」Maven常用命令

    Maven 3种打包方式的区别:mvn package项目打包,在项目target目录下生成编译后的jar或war...

  • maven操作命令

    mvn package 说明: 项目打包工具,会在模块下的target目录生成jar或war等文件,如下运行结果。...

  • maven项目打包命令

    maven项目打包首先需执行mvn clean命令清除编译所产生的文件(包括编译的class、jar、war) 再...

  • GitLab CI 实现 Golang 自动构建为 Docker

    实现目标 提交代码自动构建,自动打包为docker镜像 前期准备 Makefile 学习并使用 MakeFile ...

  • maven

    指定配置文件打包:开发: mvn package -Pdev mvn package :打包jar包mvn ins...

  • 使用Dockerfile构建镜像

    1. 准备工作 mvn clean package #使用maven打包项目; 2. 镜像构建 2.1 在jar包...

  • 2.Maven - 常用命令

    参考 1. 常用命令 清理mvn clean 编译mvn compile 打包说明pom.xml配置 war 打包...

网友评论

      本文标题:mvn 打包并自动上传 jar/war docker 镜像

      本文链接:https://www.haomeiwen.com/subject/rrrdcqtx.html