我正在使用 maven 和fabric8-maven-plugin
openshift 构建一个 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);
}
}