Skip to content

Commit

Permalink
Update Helidon steps after QA
Browse files Browse the repository at this point in the history
  • Loading branch information
mraible committed Feb 1, 2024
1 parent 4f31645 commit 3f7bb3a
Show file tree
Hide file tree
Showing 14 changed files with 185 additions and 60 deletions.
32 changes: 19 additions & 13 deletions demo.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -302,10 +302,19 @@ helidon init --flavor SE --groupid com.okta.rest \
+
TIP: See https://blogs.oracle.com/developers/post/migrating-a-helidon-se-application-to-gradle[Migrating a Helidon SE application to Gradle] for Gradle support.

. Add MicroProfile JWT support in `pom.xml`:
. Delete the default Java classes created by the Helidon CLI:

- On Windows: `del /s *.java`
- On Mac/Linux: `find . -name '*.java' -delete`

. Add JWT authentication support in `pom.xml`:
+
[source,xml]
----
<dependency>
<groupId>io.helidon.webserver</groupId>
<artifactId>helidon-webserver-security</artifactId>
</dependency>
<dependency>
<groupId>io.helidon.security.providers</groupId>
<artifactId>helidon-security-providers-jwt</artifactId>
Expand All @@ -316,7 +325,7 @@ TIP: See https://blogs.oracle.com/developers/post/migrating-a-helidon-se-applica
+
[source,java]
----
package com.okta.rest.controller;
package com.okta.rest.resource;
import static io.helidon.http.Status.OK_200;
Expand All @@ -343,24 +352,25 @@ public class HelloResource implements HttpFeature {
}
----

