You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by bd...@apache.org on 2019/07/04 10:05:24 UTC
[sling-whiteboard] 01/04: Initial Quarkus.io skeleton
This is an automated email from the ASF dual-hosted git repository.
bdelacretaz pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-whiteboard.git
commit d82c48b4f0eefd19fb479fbdc12ac0b8c4599810
Author: Bertrand Delacretaz <bd...@apache.org>
AuthorDate: Thu Jul 4 11:56:18 2019 +0200
Initial Quarkus.io skeleton
---
graalvm/README.md | 2 +
graalvm/pom.xml | 114 ++++++++++++++++
graalvm/src/main/docker/Dockerfile.jvm | 22 +++
graalvm/src/main/docker/Dockerfile.native | 22 +++
.../org/apache/sling/serverless/HelloResource.java | 17 +++
.../main/resources/META-INF/resources/index.html | 152 +++++++++++++++++++++
graalvm/src/main/resources/application.properties | 2 +
.../apache/sling/serverless/HelloResourceTest.java | 21 +++
.../sling/serverless/NativeHelloResourceIT.java | 9 ++
9 files changed, 361 insertions(+)
diff --git a/graalvm/README.md b/graalvm/README.md
new file mode 100644
index 0000000..bec2eb0
--- /dev/null
+++ b/graalvm/README.md
@@ -0,0 +1,2 @@
+# sling-graalvm
+Experimenting with GraalVM to run Apache Sling modules
diff --git a/graalvm/pom.xml b/graalvm/pom.xml
new file mode 100644
index 0000000..3146161
--- /dev/null
+++ b/graalvm/pom.xml
@@ -0,0 +1,114 @@
+<?xml version="1.0"?>
+<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.apache.sling</groupId>
+ <artifactId>org.apache.sling.serverless.osgimocks</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ <properties>
+ <surefire-plugin.version>2.22.0</surefire-plugin.version>
+ <maven.compiler.target>1.8</maven.compiler.target>
+ <maven.compiler.source>1.8</maven.compiler.source>
+ <quarkus.version>0.18.0</quarkus.version>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
+ </properties>
+ <dependencyManagement>
+ <dependencies>
+ <dependency>
+ <groupId>io.quarkus</groupId>
+ <artifactId>quarkus-bom</artifactId>
+ <version>${quarkus.version}</version>
+ <type>pom</type>
+ <scope>import</scope>
+ </dependency>
+ </dependencies>
+ </dependencyManagement>
+ <dependencies>
+ <dependency>
+ <groupId>io.quarkus</groupId>
+ <artifactId>quarkus-resteasy</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>io.quarkus</groupId>
+ <artifactId>quarkus-junit5</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>io.rest-assured</groupId>
+ <artifactId>rest-assured</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>io.quarkus</groupId>
+ <artifactId>quarkus-maven-plugin</artifactId>
+ <version>${quarkus.version}</version>
+ <executions>
+ <execution>
+ <goals>
+ <goal>build</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <version>${surefire-plugin.version}</version>
+ <configuration>
+ <systemProperties>
+ <java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
+ </systemProperties>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ <profiles>
+ <profile>
+ <id>native</id>
+ <activation>
+ <property>
+ <name>native</name>
+ </property>
+ </activation>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>io.quarkus</groupId>
+ <artifactId>quarkus-maven-plugin</artifactId>
+ <version>${quarkus.version}</version>
+ <executions>
+ <execution>
+ <goals>
+ <goal>native-image</goal>
+ </goals>
+ <configuration>
+ <enableHttpUrlHandler>true</enableHttpUrlHandler>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <artifactId>maven-failsafe-plugin</artifactId>
+ <version>${surefire-plugin.version}</version>
+ <executions>
+ <execution>
+ <goals>
+ <goal>integration-test</goal>
+ <goal>verify</goal>
+ </goals>
+ <configuration>
+ <systemProperties>
+ <native.image.path>${project.build.directory}/${project.build.finalName}-runner</native.image.path>
+ </systemProperties>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+ </profile>
+ </profiles>
+</project>
diff --git a/graalvm/src/main/docker/Dockerfile.jvm b/graalvm/src/main/docker/Dockerfile.jvm
new file mode 100644
index 0000000..9aee95d
--- /dev/null
+++ b/graalvm/src/main/docker/Dockerfile.jvm
@@ -0,0 +1,22 @@
+####
+# This Dockerfile is used in order to build a container that runs the Quarkus application in JVM mode
+#
+# Before building the docker image run:
+#
+# mvn package
+#
+# Then, build the image with:
+#
+# docker build -f src/main/docker/Dockerfile.jvm -t quarkus/org.apache.sling.serverless.osgimocks-jvm .
+#
+# Then run the container using:
+#
+# docker run -i --rm -p 8080:8080 quarkus/org.apache.sling.serverless.osgimocks-jvm
+#
+###
+FROM fabric8/java-alpine-openjdk8-jre
+ENV JAVA_OPTIONS="-Dquarkus.http.host=0.0.0.0 -Djava.util.logging.manager=org.jboss.logmanager.LogManager"
+ENV AB_ENABLED=jmx_exporter
+COPY target/lib/* /deployments/lib/
+COPY target/*-runner.jar /deployments/app.jar
+ENTRYPOINT [ "/deployments/run-java.sh" ]
\ No newline at end of file
diff --git a/graalvm/src/main/docker/Dockerfile.native b/graalvm/src/main/docker/Dockerfile.native
new file mode 100644
index 0000000..cac18ad
--- /dev/null
+++ b/graalvm/src/main/docker/Dockerfile.native
@@ -0,0 +1,22 @@
+####
+# This Dockerfile is used in order to build a container that runs the Quarkus application in native (no JVM) mode
+#
+# Before building the docker image run:
+#
+# mvn package -Pnative -Dnative-image.docker-build=true
+#
+# Then, build the image with:
+#
+# docker build -f src/main/docker/Dockerfile.native -t quarkus/org.apache.sling.serverless.osgimocks .
+#
+# Then run the container using:
+#
+# docker run -i --rm -p 8080:8080 quarkus/org.apache.sling.serverless.osgimocks
+#
+###
+FROM registry.access.redhat.com/ubi8/ubi-minimal
+WORKDIR /work/
+COPY target/*-runner /work/application
+RUN chmod 775 /work
+EXPOSE 8080
+CMD ["./application", "-Dquarkus.http.host=0.0.0.0"]
\ No newline at end of file
diff --git a/graalvm/src/main/java/org/apache/sling/serverless/HelloResource.java b/graalvm/src/main/java/org/apache/sling/serverless/HelloResource.java
new file mode 100644
index 0000000..790193b
--- /dev/null
+++ b/graalvm/src/main/java/org/apache/sling/serverless/HelloResource.java
@@ -0,0 +1,17 @@
+package org.apache.sling.serverless;
+
+import java.util.Date;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+
+@Path("/hello")
+public class HelloResource {
+
+ @GET
+ @Produces(MediaType.TEXT_PLAIN)
+ public String hello() {
+ return "hello, at " + new Date();
+ }
+}
\ No newline at end of file
diff --git a/graalvm/src/main/resources/META-INF/resources/index.html b/graalvm/src/main/resources/META-INF/resources/index.html
new file mode 100644
index 0000000..60a4320
--- /dev/null
+++ b/graalvm/src/main/resources/META-INF/resources/index.html
@@ -0,0 +1,152 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+ <meta charset="UTF-8">
+ <title>org.apache.sling.serverless.osgimocks - 1.0-SNAPSHOT</title>
+ <style>
+ h1, h2, h3, h4, h5, h6 {
+ margin-bottom: 0.5rem;
+ font-weight: 400;
+ line-height: 1.5;
+ }
+
+ h1 {
+ font-size: 2.5rem;
+ }
+
+ h2 {
+ font-size: 2rem
+ }
+
+ h3 {
+ font-size: 1.75rem
+ }
+
+ h4 {
+ font-size: 1.5rem
+ }
+
+ h5 {
+ font-size: 1.25rem
+ }
+
+ h6 {
+ font-size: 1rem
+ }
+
+ .lead {
+ font-weight: 300;
+ font-size: 2rem;
+ }
+
+ .banner {
+ font-size: 2.7rem;
+ margin: 0;
+ padding: 2rem 1rem;
+ background-color: #00A1E2;
+ color: white;
+ }
+
+ body {
+ margin: 0;
+ font-family: -apple-system, system-ui, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";
+ }
+
+ code {
+ font-family: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
+ font-size: 87.5%;
+ color: #e83e8c;
+ word-break: break-word;
+ }
+
+ .left-column {
+ padding: .75rem;
+ max-width: 75%;
+ min-width: 55%;
+ }
+
+ .right-column {
+ padding: .75rem;
+ max-width: 25%;
+ }
+
+ .container {
+ display: flex;
+ width: 100%;
+ }
+
+ li {
+ margin: 0.75rem;
+ }
+
+ .right-section {
+ margin-left: 1rem;
+ padding-left: 0.5rem;
+ }
+
+ .right-section h3 {
+ padding-top: 0;
+ font-weight: 200;
+ }
+
+ .right-section ul {
+ border-left: 0.3rem solid #00A1E2;
+ list-style-type: none;
+ padding-left: 0;
+ }
+
+ </style>
+</head>
+<body>
+
+<div class="banner lead">
+ Your new Cloud-Native application is ready!
+</div>
+
+<div class="container">
+ <div class="left-column">
+ <p class="lead"> Congratulations, you have created a new Quarkus application.</p>
+
+ <h2>Why do you see this?</h2>
+
+ <p>This page is served by Quarkus. The source is in
+ <code>src/main/resources/META-INF/resources/index.html</code>.</p>
+
+ <h2>What can I do from here?</h2>
+
+ <p>If not already done, run the application in <em>dev mode</em> using: <code>mvn compile quarkus:dev</code>.
+ </p>
+ <ul>
+ <li>Add REST resources, Servlets, functions and other services in <code>src/main/java</code>.</li>
+ <li>Your static assets are located in <code>src/main/resources/META-INF/resources</code>.</li>
+ <li>Configure your application in <code>src/main/resources/application.properties</code>.
+ </li>
+ </ul>
+
+ <h2>How do I get rid of this page?</h2>
+ <p>Just delete the <code>src/main/resources/META-INF/resources/index.html</code> file.</p>
+ </div>
+ <div class="right-column">
+ <div class="right-section">
+ <h3>Application</h3>
+ <ul>
+ <li>GroupId: org.apache.sling</li>
+ <li>ArtifactId: org.apache.sling.serverless.osgimocks</li>
+ <li>Version: 1.0-SNAPSHOT</li>
+ <li>Quarkus Version: 0.18.0</li>
+ </ul>
+ </div>
+ <div class="right-section">
+ <h3>Next steps</h3>
+ <ul>
+ <li><a href="https://quarkus.io/guides/maven-tooling.html">Setup your IDE</a></li>
+ <li><a href="https://quarkus.io/guides/getting-started-guide.html">Getting started</a></li>
+ <li><a href="https://quarkus.io">Quarkus Web Site</a></li>
+ </ul>
+ </div>
+ </div>
+</div>
+
+
+</body>
+</html>
\ No newline at end of file
diff --git a/graalvm/src/main/resources/application.properties b/graalvm/src/main/resources/application.properties
new file mode 100644
index 0000000..3c1ac56
--- /dev/null
+++ b/graalvm/src/main/resources/application.properties
@@ -0,0 +1,2 @@
+# Configuration file
+# key = value
\ No newline at end of file
diff --git a/graalvm/src/test/java/org/apache/sling/serverless/HelloResourceTest.java b/graalvm/src/test/java/org/apache/sling/serverless/HelloResourceTest.java
new file mode 100644
index 0000000..9f4ac22
--- /dev/null
+++ b/graalvm/src/test/java/org/apache/sling/serverless/HelloResourceTest.java
@@ -0,0 +1,21 @@
+package org.apache.sling.serverless;
+
+import io.quarkus.test.junit.QuarkusTest;
+import org.junit.jupiter.api.Test;
+
+import static io.restassured.RestAssured.given;
+import static org.hamcrest.CoreMatchers.containsString;
+
+@QuarkusTest
+public class HelloResourceTest {
+
+ @Test
+ public void testHelloEndpoint() {
+ given()
+ .when().get("/hello")
+ .then()
+ .statusCode(200)
+ .body(containsString("hello, at"));
+ }
+
+}
\ No newline at end of file
diff --git a/graalvm/src/test/java/org/apache/sling/serverless/NativeHelloResourceIT.java b/graalvm/src/test/java/org/apache/sling/serverless/NativeHelloResourceIT.java
new file mode 100644
index 0000000..7bfae1b
--- /dev/null
+++ b/graalvm/src/test/java/org/apache/sling/serverless/NativeHelloResourceIT.java
@@ -0,0 +1,9 @@
+package org.apache.sling.serverless;
+
+import io.quarkus.test.junit.SubstrateTest;
+
+@SubstrateTest
+public class NativeHelloResourceIT extends HelloResourceTest {
+
+ // Execute the same tests but in native mode.
+}
\ No newline at end of file