From 22a76a28180c8c5deff20470e28ae51c5de375bc Mon Sep 17 00:00:00 2001 From: Rudy De Busscher Date: Sun, 15 Sep 2019 20:45:53 +0200 Subject: [PATCH] Payara Micro and Payara Server adapter. Fixes #60 --- modules/payara-micro/build.gradle | 20 +++++++ .../containers/payara/PayaraMicroAdapter.java | 58 +++++++++++++++++++ ...d.testing.testcontainers.spi.ServerAdapter | 1 + .../src/main/resources/log4j.properties | 10 ++++ modules/payara-server/build.gradle | 20 +++++++ .../payara/PayaraServerAdapter.java | 56 ++++++++++++++++++ ...d.testing.testcontainers.spi.ServerAdapter | 1 + .../src/main/resources/log4j.properties | 10 ++++ 8 files changed, 176 insertions(+) create mode 100644 modules/payara-micro/build.gradle create mode 100644 modules/payara-micro/src/main/java/org/testcontainers/containers/payara/PayaraMicroAdapter.java create mode 100644 modules/payara-micro/src/main/resources/META-INF/services/org.microshed.testing.testcontainers.spi.ServerAdapter create mode 100644 modules/payara-micro/src/main/resources/log4j.properties create mode 100644 modules/payara-server/build.gradle create mode 100644 modules/payara-server/src/main/java/org/testcontainers/containers/payara/PayaraServerAdapter.java create mode 100644 modules/payara-server/src/main/resources/META-INF/services/org.microshed.testing.testcontainers.spi.ServerAdapter create mode 100644 modules/payara-server/src/main/resources/log4j.properties diff --git a/modules/payara-micro/build.gradle b/modules/payara-micro/build.gradle new file mode 100644 index 00000000..58d36cfc --- /dev/null +++ b/modules/payara-micro/build.gradle @@ -0,0 +1,20 @@ +plugins { + id 'maven-publish' +} + +publishing { + publications { + maven(MavenPublication) { + artifactId = 'microshed-testing-payara-micro' + from components.java + } + } +} + +description = "MicroShed Testing framework :: Payara Micro extensions" + +dependencies { + compile project(':microshed-testing-testcontainers') +} + +publishToMavenLocal.dependsOn ':microshed-testing-testcontainers:publishToMavenLocal' diff --git a/modules/payara-micro/src/main/java/org/testcontainers/containers/payara/PayaraMicroAdapter.java b/modules/payara-micro/src/main/java/org/testcontainers/containers/payara/PayaraMicroAdapter.java new file mode 100644 index 00000000..cffc04ce --- /dev/null +++ b/modules/payara-micro/src/main/java/org/testcontainers/containers/payara/PayaraMicroAdapter.java @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2019 Payara Services Corporation and others + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * 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.testcontainers.containers.payara; + +import org.microshed.testing.testcontainers.spi.ServerAdapter; +import org.testcontainers.images.builder.ImageFromDockerfile; + +import java.io.File; + +public class PayaraMicroAdapter implements ServerAdapter { + @Override + public int getDefaultHttpPort() { + return 8080; + } + + @Override + public int getDefaultHttpsPort() { + return 8181; + } + + @Override + public ImageFromDockerfile getDefaultImage(File appFile) { + String appName = appFile.getName(); + // Compose a docker image equivalent to doing: + // FROM payara/micro:5.193 + // CMD ["--deploymentDir", "/opt/payara/deployments", "--noCluster"] + // ADD target/myservice.war /opt/payara/deployments + ImageFromDockerfile image = new ImageFromDockerfile() + .withDockerfileFromBuilder(builder -> builder.from("payara/micro:5.193") + .cmd("--deploymentDir", "/opt/payara/deployments", "--noCluster") + .add(appName, "/opt/payara/deployments") + .build()) + .withFileFromFile(appName, appFile); + return image; + + } + + @Override + public String getReadinessPath() { + return "/health"; + } +} diff --git a/modules/payara-micro/src/main/resources/META-INF/services/org.microshed.testing.testcontainers.spi.ServerAdapter b/modules/payara-micro/src/main/resources/META-INF/services/org.microshed.testing.testcontainers.spi.ServerAdapter new file mode 100644 index 00000000..d333cb05 --- /dev/null +++ b/modules/payara-micro/src/main/resources/META-INF/services/org.microshed.testing.testcontainers.spi.ServerAdapter @@ -0,0 +1 @@ +org.testcontainers.containers.payara.PayaraMicroAdapter \ No newline at end of file diff --git a/modules/payara-micro/src/main/resources/log4j.properties b/modules/payara-micro/src/main/resources/log4j.properties new file mode 100644 index 00000000..c491db01 --- /dev/null +++ b/modules/payara-micro/src/main/resources/log4j.properties @@ -0,0 +1,10 @@ +log4j.rootLogger=INFO, stdout + +log4j.appender=org.apache.log4j.ConsoleAppender +log4j.appender.layout=org.apache.log4j.PatternLayout + +log4j.appender.stdout=org.apache.log4j.ConsoleAppender +log4j.appender.stdout.layout=org.apache.log4j.PatternLayout +log4j.appender.stdout.layout.ConversionPattern=%r %p %c %x - %m%n + +log4j.logger.org.aguibert.liberty=DEBUG \ No newline at end of file diff --git a/modules/payara-server/build.gradle b/modules/payara-server/build.gradle new file mode 100644 index 00000000..b3f31615 --- /dev/null +++ b/modules/payara-server/build.gradle @@ -0,0 +1,20 @@ +plugins { + id 'maven-publish' +} + +publishing { + publications { + maven(MavenPublication) { + artifactId = 'microshed-testing-payara-server' + from components.java + } + } +} + +description = "MicroShed Testing framework :: Payara Server extensions" + +dependencies { + compile project(':microshed-testing-testcontainers') +} + +publishToMavenLocal.dependsOn ':microshed-testing-testcontainers:publishToMavenLocal' diff --git a/modules/payara-server/src/main/java/org/testcontainers/containers/payara/PayaraServerAdapter.java b/modules/payara-server/src/main/java/org/testcontainers/containers/payara/PayaraServerAdapter.java new file mode 100644 index 00000000..c04e7764 --- /dev/null +++ b/modules/payara-server/src/main/java/org/testcontainers/containers/payara/PayaraServerAdapter.java @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2019 Payara Services Corporation and others + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * 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.testcontainers.containers.payara; + +import org.microshed.testing.testcontainers.spi.ServerAdapter; +import org.testcontainers.images.builder.ImageFromDockerfile; + +import java.io.File; + +public class PayaraServerAdapter implements ServerAdapter { + @Override + public int getDefaultHttpPort() { + return 8080; + } + + @Override + public int getDefaultHttpsPort() { + return 8181; + } + + @Override + public ImageFromDockerfile getDefaultImage(File appFile) { + String appName = appFile.getName(); + // Compose a docker image equivalent to doing: + // FROM payara/server-full:5.193 + // ADD target/myservice.war /opt/payara/deployments + ImageFromDockerfile image = new ImageFromDockerfile() + .withDockerfileFromBuilder(builder -> builder.from("payara/server-full:5.193") + .add(appName, "/opt/payara/deployments") + .build()) + .withFileFromFile(appName, appFile); + return image; + + } + + @Override + public String getReadinessPath() { + return "/health"; + } +} diff --git a/modules/payara-server/src/main/resources/META-INF/services/org.microshed.testing.testcontainers.spi.ServerAdapter b/modules/payara-server/src/main/resources/META-INF/services/org.microshed.testing.testcontainers.spi.ServerAdapter new file mode 100644 index 00000000..ef1f18f8 --- /dev/null +++ b/modules/payara-server/src/main/resources/META-INF/services/org.microshed.testing.testcontainers.spi.ServerAdapter @@ -0,0 +1 @@ +org.testcontainers.containers.payara.PayaraServerAdapter \ No newline at end of file diff --git a/modules/payara-server/src/main/resources/log4j.properties b/modules/payara-server/src/main/resources/log4j.properties new file mode 100644 index 00000000..c491db01 --- /dev/null +++ b/modules/payara-server/src/main/resources/log4j.properties @@ -0,0 +1,10 @@ +log4j.rootLogger=INFO, stdout + +log4j.appender=org.apache.log4j.ConsoleAppender +log4j.appender.layout=org.apache.log4j.PatternLayout + +log4j.appender.stdout=org.apache.log4j.ConsoleAppender +log4j.appender.stdout.layout=org.apache.log4j.PatternLayout +log4j.appender.stdout.layout.ConversionPattern=%r %p %c %x - %m%n + +log4j.logger.org.aguibert.liberty=DEBUG \ No newline at end of file