Skip to content

Commit

Permalink
feat: WebAppGenerator Jetty handler uses jkube/jkube-jetty9-binary-s2…
Browse files Browse the repository at this point in the history
…i for Docker and S2I builds

Signed-off-by: Marc Nuri <[email protected]>
  • Loading branch information
manusa committed May 25, 2020
1 parent d4adb57 commit 8fc6f14
Show file tree
Hide file tree
Showing 11 changed files with 186 additions and 158 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ Usage:
* Fix #205: JavaExecGenerator uses jkube/jkube-java-binary-s2i for Docker and S2I builds (#183)
* Fix #206: WebAppGenerator with "/" path renames artifacts to ROOT.war
* Fix #206: WebAppGenerator>TomcatAppSeverHandler uses quay.io/jkube/jkube-tomcat9-binary-s2i as base image
* Fix #210: WebAppGenerator>JettyAppSeverHandler uses quay.io/jkube/jkube-jetty9-binary-s2i as base image

### 1.0.0-alpha-3 (2020-05-06)
* Fix #167: Add CMD for wildfly based applications
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,18 @@ public interface AppServerHandler {
/**
* Get the user to use. Return null if no specific user directive is required
*/
String getUser();
default String getUser() {
return null;
}

/**
* A list of ports which are exposed by the base image
*
* @return list of ports to expos
*/
List<String> exposedPorts();
default List<String> exposedPorts(){
return Collections.singletonList("8080");
}

/**
* A Map containing environment variables to add to the Image.
Expand All @@ -88,7 +92,7 @@ default Map<String, String> getEnv() {
* @return the assembly name.
*/
default String getAssemblyName() {
return null;
return "deployments";
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ public String getFrom() {
return from;
}

@Override
public String getAssemblyName() {
return null;
}

@Override
public String getDeploymentDir() {
return deploymentDir;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
package org.eclipse.jkube.generator.webapp.handler;

import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Stream;

import org.eclipse.jkube.generator.api.GeneratorContext;
import org.eclipse.jkube.kit.common.util.JKubeProjectUtil;
Expand All @@ -27,45 +26,50 @@
*/
public class JettyAppSeverHandler extends AbstractAppServerHandler {

private static final String JETTY_MAVEN_PLUGIN_ARTIFACT_ID = "jetty-maven-plugin";

public JettyAppSeverHandler(GeneratorContext context) {
super("jetty", context);
}
public JettyAppSeverHandler(GeneratorContext context) {
super("jetty", context);
}

@Override
public boolean isApplicable() {
try {
return hasOneOf("glob:**/WEB-INF/jetty-web.xml",
"glob:**/META-INF/jetty-logging.properties") ||
JKubeProjectUtil.hasPlugin(getProject(), "org.mortbay.jetty", "jetty-maven-plugin") ||
JKubeProjectUtil.hasPlugin(getProject(), "org.eclipse.jetty", "jetty-maven-plugin");
} catch (IOException exception) {
throw new IllegalStateException("Unable to scan output directory: ", exception);
}
@Override
public boolean isApplicable() {
try {
return isJettyWebApp() || hasJettyMavenPlugin();
} catch (IOException exception) {
throw new IllegalStateException("Unable to scan output directory: ", exception);
}
}

@Override
public String getFrom() {
return imageLookup.getImageName("jetty.upstream.docker");
}
private boolean isJettyWebApp() throws IOException {
return hasOneOf(
"glob:**/WEB-INF/jetty-web.xml",
"glob:**/META-INF/jetty-logging.properties"
);
}

@Override
public List<String> exposedPorts() {
return Arrays.asList("8080","8778");
}
private boolean hasJettyMavenPlugin() {
return Stream.of("org.mortbay.jetty", "org.eclipse.jetty")
.anyMatch(groupId -> JKubeProjectUtil.hasPlugin(getProject(), groupId, JETTY_MAVEN_PLUGIN_ARTIFACT_ID));
}

@Override
public String getDeploymentDir() {
return "/deployments";
}
@Override
public String getFrom() {
return imageLookup.getImageName("jetty.upstream.docker");
}

@Override
public String getCommand() {
return "/opt/jetty/bin/deploy-and-run.sh";
}
@Override
public String getDeploymentDir() {
return "/deployments";
}

@Override
public String getUser() {
return "jboss:jboss:jboss";
}
@Override
public String getCommand() {
return "/usr/local/s2i/run";
}

@Override
public boolean supportsS2iBuild() {
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
package org.eclipse.jkube.generator.webapp.handler;

import java.io.IOException;
import java.util.Collections;
import java.util.List;
import java.util.stream.Stream;

import org.eclipse.jkube.generator.api.GeneratorContext;
Expand Down Expand Up @@ -53,31 +51,16 @@ public String getFrom() {
return imageLookup.getImageName("tomcat.upstream.docker");
}

@Override
public List<String> exposedPorts() {
return Collections.singletonList("8080");
}

@Override
public String getDeploymentDir() {
return "/deployments";
}

@Override
public String getAssemblyName() {
return "deployments";
}

@Override
public String getCommand() {
return "/usr/local/s2i/run";
}

@Override
public String getUser() {
return null;
}

@Override
public boolean supportsS2iBuild() {
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,6 @@ public String getFrom() {
return fromSelector.getFrom();
}

@Override
public List<String> exposedPorts() {
return Collections.singletonList("8080");
}

@Override
public String getDeploymentDir() {
// Applicable for Docker image - ignored for s2i
Expand All @@ -107,10 +102,6 @@ public Map<String, String> getEnv() {
return Collections.singletonMap("GALLEON_PROVISION_LAYERS", "cloud-server,web-clustering");
}

@Override
public String getAssemblyName() {
return "deployments";
}

@Override
public String getUser() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
/**
* Copyright (c) 2019 Red Hat, Inc.
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at:
*
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Red Hat, Inc. - initial API and implementation
*/
package org.eclipse.jkube.generator.webapp.handler;

import java.io.File;
import java.io.IOException;
import java.util.Collections;

import org.eclipse.jkube.generator.api.GeneratorContext;
import org.eclipse.jkube.kit.common.Plugin;

import mockit.Expectations;
import mockit.Mocked;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.nullValue;
import static org.hamcrest.Matchers.startsWith;
import static org.junit.Assert.assertTrue;

public class JettyAppSeverHandlerTest {

@Rule
public TemporaryFolder temporaryFolder = new TemporaryFolder();

@Mocked
private GeneratorContext generatorContext;

@Test
public void isApplicableHasJettyLoggingShouldReturnTrue() throws IOException {
// Given
// @formatter:off
new Expectations() {{
generatorContext.getProject().getBuildDirectory(); result = temporaryFolder.getRoot();
}};
// @formatter:on
assertTrue(new File(temporaryFolder.newFolder("META-INF"), "jetty-logging.properties").createNewFile());
assertTrue(new File(temporaryFolder.newFolder("META-INF-1337"), "context.xml").createNewFile());
// When
final boolean result = new JettyAppSeverHandler(generatorContext).isApplicable();
// Then
assertThat(result, equalTo(true));
}

@Test
public void isApplicableHasNotJettyLoggingShouldReturnFalse() throws IOException {
// Given
// @formatter:off
new Expectations() {{
generatorContext.getProject().getBuildDirectory(); result = temporaryFolder.getRoot();
}};
// @formatter:on
assertTrue(new File(temporaryFolder.newFolder("META-INF-1337"), "context.xml").createNewFile());
// When
final boolean result = new JettyAppSeverHandler(generatorContext).isApplicable();
// Then
assertThat(result, equalTo(false));
}

@Test
public void isApplicableHasJettyMavenPluginShouldReturnTrue(@Mocked Plugin plugin) {
// Given
// @formatter:off
new Expectations() {{
generatorContext.getProject().getBuildDirectory(); result = temporaryFolder.getRoot();
plugin.getGroupId(); result = "org.eclipse.jetty";
plugin.getArtifactId(); result = "jetty-maven-plugin";
generatorContext.getProject().getPlugins(); result = Collections.singletonList(plugin);
}};
// @formatter:on
// When
final boolean result = new JettyAppSeverHandler(generatorContext).isApplicable();
// Then
assertThat(result, equalTo(true));
}

@Test
public void isApplicableHasJetty1337MavenPluginShouldReturnFalse(@Mocked Plugin plugin) {
// Given
// @formatter:off
new Expectations() {{
generatorContext.getProject().getBuildDirectory(); result = temporaryFolder.getRoot();
plugin.getGroupId(); result = "org.eclipse.jetty";
plugin.getArtifactId(); result = "jetty1337-maven-plugin";
generatorContext.getProject().getPlugins(); result = Collections.singletonList(plugin);
}};
// @formatter:on
// When
final boolean result = new JettyAppSeverHandler(generatorContext).isApplicable();
// Then
assertThat(result, equalTo(false));
}

@Test
public void handlerSettings() {
// When
final JettyAppSeverHandler handler = new JettyAppSeverHandler(generatorContext);
// Then
assertThat(handler.getFrom(), startsWith("quay.io/jkube/jkube-jetty9-binary-s2i:"));
assertThat(handler.exposedPorts(), contains("8080"));
assertThat(handler.getDeploymentDir(), equalTo("/deployments"));
assertThat(handler.getAssemblyName(), equalTo("deployments"));
assertThat(handler.getCommand(), equalTo("/usr/local/s2i/run"));
assertThat(handler.getUser(), nullValue());
assertThat(handler.supportsS2iBuild(), equalTo(true));
}
}
10 changes: 5 additions & 5 deletions jkube-kit/parent/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@
<!-- ======================================================= -->
<!-- === Java base image versions for docker, s2i (istag == s2i) -->
<!-- Upstream -->
<version.image.java.upstream.docker>0.0.2</version.image.java.upstream.docker>
<version.image.java.upstream.s2i>0.0.2</version.image.java.upstream.s2i>
<version.image.java.upstream.docker>0.0.3</version.image.java.upstream.docker>
<version.image.java.upstream.s2i>0.0.3</version.image.java.upstream.s2i>

<!-- RedHat -->
<version.image.java.redhat.docker>2.0</version.image.java.redhat.docker>
Expand All @@ -96,8 +96,8 @@

<!-- ======================================================= -->
<!-- Servlet container images -->
<version.image.tomcat.upstream>0.0.2</version.image.tomcat.upstream>
<version.image.jetty.upstream>1.5.1</version.image.jetty.upstream>
<version.image.tomcat.upstream>0.0.3</version.image.tomcat.upstream>
<version.image.jetty.upstream>0.0.3</version.image.jetty.upstream>
<version.image.wildfly.upstream.docker>19.0.0.Final</version.image.wildfly.upstream.docker>
<version.image.wildfly.upstream.s2i>19.0</version.image.wildfly.upstream.s2i>

Expand Down Expand Up @@ -125,7 +125,7 @@

<!-- webapp -->
<image.tomcat.upstream>quay.io/jkube/jkube-tomcat9-binary-s2i:${version.image.tomcat.upstream}</image.tomcat.upstream>
<image.jetty.upstream>fabric8/jetty-9:${version.image.jetty.upstream}</image.jetty.upstream>
<image.jetty.upstream>quay.io/jkube/jkube-jetty9-binary-s2i:${version.image.jetty.upstream}</image.jetty.upstream>
<image.wildfly.upstream.docker>jboss/wildfly:${version.image.wildfly.upstream.docker}</image.wildfly.upstream.docker>
<image.wildfly.upstream.s2i>quay.io/wildfly/wildfly-centos7:${version.image.wildfly.upstream.s2i}</image.wildfly.upstream.s2i>
<image.wildfly.upstream.istag>wildfly:${version.image.wildfly.upstream.s2i}</image.wildfly.upstream.istag>
Expand Down
Loading

0 comments on commit 8fc6f14

Please sign in to comment.