Skip to content

Commit

Permalink
Merge pull request #106 from fabiobrz/add-eap7-provisioners.legacy-s2i
Browse files Browse the repository at this point in the history
[issue 80] - Add EAP 7 legacy s2i build provisioner
  • Loading branch information
marekkopecky authored Nov 14, 2023
2 parents f821c23 + 5928b3b commit e482315
Show file tree
Hide file tree
Showing 15 changed files with 487 additions and 22 deletions.
33 changes: 17 additions & 16 deletions README.md

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?xml version="1.0" encoding="UTF-8"?>
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.jboss.intersmash</groupId>
<artifactId>intersmash-deployments-shared-eap7</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

<artifactId>eap7-helloworld</artifactId>
<packaging>war</packaging>

<name>Intersmash Shared Deployments (EAP 7): Hello World Quickstart</name>

<properties>
<formatting-style-base-directory>${project.parent.parent.parent.parent.basedir}/ide-config</formatting-style-base-directory>
</properties>

<dependencies>
<!-- Import the CDI API, we use provided scope as the API is included in WildFly -->
<dependency>
<groupId>jakarta.inject</groupId>
<artifactId>jakarta.inject-api</artifactId>
<scope>provided</scope>
</dependency>
<!-- Import the Servlet API, we use provided scope as the API is included in WildFly -->
<dependency>
<groupId>org.jboss.spec.javax.servlet</groupId>
<artifactId>jboss-servlet-api_4.0_spec</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<warName>ROOT</warName>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2015, Red Hat, Inc. and/or its affiliates, and individual
* contributors by the @authors tag. See the copyright.txt in the
* distribution for a full listing of individual contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.as.quickstarts.helloworld;

