Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Source build #340

Open
wants to merge 10 commits into
base: source-build
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions builds-applications/apps/vertx-site/README.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
= Vertx-helloworld

image:https://img.shields.io/badge/vert.x-4.4.4-purple.svg[link="https://vertx.io"]

This application was generated using http://start.vertx.io

== Building

To launch your tests:
```
./mvnw clean test
```

To package your application:
```
./mvnw clean package
```

To run your application:
```
./mvnw clean compile exec:java
```

== Help

* https://vertx.io/docs/[Vert.x Documentation]
* https://stackoverflow.com/questions/tagged/vert.x?sort=newest&pageSize=15[Vert.x Stack Overflow]
* https://groups.google.com/forum/?fromgroups#!forum/vertx[Vert.x User Group]
* https://discord.gg/6ry7aqPWXy[Vert.x Discord]
* https://gitter.im/eclipse-vertx/vertx-users[Vert.x Gitter]


7 changes: 7 additions & 0 deletions builds-applications/apps/vertx-site/oc-new-app.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/env bash

oc new-app --name vertx-site \
--build-env MAVEN_MIRROR_URL=http://nexus-infra.apps.ocp4.example.com/repository/java \
-i redhat-openjdk18-openshift:1.8 \
--context-dir builds-applications/apps/vertx-site \
https://git.ocp4.example.com/developer/DO288-apps
116 changes: 116 additions & 0 deletions builds-applications/apps/vertx-site/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
<?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>

<groupId>com.redhat</groupId>
<artifactId>vertx-site</artifactId>
<version>1.0.0-SNAPSHOT</version>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

<maven-compiler-plugin.version>3.8.1</maven-compiler-plugin.version>
<maven-shade-plugin.version>3.2.4</maven-shade-plugin.version>
<maven-surefire-plugin.version>3.0.0-M5</maven-surefire-plugin.version>
<exec-maven-plugin.version>3.0.0</exec-maven-plugin.version>

<vertx.version>4.4.4</vertx.version>
<junit-jupiter.version>5.9.1</junit-jupiter.version>

<main.verticle>com.redhat.vertx_site.MainVerticle</main.verticle>
<launcher.class>io.vertx.core.Launcher</launcher.class>
</properties>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-stack-depchain</artifactId>
<version>${vertx.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-core</artifactId>
</dependency>
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-web</artifactId>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-unit</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven-compiler-plugin.version}</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<verbose>true</verbose>
</configuration>
</plugin>
<plugin>
<artifactId>maven-shade-plugin</artifactId>
<version>${maven-shade-plugin.version}</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<manifestEntries>
<Main-Class>${launcher.class}</Main-Class>
<Main-Verticle>${main.verticle}</Main-Verticle>
</manifestEntries>
</transformer>
<transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
</transformers>
<outputFile>${project.build.directory}/${project.artifactId}-${project.version}-fat.jar
</outputFile>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven-surefire-plugin.version}</version>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>${exec-maven-plugin.version}</version>
<configuration>
<mainClass>io.vertx.core.Launcher</mainClass>
<arguments>
<argument>run</argument>
<argument>${main.verticle}</argument>
</arguments>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.redhat.vertx_site;

import io.vertx.core.AbstractVerticle;
import io.vertx.core.Vertx;
import io.vertx.core.http.HttpServer;
import io.vertx.core.http.HttpServerResponse;
import io.vertx.ext.web.Router;
import io.vertx.ext.web.RoutingContext;

