0

我正在使用 maven 和fabric8-maven-pluginopenshift 构建一个 Spring Boot Java 应用程序。

我正在运行的命令行是:

mvn -Dfabric8.mode=openshift -Ddocker.skip=true clean install fabric8:resource fabric8:build fabric8:apply -Dfabric8.skipResourceValidation

我的 openshift deploymentConfig 在:

demo/src/main/fabric8/deployment.yml

因此,我希望命名空间中创建的 deploymentConfigmy-namespace将具有如下图像触发器:

apiVersion: apps.openshift.io/v1
kind: DeploymentConfig
metadata:
...
spec:
....
  test: false
  triggers:
    - imageChangeParams:
        automatic: true
        containerNames:
          - demo
        from:
          kind: ImageStreamTag
          name: 'demo:latest'
          namespace: my-namespace
      type: ImageChange

但事实并非如此。关于为什么未在生成的部署配置中创建图像触发器的任何建议?

下面的一些更多细节:

pom.xml:

<project xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

  <parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
     <version>2.1.8.RELEASE</version>
    <relativePath /> <!-- lookup parent from repository -->
  </parent> 

    <groupId>com.samples</groupId>
    <artifactId>demo</artifactId>
    <version>1.0.0-SNAPSHOT</version>
    <packaging>jar</packaging>

    <properties>
        <fabric8-maven-plugin.version>4.4.0</fabric8-maven-plugin.version>
        <!--
      <fabric8.enricher.fmp-openshift-imageChangeTrigger.enrichAll>true</fabric8.enricher.fmp-openshift-imageChangeTrigger.enrichAll>
      <fabric8.openshift.enrichAllWithImageChangeTrigger>true</fabric8.openshift.enrichAllWithImageChangeTrigger>
        -->
    </properties>


  <dependencies>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter</artifactId>
    </dependency>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-web</artifactId>
    </dependency>

    <dependency>
      <groupId>net.logstash.logback</groupId>
      <artifactId>logstash-logback-encoder</artifactId>
      <version>4.10</version>
    </dependency>

  </dependencies>   


    <build>
    <plugins>
      <plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
      </plugin>     


      <plugin>
        <groupId>io.fabric8</groupId>
        <artifactId>fabric8-maven-plugin</artifactId>
        <version>${fabric8-maven-plugin.version}</version>
        <configuration>
          <images>
            <image>
              <name>${project.artifactId}</name>
              <build>
                <fromExt>
                  <name>openjdk18-openshift:1.6-16</name>
                  <namespace>internal</namespace>
                  <kind>ImageStreamTag</kind>
                </fromExt>                
                <assembly>
                  <basedir>/deployments</basedir>
                  <descriptorRef>rootWar</descriptorRef>
                </assembly>
                <env>
                  <JAVA_APP_DIR>/deployments</JAVA_APP_DIR>
                </env>
              </build>
            </image>
          </images>
        </configuration>
      </plugin>

        </plugins>
    </build>
</project>

演示/src/main/fabric8/deployment.yml

spec:
  replicas: 1
  strategy:
    activeDeadlineSeconds: 21600
    recreateParams:
      timeoutSeconds: 600
    type: Recreate
  template:
    metadata:
      labels:
        group: com.samples
        project: demo
        provider: fabric8
    spec:
      containers:
      - args:
         - /usr/local/s2i/run
        name: demo
        env:
          - name: JAVA_APP_JAR
            value: /deployments/ROOT.war        

src/main/java/com/samples/DemoApplication.java

package com.samples;

import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class DemoApplication {
  private static final org.slf4j.Logger log = LoggerFactory.getLogger(DemoApplication.class);

  private String name = "demoApplicationName";

  public String getName() {
    return name;
  }

  public static void main(String[] args) {
    SpringApplication.run(DemoApplication.class, args);
  }
}
4

1 回答 1

0

这是 Fabric8 Maven 插件中的一个错误,已修复。它在v4.4.1. 我们现在正在努力将 Fabric8 Maven 插件重新命名为Eclipse JKube。如果您可以尝试一下,将不胜感激(它与 FMP 相同,只是没有 Fabric8 品牌名称)。将来,Fabric8 Maven 插件将被标记为已弃用,以支持 Eclipse JKube。我在 pom.xml 中使用您提供的代码和 Eclipse JKube 创建了一个简单的项目:

https://github.com/r0haaaan/fmp-openshift-sample-with-fragments

运行oc:resource目标后,您可以看到现在正在生成触发器:

~/work/repos/fmp-samples/fmp-openshift-sample-with-fragments : $ mvn oc:resource
[INFO] Scanning for projects...
[INFO] 
[INFO] --------------------------< com.samples:demo >--------------------------
[INFO] Building demo 1.0.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- openshift-maven-plugin:1.0.0-alpha-2:resource (default-cli) @ demo ---
[INFO] oc: Using docker image name of namespace: rokumar
[INFO] oc: Running generator spring-boot
[INFO] oc: spring-boot: Using Docker image fabric8/java-centos-openjdk8-jdk:1.5.6 as base / builder
[INFO] oc: using resource templates from /home/rohaan/work/repos/fmp-samples/fmp-openshift-sample-with-fragments/src/main/jkube
[INFO] oc: jkube-service: Adding a default service 'demo' with ports [8080]
[INFO] oc: jkube-revision-history: Adding revision history limit to 2
[INFO] oc: validating /home/rohaan/work/repos/fmp-samples/fmp-openshift-sample-with-fragments/target/classes/META-INF/jkube/openshift/demo-service.yml resource
[INFO] oc: validating /home/rohaan/work/repos/fmp-samples/fmp-openshift-sample-with-fragments/target/classes/META-INF/jkube/openshift/demo-deploymentconfig.yml resource
[INFO] oc: validating /home/rohaan/work/repos/fmp-samples/fmp-openshift-sample-with-fragments/target/classes/META-INF/jkube/openshift/demo-route.yml resource
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  11.535 s
[INFO] Finished at: 2020-05-05T21:27:24+05:30
[INFO] ------------------------------------------------------------------------
~/work/repos/fmp-samples/fmp-openshift-sample-with-fragments : $ cat /home/rohaan/work/repos/fmp-samples/fmp-openshift-sample-with-fragments/target/classes/META-INF/jkube/openshift/demo-deploymentconfig.yml | tail -n10
  triggers:
  - type: ConfigChange
  - imageChangeParams:
      automatic: true
      containerNames:
      - demo
      from:
        kind: ImageStreamTag
        name: demo:latest
    type: ImageChange
~/work/repos/fmp-samples/fmp-openshift-sample-with-fragments : $ 
于 2020-05-05T16:07:39.217 回答