/**
* A simple CDI service which is able to say hello to someone
*
* @author Pete Muir
*
*/
public class HelloService {

String createHelloMessage(String name) {
return "Hello " + name + "!";
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2015, Red Hat, Inc. and/or its affiliates, and individual
* contributors by the @authors tag. See the copyright.txt in the
* distribution for a full listing of individual contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.as.quickstarts.helloworld;

import java.io.IOException;
import java.io.PrintWriter;

import javax.inject.Inject;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
* <p>
* A simple servlet taking advantage of features added in 3.0.
* </p>
*
* <p>
* The servlet is registered and mapped to /HelloServlet using the {@linkplain WebServlet
* @HttpServlet}. The {@link HelloService} is injected by CDI.
* </p>
*
* @author Pete Muir
*
*/
@SuppressWarnings("serial")
@WebServlet("/HelloWorld")
public class HelloWorldServlet extends HttpServlet {

static String PAGE_HEADER = "<html><head><title>helloworld</title></head><body>";

static String PAGE_FOOTER = "</body></html>";

@Inject
HelloService helloService;

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
resp.setContentType("text/html");
PrintWriter writer = resp.getWriter();
writer.println(PAGE_HEADER);
writer.println("<h1>" + helloService.createHelloMessage("World") + "</h1>");
writer.println(PAGE_FOOTER);
writer.close();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<!--
JBoss, Home of Professional Open Source
Copyright 2015, Red Hat, Inc. and/or its affiliates, and individual
contributors by the @authors tag. See the copyright.txt in the
distribution for a full listing of individual contributors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<!-- Marker file indicating CDI should be enabled -->
<beans xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/beans_1_1.xsd"
bean-discovery-mode="all">
</beans>

Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<!--
JBoss, Home of Professional Open Source
Copyright 2015, Red Hat, Inc. and/or its affiliates, and individual
contributors by the @authors tag. See the copyright.txt in the
distribution for a full listing of individual contributors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<!-- Plain HTML page that kicks us into the app -->

<html>
<head>
<meta http-equiv="Refresh" content="0; URL=HelloWorld">
</head>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?xml version="1.0" encoding="UTF-8"?>
<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.jboss.intersmash</groupId>
<artifactId>intersmash-deployments-shared</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<packaging>pom</packaging>
<artifactId>intersmash-deployments-shared-eap7</artifactId>

<name>Intersmash Shared Deployments: EAP 7 aggregator</name>

<properties>
<!-- EAP 7 deployments must run on JDK 8 too -->
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<!-- Default EAP 7 version -->
<jboss-eap7.version>7.4.13.GA</jboss-eap7.version>
<!-- Default EAP `ee` BOMs version is set here for pulling the right EAP BOM -->
<bom.jboss-eap7-jakartaee.groupId>org.jboss.bom</bom.jboss-eap7-jakartaee.groupId>
<bom.jboss-eap7jakartaee.artifactId>jboss-eap-jakartaee8</bom.jboss-eap7jakartaee.artifactId>
<bom.jboss-eap7-jakartaee.version>${jboss-eap7.version}</bom.jboss-eap7-jakartaee.version>
</properties>

<modules>
<module>eap7-helloworld</module>
</modules>

<dependencyManagement>
<dependencies>
<!-- Lock all the provided dependencies to match the WildFly/EAP version -->
<dependency>
<groupId>${bom.jboss-eap7-jakartaee.groupId}</groupId>
<artifactId>${bom.jboss-eap7jakartaee.artifactId}</artifactId>
<version>${bom.jboss-eap7-jakartaee.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
</project>
1 change: 1 addition & 0 deletions deployments/intersmash-deployments-shared/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

<modules>
<module>intersmash-deployments-shared-wildfly</module>
<module>intersmash-deployments-shared-eap7</module>
</modules>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package org.jboss.intersmash.testsuite.junit5.categories;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
Expand All @@ -27,6 +28,6 @@
*/
@Tag("ts.not-for-community")
@Retention(RetentionPolicy.RUNTIME)
@Target({ java.lang.annotation.ElementType.TYPE })
@Target({ java.lang.annotation.ElementType.TYPE, ElementType.METHOD })
public @interface NotForCommunityExecutionProfile {
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.jboss.intersmash.tools.IntersmashConfig;
import org.jboss.intersmash.tools.application.openshift.BootableJarOpenShiftApplication;
import org.jboss.intersmash.tools.application.openshift.Eap7ImageOpenShiftApplication;
import org.jboss.intersmash.tools.application.openshift.Eap7LegacyS2iBuildTemplateApplication;
import org.jboss.intersmash.tools.application.openshift.Eap7TemplateOpenShiftApplication;
import org.jboss.intersmash.tools.application.openshift.KafkaOperatorApplication;
import org.jboss.intersmash.tools.application.openshift.MysqlImageOpenShiftApplication;
Expand All @@ -42,10 +43,12 @@
import org.jboss.intersmash.tools.application.openshift.input.BuildInput;
import org.jboss.intersmash.tools.application.openshift.input.BuildInputBuilder;
import org.jboss.intersmash.tools.application.openshift.template.Eap7Template;
import org.jboss.intersmash.tools.util.openshift.WildflyOpenShiftUtils;
import org.jboss.intersmash.tools.util.wildfly.Eap7CliScriptBuilder;

import cz.xtf.builder.builders.SecretBuilder;
import cz.xtf.builder.builders.secret.SecretType;
import cz.xtf.core.config.OpenShiftConfig;
import io.fabric8.kubernetes.api.model.EnvVar;
import io.fabric8.kubernetes.api.model.EnvVarBuilder;
import io.fabric8.kubernetes.api.model.Secret;
Expand Down Expand Up @@ -118,6 +121,51 @@ public String getName() {
};
}

public static Eap7LegacyS2iBuildTemplateApplication getEap7LegacyS2iBuildTemplateApplication() {
return new Eap7LegacyS2iBuildTemplateApplication() {
private String eapImage;
private String eapRuntimeImage;
private final Map<String, String> parameters;
private final List<EnvVar> envVars;

{
eapImage = WildflyOpenShiftUtils.importBuilderImage(IntersmashConfig.eap7ImageURL()).getMetadata().getName();
eapRuntimeImage = WildflyOpenShiftUtils.importRuntimeImage(IntersmashConfig.eap7RuntimeImageUrl()).getMetadata()
.getName();
String deployment = "deployments/intersmash-deployments-shared/intersmash-deployments-shared-eap7/eap7-helloworld";
//params
parameters = new HashMap<>();
parameters.put("APPLICATION_IMAGE", getName());
parameters.put("EAP_IMAGE", eapImage);
parameters.put("EAP_RUNTIME_IMAGE", eapRuntimeImage);
parameters.put("EAP_IMAGESTREAM_NAMESPACE", OpenShiftConfig.namespace());
parameters.put("SOURCE_REPOSITORY_URL", IntersmashConfig.deploymentsRepositoryUrl());
parameters.put("SOURCE_REPOSITORY_REF", IntersmashConfig.deploymentsRepositoryRef());
parameters.put("ARTIFACT_DIR", deployment + "/target");

// envvars
envVars = new ArrayList<>();
// Set to allow cloning from Gitlab - any value here do the job
envVars.add(new EnvVarBuilder().withName("GIT_SSL_NO_VERIFY").withValue("").build());
}

@Override
public List<EnvVar> getEnvVars() {
return envVars;
}

@Override
public Map<String, String> getParameters() {
return parameters;
}

@Override
public String getName() {
return "eap-s2i-build-application";
}
};
}

static BootableJarOpenShiftApplication getWildflyBootableJarOpenShiftApplication() {
return new BootableJarOpenShiftApplication() {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,15 @@
import java.util.stream.Stream;

import org.jboss.intersmash.testsuite.IntersmashTestsuiteProperties;
import org.jboss.intersmash.testsuite.junit5.categories.NotForCommunityExecutionProfile;
import org.jboss.intersmash.tools.provision.openshift.Eap7LegacyS2iBuildTemplateProvisioner;
import org.jboss.intersmash.tools.provision.openshift.MysqlImageOpenShiftProvisioner;
import org.jboss.intersmash.tools.provision.openshift.OpenShiftProvisioner;
import org.jboss.intersmash.tools.provision.openshift.PostgreSQLImageOpenShiftProvisioner;
import org.jboss.intersmash.tools.provision.openshift.WildflyBootableJarImageOpenShiftProvisioner;
import org.jboss.intersmash.tools.provision.openshift.WildflyImageOpenShiftProvisioner;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;

Expand Down Expand Up @@ -80,4 +83,31 @@ public void testProvisioningWorkflowCleanup(OpenShiftProvisioner provisioner) {
openShift.configMaps().withName("no-delete").delete();
openShift.waiters().isProjectClean().waitFor();
}

/**
* EapS2iBuild application requires additional image streams to be created. CleanBeforeEach would delete it if the
* provisioner is initialized in {@link #provisionerProvider()}, so we need a separate test method.
*/
@Test
@NotForCommunityExecutionProfile
public void eap7LegacyS2iBuild() {
Eap7LegacyS2iBuildTemplateProvisioner provisioner = new Eap7LegacyS2iBuildTemplateProvisioner(
OpenShiftProvisionerTestBase.getEap7LegacyS2iBuildTemplateApplication());
provisioner.preDeploy();
provisioner.deploy();
openShift.configMaps().create(new ConfigMapBuilder().withNewMetadata().withName("no-delete").endMetadata().build());
provisioner.undeploy();
provisioner.postUndeploy();
Assertions.assertNotNull(openShift.configMaps().withName("no-delete").get());
openShift.configMaps().withName("no-delete").delete();
// delete the images streams created by EapS2iBuildTemplateApplication
openShift.imageStreams()
.withName(((String) provisioner.getApplication().getParameters().get("EAP_IMAGE")).split(":")[0])
.delete();
openShift.imageStreams()
.withName(((String) provisioner.getApplication().getParameters().get("EAP_RUNTIME_IMAGE")).split(":")[0])
.delete();

openShift.waiters().isProjectClean().waitFor();
}
}
Loading

0 comments on commit e482315

Please sign in to comment.