public class MainVerticle extends AbstractVerticle {

@Override
public void start() {
// Create an HTTP server
HttpServer server = vertx.createHttpServer();

// Create a router to handle the HTTP requests
Router router = Router.router(vertx);

// Define the route for the root path
router.get("/").handler(this::handleRoot);

// Start the server and listen on port 8080
server.requestHandler(router).listen(8080);
}

private void handleRoot(RoutingContext routingContext) {
HttpServerResponse response = routingContext.response();

// Set the content type header
response.putHeader("Content-Type", "text/html");

// Send HTML content as the response
response.end("<html><body><h1>Welcome to your Vert.x v1.0 application!</h1></body></html>");
}

public static void main(String[] args) {
Vertx vertx = Vertx.vertx();
vertx.deployVerticle(new MainVerticle());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.redhat.tests;

import com.redhat.vertx_site.MainVerticle;
import io.vertx.core.Vertx;
import io.vertx.core.http.HttpClient;
import io.vertx.core.http.HttpClientResponse;
import io.vertx.core.http.HttpMethod;
import io.vertx.ext.unit.TestContext;
import io.vertx.ext.unit.junit.VertxUnitRunner;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;


@RunWith(VertxUnitRunner.class)
public class VertxSiteTest {
private Vertx vertx;

@Before
public void setUp(TestContext context) {
vertx = Vertx.vertx();
vertx.deployVerticle(new MainVerticle(), context.asyncAssertSuccess());
}

@After
public void tearDown(TestContext context) {
vertx.close(context.asyncAssertSuccess());
}

@Test
public void testHomePage(TestContext context) {
final HttpClient client = vertx.createHttpClient();

client.request(HttpMethod.GET, 8080, "localhost", "/")
.compose(request -> request.send().compose(HttpClientResponse::body))
.onComplete(context.asyncAssertSuccess(buffer -> {
context.assertTrue(buffer.toString().contains("Welcome to your Vert.x"));
client.close();
}));
}

}
8 changes: 8 additions & 0 deletions builds-applications/solutions/oc-new-app.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/env bash

oc new-app --name vertx-site \
--build-env MAVEN_MIRROR_URL=http://nexus-infra.apps.ocp4.example.com/repository/java \
--env JAVA_APP_JAR=vertx-site-1.0.0-SNAPSHOT-fat.jar \
-i redhat-openjdk18-openshift:1.8 \
--context-dir builds-applications/apps/vertx-site \
https://git.ocp4.example.com/developer/DO288-apps
5 changes: 5 additions & 0 deletions images-ubi/apps/greetings/.containerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.git
.npm
.containerignore
node_modules
Containerfile
12 changes: 12 additions & 0 deletions images-ubi/apps/greetings/Containerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM registry.ocp4.example.com:8443/ubi9/nodejs-18-minimal:1-51

ENV PORT=80
EXPOSE ${PORT}

USER root

ADD . $HOME

RUN npm ci --omit=dev && rm -rf .npm

CMD npm start
93 changes: 93 additions & 0 deletions images-ubi/apps/greetings/LocalizationService.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/**
* Simulate an external localization service
*/
const fs = require("fs").promises;


const TRANSLATIONS = {
"greeting": {
"de-de": "Guten tag",
"en-us": "Hi!",
"es-es": "Hola, ¿que tal?",
"fr-be": "Bonjour, ça va bien?",
"it-it": "Ciao, come stai?",
"ca": "Bon dia",
"pt-pt": "Olá, tudo bem?",
"hi": "Namaste",
"nl-nl": "Hallo",
"no-no": "Hei!",
"el": "Yassou",
"cs": "Ahoj!",
"pl": "Cześć!",
"sv-se": "Hej",
"ru": "Privet",
"tr": "Selam"
}
}


async function translate(key, locale) {
let translated;

try {
translated = await readFromFileCache(key, locale);
console.info(`${locale} '${key}' found in cache`);
} catch (error) {
// Only handle the not found case (ENOENT)
if (error.code !== "ENOENT") {
throw err;
}

translated = await getTranslationFromExternalService(key, locale);

await writeToFileCache(key, locale, translated);
}

return translated;
}


async function readFromFileCache(key, locale) {
const buffer = await fs.readFile(generateCacheFilename(key, locale));
return buffer.toString();
}


function writeToFileCache(key, locale, value) {
return fs.writeFile(generateCacheFilename(key, locale), value);
}


function generateCacheFilename(key, locale) {
return `/var/cache/translation_${key}_${locale}`;
}


function getTranslationFromExternalService(key, locale) {
// Simulate a network delay of 500 millis
return new Promise((resolve) => {
setTimeout(() => {
const translated = TRANSLATIONS[key][locale];
resolve(translated);
}, 500);
});
}


function getSupportedLocaleIDs() {
return Object.keys(TRANSLATIONS.greeting);
}


function getRandomLocaleID() {
const locales = getSupportedLocaleIDs();
const localeIndex = Math.floor(Math.random() * locales.length);
return locales[localeIndex];
}


module.exports = {
translate,
getRandomLocaleID,
getSupportedLocaleIDs
}
Loading