maven的dockerfile的坑

pom.xml

<plugin>
  <groupId>com.spotify</groupId>
  <artifactId>dockerfile-maven-plugin</artifactId>
  <version>2.0</version>
  <executions>
    <execution>
      <!--开启DOCKER编译工具-->
      <id>default</id>
      <goals>
        <!--如果package时不想用docker打包,就注释掉这个goal-->
        <goal>build</goal> <!--编译-->
        <goal>push</goal> <!--推送功能-->
      </goals>
    </execution>
  </executions>
  <configuration>
    <!--私有镜像仓库用户名 -->
    <username>XX</username>
    <!--私有镜像仓库密码-->
    <password>XX</password>
    <!--相当于给镜像打个TAG -->
    <repository>registry.xx.com/platform/${project.artifactId}</repository>
    <!--镜像版本-->
    <tag>${project.version}-${profiles.active}</tag>
    <!-- 根据选择的profiles使用不同的dockerfile打包 -->
    <dockerfile>Dockerfile-${profiles.active}</dockerfile>
    <namespace>-platform-test</namespace>
    <deployment>xxApp</deployment>
    <buildArgs>
      <!--提供参数向Dockerfile传递-->
      <JAR_FILE>target/${project.build.finalName}.jar</JAR_FILE>
    </buildArgs>
  </configuration>
</plugin>


这个使用mvn clean package -Dmaven.test.skip=true -P prd

这里的prd参数不好用,在父pom.xml里profiles里只留下prd才行。

<profiles>
    <profile>
        <!-- 正式环境 -->
        <id>prd</id>
        <properties>
            <profiles.active>prd</profiles.active>
        </properties>
        <activation>
            <activeByDefault>true</activeByDefault>
        </activation>
    </profile>


</profiles>

而pom.xml配置了build与run,只有build能生效。

文/程忠 浏览次数:0次   2023-10-08 18:04:07

相关阅读


评论:
点击刷新

↓ 广告开始-头部带绿为生活 ↓
↑ 广告结束-尾部支持多点击 ↑