Skip to content

Commit

Permalink
Convert to Helidon SE
Browse files Browse the repository at this point in the history
  • Loading branch information
mraible committed Jan 12, 2024
1 parent f81bc01 commit 0fbd049
Show file tree
Hide file tree
Showing 16 changed files with 119 additions and 230 deletions.
21 changes: 5 additions & 16 deletions helidon/.helidon

Large diffs are not rendered by default.

8 changes: 4 additions & 4 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 .
RUN mvn package -Dmaven.test.skip -Declipselink.weave.skip -Declipselink.weave.skip -DskipOpenApiGenerate
ADD pom.xml 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 All @@ -31,9 +31,9 @@ FROM container-registry.oracle.com/java/openjdk:21
WORKDIR /helidon

# Copy the binary built in the 1st stage
COPY --from=build /helidon/target/helidon.jar ./
COPY --from=build /helidon/target/helidon-se.jar ./
COPY --from=build /helidon/target/libs ./libs

CMD ["java", "-jar", "helidon.jar"]
CMD ["java", "-jar", "helidon-se.jar"]

EXPOSE 8080
14 changes: 2 additions & 12 deletions helidon/Dockerfile.jlink
Original file line number Diff line number Diff line change
@@ -1,16 +1,6 @@

# 1st stage, build the app
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/
FROM maven:3.8.4-openjdk-17-slim as build

WORKDIR /helidon

Expand All @@ -30,6 +20,6 @@ RUN echo "done!"

FROM debian:stretch-slim
WORKDIR /helidon
COPY --from=build /helidon/target/helidon-jri ./
COPY --from=build /helidon/target/helidon-se-jri ./
ENTRYPOINT ["/bin/bash", "/helidon/bin/start"]
EXPOSE 8080
4 changes: 2 additions & 2 deletions helidon/Dockerfile.native
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ FROM scratch
WORKDIR /helidon

# Copy the binary built in the 1st stage
COPY --from=build /helidon/target/helidon .
COPY --from=build /helidon/target/helidon-se .

ENTRYPOINT ["./helidon"]
ENTRYPOINT ["./helidon-se"]

EXPOSE 8080
57 changes: 16 additions & 41 deletions helidon/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# helidon

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

## Build and run

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

## Exercise the application

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


JSON:
```
curl -X GET http://localhost:8080/greet
{"message":"Hello World!"}
Expand Down Expand Up @@ -61,65 +57,44 @@ curl -s -X GET http://localhost:8080/health
```


## Building a Native Image

The generation of native binaries requires an installation of GraalVM 22.1.0+.
## Building a Native Image

You can build a native binary using Maven as follows:
Make sure you have GraalVM locally installed:

```
mvn -Pnative-image install -DskipTests
$GRAALVM_HOME/bin/native-image --version
```

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.



## Building the Docker Image
Build the native image using the native image profile:

```
docker build -t helidon .
mvn package -Pnative-image
```

## Running the Docker Image
This uses the helidon-maven-plugin to perform the native compilation using your installed copy of GraalVM. It might take a while to complete.
Once it completes start the application using the native executable (no JVM!):

```
docker run --rm -p 8080:8080 helidon:latest
./target/helidon
```

Exercise the application as described above.


## Run the application in Kubernetes
Yep, it starts fast. You can exercise the application’s endpoints as before.

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
## Building the Docker Image

```
kubectl cluster-info # Verify which cluster
kubectl get pods # Verify connectivity to cluster
docker build -t helidon .
```

### Deploy the application to Kubernetes
## Running the Docker Image

