我正在为openshift构建一个带有maven和fabric8-maven-plugin
的spring-boot java应用程序。
我运行的命令行是:
mvn -Dfabric8.mode=openshift -Ddocker.skip=true clean install fabric8:resource fabric8:build fabric8:apply -Dfabric8.skipResourceValidation
我有我的openshift部署配置在:
demo/src/main/fabric8/deployment.yml
因此,我希望在名称空间my-namespace
中创建的deploymentConfig将具有如下图像触发器:
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>
demo/src/main/fabric8/deployml
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);
}
}
这是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 : $