. Add a `HelloApplication` class in `src/main/java/com/okta/rest` to register your resource and configure JWT authentication:
. Create a `Main` class in `src/main/java/com/okta/rest` to register your resource and configure JWT authentication:
+
[source,java]
----
package com.okta.rest;
import com.okta.rest.controller.HelloResource;
import com.okta.rest.resource.HelloResource;
import io.helidon.config.Config;
import io.helidon.config.ConfigSources;
import io.helidon.logging.common.LogConfig;
import io.helidon.webserver.WebServer;
import io.helidon.webserver.WebServerConfig;
import io.helidon.webserver.security.SecurityHttpFeature;
import java.util.concurrent.TimeUnit;
public class HelloApplication {
public class Main {
public static void main(String[] args) {
LogConfig.configureRuntime();
WebServerConfig.Builder builder = WebServer.builder();
setup(builder);
WebServer server = builder.port(8080).build();
Expand All @@ -375,7 +385,8 @@ public class HelloApplication {
}
static void setup(WebServerConfig.Builder server) {
Config config = Config.create(ConfigSources.classpath("application.yml"));
Config config = Config.create();
Config.global(config);
server.routing(routing -> routing
.addFeature(SecurityHttpFeature.create(config.get("security.web-server")))
Expand All @@ -384,7 +395,7 @@ public class HelloApplication {
}
----

. Create a YAML config file at `src/main/resources/application.yml`.
. Add your security settings and routes to `src/main/resources/application.yaml`.
+
[source,yaml]
----
Expand All @@ -411,11 +422,6 @@ security:

http :8080/hello Authorization:"Bearer $TOKEN"

. Delete the default Java classes created by the Helidon CLI:

- On Windows: `del /s *.java`
- On Mac/Linux: `find . -name '*.java' -delete`

=== Build a native Helidon app with GraalVM

. Update `src/main/resources/META-INF/native-image/com.okta.rest/helidon/native-image.properties` so native compilation will work with Java 21.
Expand Down
4 changes: 2 additions & 2 deletions helidon/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ WORKDIR /helidon
# Create a first layer to cache the "Maven World" in the local repository.
# Incremental docker builds will always resume after that, unless you update
# the pom
ADD pom.xml pom.xml
RUN mvn package -Dmaven.test.skip -Declipselink.weave.skip
ADD pom.xml .
RUN mvn package -Dmaven.test.skip -Declipselink.weave.skip

# Do the Maven build!
# Incremental docker builds will resume here when you change sources
Expand Down
12 changes: 11 additions & 1 deletion helidon/Dockerfile.jlink
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@

# 1st stage, build the app
FROM maven:3.8.4-openjdk-17-slim as build
FROM container-registry.oracle.com/java/openjdk:21 as build

WORKDIR /usr/share

# Install maven
RUN set -x && \
curl -O https://archive.apache.org/dist/maven/maven-3/3.8.4/binaries/apache-maven-3.8.4-bin.tar.gz && \
tar -xvf apache-maven-*-bin.tar.gz && \
rm apache-maven-*-bin.tar.gz && \
mv apache-maven-* maven && \
ln -s /usr/share/maven/bin/mvn /bin/

WORKDIR /helidon

Expand Down
68 changes: 60 additions & 8 deletions helidon/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# helidon

Minimal Helidon SE project suitable to start from scratch.
Sample Helidon SE project that includes multiple REST operations.

## Build and run

Expand All @@ -12,11 +12,15 @@ java -jar target/helidon.jar
```

## Exercise the application

Basic:
```
curl -X GET http://localhost:8080/simple-greet
{"message":"Hello World!"}
Hello World!
```


JSON:
```
curl -X GET http://localhost:8080/greet
{"message":"Hello World!"}
Expand All @@ -36,30 +40,49 @@ curl -X GET http://localhost:8080/greet/Jose

```
# Prometheus Format
curl -s -X GET http://localhost:8080/metrics
curl -s -X GET http://localhost:8080/observe/metrics
# TYPE base:gc_g1_young_generation_count gauge
. . .
# JSON Format
curl -H 'Accept: application/json' -X GET http://localhost:8080/metrics
curl -H 'Accept: application/json' -X GET http://localhost:8080/observe/metrics
{"base":...
. . .
```



## Try health

```
curl -s -X GET http://localhost:8080/health
{"outcome":"UP",...
This example shows the basics of using Helidon SE Health. It uses the
set of built-in health checks that Helidon provides plus defines a
custom health check.

Note the port number reported by the application.

Probe the health endpoints:

```bash
curl -X GET http://localhost:8080/observe/health
curl -X GET http://localhost:8080/observe/health/ready
```



## Building a Native Image

The generation of native binaries requires an installation of GraalVM 22.1.0+.

You can build a native binary using Maven as follows:

```
mvn -Pnative-image install -DskipTests
```

The generation of the executable binary may take a few minutes to complete depending on
your hardware and operating system. When completed, the executable file will be available
under the `target` directory and be named after the artifact ID you have chosen during the
project generation phase.

Make sure you have GraalVM locally installed:

```
Expand Down Expand Up @@ -97,6 +120,35 @@ docker run --rm -p 8080:8080 helidon:latest
Exercise the application as described above.


## Run the application in Kubernetes

If you don’t have access to a Kubernetes cluster, you can [install one](https://helidon.io/docs/latest/#/about/kubernetes) on your desktop.

### Verify connectivity to cluster

```
kubectl cluster-info # Verify which cluster
kubectl get pods # Verify connectivity to cluster
```

### Deploy the application to Kubernetes

```
kubectl create -f app.yaml # Deploy application
kubectl get pods # Wait for quickstart pod to be RUNNING
kubectl get service helidon # Get service info
```

Note the PORTs. You can now exercise the application as you did before but use the second
port number (the NodePort) instead of 8080.

After you’re done, cleanup.

```
kubectl delete -f app.yaml
```

## Building a Custom Runtime Image

Build the custom runtime image using the jlink image profile:
Expand Down
36 changes: 36 additions & 0 deletions helidon/app.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
kind: Service
apiVersion: v1
metadata:
name: helidon
labels:
app: helidon
spec:
type: NodePort
selector:
app: helidon
ports:
- port: 8080
targetPort: 8080
name: http
---
kind: Deployment
apiVersion: apps/v1
metadata:
name: helidon
spec:
replicas: 1
selector:
matchLabels:
app: helidon
template:
metadata:
labels:
app: helidon
version: v1
spec:
containers:
- name: helidon
image: helidon
imagePullPolicy: IfNotPresent
ports:
- containerPort: 8080
52 changes: 47 additions & 5 deletions helidon/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<version>1.0-SNAPSHOT</version>

<properties>
<mainClass>com.okta.rest.HelloApplication</mainClass>
<mainClass>com.okta.rest.Main</mainClass>
</properties>

<dependencies>
Expand All @@ -26,10 +26,6 @@
<groupId>io.helidon.webserver</groupId>
<artifactId>helidon-webserver-security</artifactId>
</dependency>
<dependency>
<groupId>io.helidon.webserver</groupId>
<artifactId>helidon-webserver-context</artifactId>
</dependency>
<dependency>
<groupId>io.helidon.security.providers</groupId>
<artifactId>helidon-security-providers-jwt</artifactId>
Expand All @@ -38,10 +34,56 @@
<groupId>io.helidon.config</groupId>
<artifactId>helidon-config-yaml</artifactId>
</dependency>
<dependency>
<groupId>io.helidon.webserver.observe</groupId>
<artifactId>helidon-webserver-observe-health</artifactId>
</dependency>
<dependency>
<groupId>io.helidon.health</groupId>
<artifactId>helidon-health-checks</artifactId>
</dependency>
<dependency>
<groupId>io.helidon.logging</groupId>
<artifactId>helidon-logging-jul</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>jakarta.json</groupId>
<artifactId>jakarta.json-api</artifactId>
</dependency>
<dependency>
<groupId>io.helidon.http.media</groupId>
<artifactId>helidon-http-media-jsonp</artifactId>
</dependency>
<dependency>
<groupId>io.helidon.webserver.observe</groupId>
<artifactId>helidon-webserver-observe-metrics</artifactId>
</dependency>
<dependency>
<groupId>io.helidon.metrics</groupId>
<artifactId>helidon-metrics-system-meters</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>io.helidon.webclient</groupId>
<artifactId>helidon-webclient</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-all</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.helidon.webserver.testing.junit5</groupId>
<artifactId>helidon-webserver-testing-junit5</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
package com.okta.rest;

import com.okta.rest.controller.HelloResource;
import com.okta.rest.resource.HelloResource;
import io.helidon.config.Config;
import io.helidon.config.ConfigSources;
import io.helidon.logging.common.LogConfig;
import io.helidon.webserver.WebServer;
import io.helidon.webserver.WebServerConfig;
import io.helidon.webserver.security.SecurityHttpFeature;

import java.util.concurrent.TimeUnit;

public class HelloApplication {
public class Main {

public static void main(String[] args) {
LogConfig.configureRuntime();
WebServerConfig.Builder builder = WebServer.builder();
setup(builder);
WebServer server = builder.port(8080).build();
Expand All @@ -26,7 +27,8 @@ public static void main(String[] args) {
}

static void setup(WebServerConfig.Builder server) {
Config config = Config.create(ConfigSources.classpath("application.yml"));
Config config = Config.create();
Config.global(config);

server.routing(routing -> routing
.addFeature(SecurityHttpFeature.create(config.get("security.web-server")))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.okta.rest.controller;
package com.okta.rest.resource;

import static io.helidon.http.Status.OK_200;

Expand Down
4 changes: 0 additions & 4 deletions helidon/src/main/resources/application.properties

This file was deleted.

File renamed without changes.
Loading

0 comments on commit 3f7bb3a

Please sign in to comment.