```
kubectl create -f app.yaml # Deploy application
kubectl get pods # Wait for quickstart pod to be RUNNING
kubectl get service helidon # Get service info
docker run --rm -p 8080:8080 helidon:latest
```

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
```
Exercise the application as described above.


## Building a Custom Runtime Image
Expand Down
36 changes: 0 additions & 36 deletions helidon/app.yaml

This file was deleted.

93 changes: 16 additions & 77 deletions helidon/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,99 +5,38 @@
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>io.helidon.applications</groupId>
<artifactId>helidon-mp</artifactId>
<artifactId>helidon-se</artifactId>
<version>4.0.2</version>
<relativePath/>
</parent>
<groupId>com.okta.rest</groupId>
<artifactId>helidon</artifactId>
<artifactId>helidon-se</artifactId>
<version>1.0-SNAPSHOT</version>

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

<dependencies>
<dependency>
<groupId>io.helidon.microprofile.bundles</groupId>
<artifactId>helidon-microprofile-core</artifactId>
</dependency>
<dependency>
<groupId>io.helidon.microprofile.openapi</groupId>
<artifactId>helidon-microprofile-openapi</artifactId>
</dependency>
<dependency>
<groupId>io.helidon.microprofile.health</groupId>
<artifactId>helidon-microprofile-health</artifactId>
</dependency>
<dependency>
<groupId>io.helidon.microprofile.jwt</groupId>
<artifactId>helidon-microprofile-jwt-auth</artifactId>
</dependency>
<dependency>
<groupId>jakarta.json.bind</groupId>
<artifactId>jakarta.json.bind-api</artifactId>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-json-binding</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>io.helidon.logging</groupId>
<artifactId>helidon-logging-jul</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>io.smallrye</groupId>
<artifactId>jandex</artifactId>
<scope>runtime</scope>
<groupId>io.helidon.webserver</groupId>
<artifactId>helidon-webserver</artifactId>
</dependency>
<dependency>
<groupId>jakarta.activation</groupId>
<artifactId>jakarta.activation-api</artifactId>
<groupId>io.helidon.webserver</groupId>
<artifactId>helidon-webserver-security</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.microprofile.metrics</groupId>
<artifactId>microprofile-metrics-api</artifactId>
<groupId>io.helidon.webserver</groupId>
<artifactId>helidon-webserver-context</artifactId>
</dependency>
<dependency>
<groupId>io.helidon.microprofile.metrics</groupId>
<artifactId>helidon-microprofile-metrics</artifactId>
<groupId>io.helidon.security.providers</groupId>
<artifactId>helidon-security-providers-jwt</artifactId>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.helidon.microprofile.testing</groupId>
<artifactId>helidon-microprofile-testing-junit5</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-all</artifactId>
<scope>test</scope>
<groupId>io.helidon.http.media</groupId>
<artifactId>helidon-http-media-jsonp</artifactId>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-libs</id>
</execution>
</executions>
</plugin>
<plugin>
<groupId>io.smallrye</groupId>
<artifactId>jandex-maven-plugin</artifactId>
<executions>
<execution>
<id>make-index</id>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
56 changes: 46 additions & 10 deletions helidon/src/main/java/com/okta/rest/HelloApplication.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,55 @@
package com.okta.rest;

import java.net.URI;

import com.okta.rest.controller.HelloResource;
import org.eclipse.microprofile.auth.LoginConfig;

import jakarta.enterprise.context.ApplicationScoped;
import jakarta.ws.rs.core.Application;
import io.helidon.common.configurable.Resource;
import io.helidon.config.Config;
import io.helidon.security.Security;
import io.helidon.security.providers.jwt.JwtProvider;
import io.helidon.webserver.WebServer;
import io.helidon.webserver.context.ContextFeature;
import io.helidon.webserver.http.HttpRouting;
import io.helidon.webserver.security.SecurityFeature;

public class HelloApplication {

public static void main(String[] args) {

import java.util.Set;
var config = Config.global();
var oauth =
JwtProvider.builder()
.issuer(config.get("se.jwt.verify.issuer").asString().get())
.verifyJwk(
Resource.create(
config
.get("se.jwt.verify.publickey.location")
.asString()
.map(URI::create)
.orElseThrow()))
.build();

@LoginConfig(authMethod = "MP-JWT")
@ApplicationScoped
public class HelloApplication extends Application {
Security security = Security.builder().addProvider(oauth).build();
var securityFeature =
SecurityFeature.create(
sfb ->
sfb.security(security)
.addPath(p -> p.path("/hello").handler(h -> h.authenticate(true))));

WebServer.builder()
.config(config.get("server"))
.routing(HelloApplication::routing)
.addFeature(ContextFeature.create())
.addFeature(securityFeature)
.build()
.start();
}

@Override
public Set<Class<?>> getClasses() {
return Set.of(HelloResource.class);
/**
* Updates HTTP Routing.
*/
static void routing(HttpRouting.Builder routing) {
routing.addFeature(new HelloResource());
}
}
Loading

0 comments on commit 0fbd049

Please sign in to comment.