diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml
index d200e7d..9f818d4 100644
--- a/.github/workflows/docker-image.yml
+++ b/.github/workflows/docker-image.yml
@@ -2,7 +2,7 @@ name: Build and Push Docker Image
on:
release:
- types: [created]
+ types: [ created ]
workflow_dispatch:
inputs:
tag:
@@ -14,34 +14,34 @@ jobs:
build-and-push:
runs-on: ubuntu-latest
steps:
- - uses: actions/checkout@v2
+ - uses: actions/checkout@v2
- - name: Set up Docker Buildx
- uses: docker/setup-buildx-action@v1
+ - name: Set up Docker Buildx
+ uses: docker/setup-buildx-action@v1
- - name: Login to Docker Hub
- uses: docker/login-action@v1
- with:
- username: ${{ secrets.DOCKERHUB_USERNAME }}
- password: ${{ secrets.DOCKERHUB_PASSWORD }}
+ - name: Login to Docker Hub
+ uses: docker/login-action@v1
+ with:
+ username: ${{ secrets.DOCKERHUB_USERNAME }}
+ password: ${{ secrets.DOCKERHUB_PASSWORD }}
- - name: Set tag name
- id: tag_name
- run: |
- if [ "${{ github.event_name }}" = "release" ]; then
- echo "::set-output name=tag::${GITHUB_REF#refs/tags/}"
- elif [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
- echo "::set-output name=tag::${{ github.event.inputs.tag }}"
- fi
+ - name: Set tag name
+ id: tag_name
+ run: |
+ if [ "${{ github.event_name }}" = "release" ]; then
+ echo "::set-output name=tag::${GITHUB_REF#refs/tags/}"
+ elif [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
+ echo "::set-output name=tag::${{ github.event.inputs.tag }}"
+ fi
- - name: Build and push Docker image with Release tag
- uses: docker/build-push-action@v2
- with:
- context: .
- file: ./Dockerfiles/Dockerfile
- push: true
- tags: |
- yangclivia/spring-native-image:${{ steps.tag_name.outputs.tag }}
- yangclivia/spring-native-image:latest
- platforms: linux/amd64,linux/arm64
- build-args: TARGETPLATFORM=${{ matrix.platform }}
+ - name: Build and push Docker image with Release tag
+ uses: docker/build-push-action@v2
+ with:
+ context: .
+ file: ./Dockerfiles/Dockerfile
+ push: true
+ tags: |
+ yangclivia/spring-native-image:${{ steps.tag_name.outputs.tag }}
+ yangclivia/spring-native-image:latest
+ platforms: linux/amd64,linux/arm64
+ build-args: TARGETPLATFORM=${{ matrix.platform }}
diff --git a/.github/workflows/maven-publish.yml b/.github/workflows/maven-publish.yml
index 8e95df2..932418e 100644
--- a/.github/workflows/maven-publish.yml
+++ b/.github/workflows/maven-publish.yml
@@ -2,7 +2,7 @@ name: Maven Package
on:
release:
- types: [created]
+ types: [ created ]
jobs:
build:
@@ -12,27 +12,27 @@ jobs:
packages: write
steps:
- - uses: actions/checkout@v3
-
- - name: Set up GraalVM
- uses: DeLaGuardo/setup-graalvm@5.0
- with:
- graalvm-version: '21.3' # 更新为支持 Java 17 的 GraalVM 版本
- java-version: 'java17' # 确保 Java 版本符合你的需求
+ - uses: actions/checkout@v3
+
+ - name: Set up GraalVM
+ uses: DeLaGuardo/setup-graalvm@5.0
+ with:
+ graalvm-version: '21.3' # 更新为支持 Java 17 的 GraalVM 版本
+ java-version: 'java17' # 确保 Java 版本符合你的需求
- - name: Grant execute permission for mvnw
- run: chmod +x ./mvnw
+ - name: Grant execute permission for mvnw
+ run: chmod +x ./mvnw
- - name: Set JAVA_HOME
- run: echo "JAVA_HOME=$(java -XshowSettings:properties -version 2>&1 > /dev/null | grep 'java.home' | awk '{print \\\$3}')" >> $GITHUB_ENV
-
- - name: Build with Maven
- run: ./mvnw native:compile -Pnative
+ - name: Set JAVA_HOME
+ run: echo "JAVA_HOME=$(java -XshowSettings:properties -version 2>&1 > /dev/null | grep 'java.home' | awk '{print \\\$3}')" >> $GITHUB_ENV
- - name: Publish to GitHub Packages Apache Maven
- run: mvn deploy -Pnative -s $GITHUB_WORKSPACE/settings.xml
- env:
- GITHUB_TOKEN: ${{ github.token }}
+ - name: Build with Maven
+ run: ./mvnw native:compile -Pnative
+
+ - name: Publish to GitHub Packages Apache Maven
+ run: mvn deploy -Pnative -s $GITHUB_WORKSPACE/settings.xml
+ env:
+ GITHUB_TOKEN: ${{ github.token }}
diff --git a/.idea/compiler.xml b/.idea/compiler.xml
index c9090be..93945cf 100644
--- a/.idea/compiler.xml
+++ b/.idea/compiler.xml
@@ -7,13 +7,16 @@
-
+
-
+
+
+
diff --git a/README-Cloud-Shell.md b/README-Cloud-Shell.md
index 3a627bc..173c9d8 100644
--- a/README-Cloud-Shell.md
+++ b/README-Cloud-Shell.md
@@ -1,14 +1,18 @@
# Spring Boot Microservice with Oracle GraalVM in OCI Cloud Shell
-This part shows how you can get started quickly with Oracle GraalVM in Oracle Cloud Infrastructure (OCI) Cloud Shell using the Spring Boot 3 microservice example.
+This part shows how you can get started quickly with Oracle GraalVM in Oracle Cloud Infrastructure (OCI) Cloud Shell
+using the Spring Boot 3 microservice example.
Oracle GraalVM is available for use on Oracle Cloud Infrastructure (OCI) at no additional cost.
## What is Cloud Shell?
-[Cloud Shell](https://www.oracle.com/devops/cloud-shell/) is a free-to-use browser-based terminal accessible from the Oracle Cloud Console. It provides access to a Linux shell with preinstalled developer tools and a pre-authenticated OCI CLI. You can use the shell to interact with OCI resources, follow labs and tutorials, and quickly run utility commands.
+[Cloud Shell](https://www.oracle.com/devops/cloud-shell/) is a free-to-use browser-based terminal accessible from the
+Oracle Cloud Console. It provides access to a Linux shell with preinstalled developer tools and a pre-authenticated OCI
+CLI. You can use the shell to interact with OCI resources, follow labs and tutorials, and quickly run utility commands.
-Oracle GraalVM for JDK 17 (with Native Image) is preinstalled in Cloud Shell, so you don’t have to install and configure a development machine to get started.
+Oracle GraalVM for JDK 17 (with Native Image) is preinstalled in Cloud Shell, so you don’t have to install and configure
+a development machine to get started.
## Step 1: Launch Cloud Shell
@@ -22,7 +26,7 @@ Oracle GraalVM for JDK 17 (with Native Image) is preinstalled in Cloud Shell, so
csruntimectl java list
```
- The output should be similar to (versions may vary):
+ The output should be similar to (versions may vary):
```shell
graalvmjdk-17 /usr/lib64/graalvm/graalvm-java17
@@ -36,7 +40,7 @@ Oracle GraalVM for JDK 17 (with Native Image) is preinstalled in Cloud Shell, so
csruntimectl java set graalvmjdk-17
```
- The output should be similar to:
+ The output should be similar to:
```shell
The current managed java version is set to graalvmjdk-17.
@@ -85,7 +89,8 @@ This step is optional - [Check software version and environment variables](../_c
curl http://localhost:8080/jibber
```
- It should generate a random nonsense verse in the style of the poem Jabberwocky by Lewis Carrol. The output should be similar to:
+ It should generate a random nonsense verse in the style of the poem Jabberwocky by Lewis Carrol. The output should be
+ similar to:
```shell
...
@@ -119,7 +124,7 @@ Now build a native executable for your Spring Boot microservice using Oracle Gra
mvn -Pnative native:compile
```
- This will create a binary executable `target/benchmark-jibber`.
+ This will create a binary executable `target/benchmark-jibber`.
2. Run the app native executable in the background
@@ -133,7 +138,8 @@ Now build a native executable for your Spring Boot microservice using Oracle Gra
curl http://localhost:8080/jibber
```
- It should generate a random nonsense verse in the style of the poem Jabberwocky by Lewis Carrol. The output should be similar to:
+ It should generate a random nonsense verse in the style of the poem Jabberwocky by Lewis Carrol. The output should be
+ similar to:
```shell
...
diff --git a/README-Code-Editor.md b/README-Code-Editor.md
index 09f430b..7f611a8 100644
--- a/README-Code-Editor.md
+++ b/README-Code-Editor.md
@@ -1,20 +1,26 @@
# Spring Boot Microservice with Oracle GraalVM in OCI Code Editor
-This part shows how you can get started quickly with Oracle GraalVM in Oracle Cloud Infrastructure (OCI) Code Editor using the Spring Boot 3 microservice example.
+This part shows how you can get started quickly with Oracle GraalVM in Oracle Cloud Infrastructure (OCI) Code Editor
+using the Spring Boot 3 microservice example.
Oracle GraalVM is available for use on Oracle Cloud Infrastructure (OCI) at no additional cost.
+
## What is Code Editor?
-[Code Editor](https://www.oracle.com/devops/code-editor/) enables you to edit and deploy code directly from the Oracle Cloud Console. You can develop applications, service workflows, and scripts entirely from a browser. This makes it easy to rapidly prototype cloud solutions, try new services, and accomplish quick coding tasks.
+[Code Editor](https://www.oracle.com/devops/code-editor/) enables you to edit and deploy code directly from the Oracle
+Cloud Console. You can develop applications, service workflows, and scripts entirely from a browser. This makes it easy
+to rapidly prototype cloud solutions, try new services, and accomplish quick coding tasks.
-Oracle GraalVM for JDK 17 (with Native Image) is preinstalled in Cloud Shell, so you don’t have to install and configure a development machine to get started. Code Editor's integration with Cloud Shell gives you direct access to Oracle GraalVM JDK and Native Image.
+Oracle GraalVM for JDK 17 (with Native Image) is preinstalled in Cloud Shell, so you don’t have to install and configure
+a development machine to get started. Code Editor's integration with Cloud Shell gives you direct access to Oracle
+GraalVM JDK and Native Image.
## Step 1: Open Terminal in Code Editor
1. [Login to OCI Console and launch Code Editor](https://cloud.oracle.com/?bdcstate=maximized&codeeditor=true).
2. Open a `New Terminal` in Code Editor. Use this Terminal window to run the commands shown in this sample.
-
+ 
## Step 2: Select GraalVM as the Current JDK
@@ -24,7 +30,7 @@ Oracle GraalVM for JDK 17 (with Native Image) is preinstalled in Cloud Shell, so
csruntimectl java list
```
- The output should be similar to (versions may vary):
+ The output should be similar to (versions may vary):
```shell
graalvmjdk-17 /usr/lib64/graalvm/graalvm-java17
@@ -38,7 +44,7 @@ Oracle GraalVM for JDK 17 (with Native Image) is preinstalled in Cloud Shell, so
csruntimectl java set graalvmjdk-17
```
- The output should be similar to:
+ The output should be similar to:
```shell
The current managed java version is set to graalvmjdk-17.
@@ -87,7 +93,8 @@ This step is optional - [Check software version and environment variables](../_c
curl http://localhost:8080/jibber
```
- It should generate a random nonsense verse in the style of the poem Jabberwocky by Lewis Carrol. The output should be similar to:
+ It should generate a random nonsense verse in the style of the poem Jabberwocky by Lewis Carrol. The output should be
+ similar to:
```shell
...
@@ -120,7 +127,7 @@ Now build a native executable for your Spring Boot microservice using GraalVM Na
```shell
mvn -Pnative native:compile
```
- This will create a binary executable `target/benchmark-jibber`.
+ This will create a binary executable `target/benchmark-jibber`.
2. Run the app native executable in the background
@@ -133,7 +140,8 @@ Now build a native executable for your Spring Boot microservice using GraalVM Na
```shell
curl http://localhost:8080/jibber
```
- It should generate a random nonsense verse in the style of the poem Jabberwocky by Lewis Carrol. The output should be similar to:
+ It should generate a random nonsense verse in the style of the poem Jabberwocky by Lewis Carrol. The output should be
+ similar to:
```shell
...
diff --git a/README.md b/README.md
index aae25e1..802c3f1 100644
--- a/README.md
+++ b/README.md
@@ -1,8 +1,12 @@
# Spring Boot Native Image Microservice
-This demo shows how to build, package, and run a simple Spring Boot 3 microservice from a JAR file with the GraalVM JDK, and from a native executable with GraalVM Native Image. The benefits of using a native executable are faster start-up times and reduced memory consumption. It also demonstrates how to run the application and build the native executable within a Docker container.
+This demo shows how to build, package, and run a simple Spring Boot 3 microservice from a JAR file with the GraalVM JDK,
+and from a native executable with GraalVM Native Image. The benefits of using a native executable are faster start-up
+times and reduced memory consumption. It also demonstrates how to run the application and build the native executable
+within a Docker container.
There are two ways to generate a native executable from a Spring Boot application:
+
- [Using GraalVM Native Build Tools](https://docs.spring.io/spring-boot/docs/current/reference/html/native-image.html#native-image.developing-your-first-application.native-build-tools)
- [Using Buildpacks](https://docs.spring.io/spring-boot/docs/current/reference/html/native-image.html#native-image.developing-your-first-application.buildpacks)
@@ -10,12 +14,22 @@ There are two ways to generate a native executable from a Spring Boot applicatio
The example is a minimal REST-based API application, built on top of Spring Boot 3. It consists of:
-- `com.example.jibber.JibberApplication`: the main Spring Boot class. It is also a REST controller which serves as an entry-point for HTTP requests.
+- `com.example.jibber.JibberApplication`: the main Spring Boot class. It is also a REST controller which serves as an
+ entry-point for HTTP requests.
- `com.example.jibber.Jabberwocky`: a utility class that implements the logic of the application.
-If you call the HTTP endpoint, `/jibber`, it will return some nonsense verse generated in the style of the Jabberwocky poem, by Lewis Carroll. The program achieves this by using a Markov Chain to model the original poem (this is essentially a statistical model). This model generates a new text. The example application provides the text of the poem, then generates a model of the text, which the application then uses to generate a new text that is similar to the original text. The application uses the [RiTa library](https://rednoise.org/rita/) as an external dependency to build and use Markov Chains.
+If you call the HTTP endpoint, `/jibber`, it will return some nonsense verse generated in the style of the Jabberwocky
+poem, by Lewis Carroll. The program achieves this by using a Markov Chain to model the original poem (this is
+essentially a statistical model). This model generates a new text. The example application provides the text of the
+poem, then generates a model of the text, which the application then uses to generate a new text that is similar to the
+original text. The application uses the [RiTa library](https://rednoise.org/rita/) as an external dependency to build
+and use Markov Chains.
-By default, the demo uses the [Native Build Tools Maven plugin](https://graalvm.github.io/native-build-tools/latest/maven-plugin.html) to perform the tasks. If you would like to run this demo using [BuildPacks](https://docs.spring.io/spring-boot/docs/current/reference/html/native-image.html#native-image.developing-your-first-application.buildpacks), the build configuration is provided for you too.
+By default, the demo uses
+the [Native Build Tools Maven plugin](https://graalvm.github.io/native-build-tools/latest/maven-plugin.html) to perform
+the tasks. If you would like to run this demo
+using [BuildPacks](https://docs.spring.io/spring-boot/docs/current/reference/html/native-image.html#native-image.developing-your-first-application.buildpacks),
+the build configuration is provided for you too.
## Prerequisites
@@ -24,7 +38,11 @@ By default, the demo uses the [Native Build Tools Maven plugin](https://graalvm.
sdk install java 21.0.2-graal
```
-2. (Optional) Install and run a Docker-API compatible container runtime such as [Rancher Desktop](https://docs.rancherdesktop.io/getting-started/installation/), [Docker](https://www.docker.io/gettingstarted/), or [Podman](https://podman.io/docs/installation). If you are using Docker, configure it to [allow non-root user access](https://docs.docker.com/engine/install/linux-postinstall/#manage-docker-as-a-non-root-user) if you are on Linux.
+2. (Optional) Install and run a Docker-API compatible container runtime such
+ as [Rancher Desktop](https://docs.rancherdesktop.io/getting-started/installation/), [Docker](https://www.docker.io/gettingstarted/),
+ or [Podman](https://podman.io/docs/installation). If you are using Docker, configure it
+ to [allow non-root user access](https://docs.docker.com/engine/install/linux-postinstall/#manage-docker-as-a-non-root-user)
+ if you are on Linux.
3. Download the demos repository or clone it as follows:
@@ -50,7 +68,8 @@ This demo is built using Maven.
./mvnw clean package
```
- It generates a runnable JAR file that contains all of the application’s dependencies and also a correctly configured `MANIFEST` file.
+ It generates a runnable JAR file that contains all of the application’s dependencies and also a correctly
+ configured `MANIFEST` file.
2. Run the application JAR and put it into the background by appending `&`:
@@ -58,19 +77,21 @@ This demo is built using Maven.
java -jar ./target/benchmark-jibber-0.0.1-SNAPSHOT.jar &
```
-3. Open the application [http://localhost:8080/jibber](http://localhost:8080/jibber) in a browser, or call the endpoint using `curl`:
+3. Open the application [http://localhost:8080/jibber](http://localhost:8080/jibber) in a browser, or call the endpoint
+ using `curl`:
```shell
curl http://localhost:8080/jibber
```
- It should generate a random nonsense verse in the style of the poem Jabberwocky by Lewis Carrol.
+ It should generate a random nonsense verse in the style of the poem Jabberwocky by Lewis Carrol.
4. Bring the application to the foreground using `fg`, and then enter `` to terminate the application.
### (Optional) Containerize the JAR
-The following steps (5-8) show how you can easily containerize the JAR built in the previous step using the Oracle GraalVM JDK container image `container-registry.oracle.com/graalvm/jdk:17-ol8`.
+The following steps (5-8) show how you can easily containerize the JAR built in the previous step using the Oracle
+GraalVM JDK container image `container-registry.oracle.com/graalvm/jdk:17-ol8`.
5. Run this command to package the JAR as a Docker container:
@@ -84,13 +105,14 @@ The following steps (5-8) show how you can easily containerize the JAR built in
docker run --rm --name graal -p 8080:8080 jibber-benchmark:jvm.0.0.1-SNAPSHOT
```
-7. Open the application [http://localhost:8080/jibber](http://localhost:8080/jibber) in a browser, or from a new terminal window, call the endpoint using `curl`:
+7. Open the application [http://localhost:8080/jibber](http://localhost:8080/jibber) in a browser, or from a new
+ terminal window, call the endpoint using `curl`:
```shell
curl http://localhost:8080/jibber
```
- You should get a random nonsense verse in the style of the poem Jabberwocky by Lewis Carrol.
+ You should get a random nonsense verse in the style of the poem Jabberwocky by Lewis Carrol.
8. To stop the application, first get the container id using `docker ps`, and then run:
@@ -103,16 +125,21 @@ The following steps (5-8) show how you can easily containerize the JAR built in
Recap what you have so far: built a Spring Boot application with an HTTP endpoint, and successfully containerised it.
Now you will look at how you can create a native executable from your application.
-Spring Boot 3's built-in support for GraalVM Native Image makes it easy to compile a Spring Boot 3 application into a native executable.
+Spring Boot 3's built-in support for GraalVM Native Image makes it easy to compile a Spring Boot 3 application into a
+native executable.
-This native executable not only starts faster but also uses far fewer resources than running the application as a JAR file.
+This native executable not only starts faster but also uses far fewer resources than running the application as a JAR
+file.
You can use the `native-image` tool from the GraalVM installation to build a native executable.
-In this example, you'll use the [GraalVM Native Build Tools for Maven](https://graalvm.github.io/native-build-tools/latest/maven-plugin.html) to build a native executable.
+In this example, you'll use
+the [GraalVM Native Build Tools for Maven](https://graalvm.github.io/native-build-tools/latest/maven-plugin.html) to
+build a native executable.
### Default Native Build Configuration
-Make sure you’re using `spring-boot-starter-parent` in order to inherit the out-of-the-box `native` profile, and the `org.graalvm.buildtools:native-maven-plugin` plugin.
+Make sure you’re using `spring-boot-starter-parent` in order to inherit the out-of-the-box `native` profile, and
+the `org.graalvm.buildtools:native-maven-plugin` plugin.
You should see the following in the Maven `pom.xml` file:
@@ -137,11 +164,13 @@ You should see the following in the Maven `pom.xml` file:
```
-The out-of-the-box `native` profile has [GraalVM Reachability Metadata](https://www.graalvm.org/native-image/libraries-and-frameworks/) enabled by default.
+The out-of-the-box `native` profile
+has [GraalVM Reachability Metadata](https://www.graalvm.org/native-image/libraries-and-frameworks/) enabled by default.
### Build and Run as a Native Executable
-With the out-of-the-box `native` profile active, you can invoke the `native:compile` goal to trigger native-image compilation.
+With the out-of-the-box `native` profile active, you can invoke the `native:compile` goal to trigger native-image
+compilation.
1. Run the following command:
@@ -149,9 +178,12 @@ With the out-of-the-box `native` profile active, you can invoke the `native:comp
./mvnw native:compile -Pnative
```
- The `native` profile is used to generate a native executable for your platform. The native executable is called _benchmark-jibber_ and is generated in the _target_ directory.
+ The `native` profile is used to generate a native executable for your platform. The native executable is called
+ _benchmark-jibber_ and is generated in the _target_ directory.
- >Alternatively, to build using BuildPacks, run the `./mvnw spring-boot:build-image -Pnative` command to generate a native executable. For more information about using BuildPacks to create a native executable, see [Building a Native Image Using Buildpacks](https://docs.spring.io/spring-boot/docs/current/reference/html/native-image.html#native-image.developing-your-first-application.buildpacks).
+ > Alternatively, to build using BuildPacks, run the `./mvnw spring-boot:build-image -Pnative` command to generate a
+ native executable. For more information about using BuildPacks to create a native executable,
+ see [Building a Native Image Using Buildpacks](https://docs.spring.io/spring-boot/docs/current/reference/html/native-image.html#native-image.developing-your-first-application.buildpacks).
2. Run the native executable and put it into the background by appending `&`:
@@ -159,7 +191,8 @@ With the out-of-the-box `native` profile active, you can invoke the `native:comp
./target/benchmark-jibber &
```
-3. Open the application [http://localhost:8080/jibber](http://localhost:8080/jibber) in a browser, or call the endpoint using `curl`:
+3. Open the application [http://localhost:8080/jibber](http://localhost:8080/jibber) in a browser, or call the endpoint
+ using `curl`:
```shell
curl http://localhost:8080/jibber
@@ -169,13 +202,17 @@ With the out-of-the-box `native` profile active, you can invoke the `native:comp
4. Bring the application to the foreground using `fg`, and then enter `` to terminate the application.
-From the log output, notice how much quicker the native executable version of this Spring Boot application starts compared to the JAR. The native executable also uses fewer resources than running from a JAR file.
+From the log output, notice how much quicker the native executable version of this Spring Boot application starts
+compared to the JAR. The native executable also uses fewer resources than running from a JAR file.
### Additional Native Build Configuration
-Notice that you can pass additional configuration arguments to the underlying `native-image` build tool using the `` section. In individual `buildArg` tags, you can pass parameters exactly the same way as you do from a command line. This lets you use all of the parameters that work with the `native-image` tool from Maven.
+Notice that you can pass additional configuration arguments to the underlying `native-image` build tool using
+the `` section. In individual `buildArg` tags, you can pass parameters exactly the same way as you do from a
+command line. This lets you use all of the parameters that work with the `native-image` tool from Maven.
-Add the following snippet to the pom.xml to pass additional arguments to enable verbose output, quick build mode, etc. over and above the out-of-the-box `native` profile.
+Add the following snippet to the pom.xml to pass additional arguments to enable verbose output, quick build mode, etc.
+over and above the out-of-the-box `native` profile.
```xml
@@ -211,7 +248,8 @@ Let's rebuild the native executable with the additional configuration arguments.
./mvnw native:compile -Pnative
```
- With the quick build mode enabled, it takes less time to build the native executable. This mode should be used in development for faster builds.
+ With the quick build mode enabled, it takes less time to build the native executable. This mode should be used in
+ development for faster builds.
2. Run the native executable and put it into the background by appending `&`:
@@ -219,17 +257,19 @@ Let's rebuild the native executable with the additional configuration arguments.
./target/benchmark-jibber &
```
-3. Open the application [http://localhost:8080/jibber](http://localhost:8080/jibber) in a browser, or call the endpoint using `curl`:
+3. Open the application [http://localhost:8080/jibber](http://localhost:8080/jibber) in a browser, or call the endpoint
+ using `curl`:
```shell
curl http://localhost:8080/jibber
```
- You should get a random nonsense verse in the style of the poem Jabberwocky by Lewis Carrol.
+ You should get a random nonsense verse in the style of the poem Jabberwocky by Lewis Carrol.
4. Bring the application to the foreground using `fg`, and then enter `` to terminate the application.
-From the log output, notice how much quicker the native executable version of this Spring Boot application starts compared to the JAR. The native executable also uses fewer resources than running from a JAR file.
+From the log output, notice how much quicker the native executable version of this Spring Boot application starts
+compared to the JAR. The native executable also uses fewer resources than running from a JAR file.
### (Optional) Containerize the Native Executable on Linux
@@ -247,13 +287,14 @@ The following steps (5-8) are for Linux only.
docker run --rm --name native -p 8080:8080 jibber-benchmark:native.0.0.1-SNAPSHOT
```
-7. Open the application [http://localhost:8080/jibber](http://localhost:8080/jibber) in a browser, or from a new terminal window, call the endpoint using `curl`:
+7. Open the application [http://localhost:8080/jibber](http://localhost:8080/jibber) in a browser, or from a new
+ terminal window, call the endpoint using `curl`:
```shell
curl http://localhost:8080/jibber
```
- It should generate a random nonsense verse in the style of the poem Jabberwocky by Lewis Carrol.
+ It should generate a random nonsense verse in the style of the poem Jabberwocky by Lewis Carrol.
8. To stop the application, first get the container id using `docker ps`, and then run:
@@ -263,9 +304,11 @@ The following steps (5-8) are for Linux only.
### (Optional) Use Multistage Docker Builds to Build a Native Image and Package it in a Lightweight Container
-The following steps (9-12) are for all platforms - MacOS, Windows, and Linux.
+The following steps (9-12) are for all platforms - MacOS, Windows, and Linux.
-For MacOS and Windows, to build a Docker image containing your native executable, you need to build the native executable inside a Docker container. To do this, we've provided a [multistage Docker build file](./Dockerfiles/Dockerfile).
+For MacOS and Windows, to build a Docker image containing your native executable, you need to build the native
+executable inside a Docker container. To do this, we've provided
+a [multistage Docker build file](./Dockerfiles/Dockerfile).
9. Run this command to build the native executable within a Docker container:
@@ -279,13 +322,14 @@ For MacOS and Windows, to build a Docker image containing your native executable
docker run --rm --name native -p 8080:8080 jibber-benchmark:native.0.0.1-SNAPSHOT
```
-11. Open the application [http://localhost:8080/jibber](http://localhost:8080/jibber) in a browser, or from a new terminal window, call the endpoint using `curl`:
+11. Open the application [http://localhost:8080/jibber](http://localhost:8080/jibber) in a browser, or from a new
+ terminal window, call the endpoint using `curl`:
```shell
curl http://localhost:8080/jibber
```
- It should generate a random nonsense verse in the style of the poem Jabberwocky by Lewis Carrol.
+ It should generate a random nonsense verse in the style of the poem Jabberwocky by Lewis Carrol.
12. To stop the application, first get the container id using `docker ps`, and then run:
@@ -295,12 +339,15 @@ For MacOS and Windows, to build a Docker image containing your native executable
## Measure the Performance of the Application and Metrics
-The Spring Actuator dependency has been added to the project, along with support for Prometheus. If you want to test the performance of either the JVM version, or the native executable version of the application, you can make use of the Prometheus support. If you are hosting the application locally, it is available on port 8080:
+The Spring Actuator dependency has been added to the project, along with support for Prometheus. If you want to test the
+performance of either the JVM version, or the native executable version of the application, you can make use of the
+Prometheus support. If you are hosting the application locally, it is available on port 8080:
[http://localhost:8080/actuator/prometheus](http://localhost:8080/actuator/prometheus)
## Related Documentation
-- Run an interactive lab: [Level Up your Spring Boot Java Application with GraalVM](https://luna.oracle.com/lab/268ea851-2f09-43e6-8d70-40a10cb4de03)
+- Run an interactive
+ lab: [Level Up your Spring Boot Java Application with GraalVM](https://luna.oracle.com/lab/268ea851-2f09-43e6-8d70-40a10cb4de03)
- [Maven Build Plugin for GraalVM Native Image](https://graalvm.github.io/native-build-tools/latest/maven-plugin.html/)
- [Spring Boot GraalVM Native Image Support](https://docs.spring.io/spring-boot/docs/current/reference/html/native-image.html)
diff --git a/config.json b/config.json
index ec691dd..e4b57e0 100644
--- a/config.json
+++ b/config.json
@@ -1,6 +1,6 @@
{
"gpt3_sleepTime": 0,
- "password": "abc",
+ "password": "2602c0f5-7e73-4586-a788-2c856d2eb748",
"get_token_url": "http:\/\/124.220.157.23:8800\/copilot_internal\/v2\/token",
"prefix": "\/tokensTool",
"serverPort": 8081,
diff --git a/pom.xml b/pom.xml
index c3f1c85..a1d20e7 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1,6 +1,6 @@
-
+4.0.0org.springframework.boot
@@ -8,10 +8,10 @@
3.2.0
- com.gpt4.copilot
- gpt-4-copilot
- 0.0.4
- native
+ com.gpt4.copilot
+ gpt-4-copilot
+ 0.0.4
+ nativeDemo project for Spring Boot with GraalVM Native Image17
@@ -77,6 +77,21 @@
org.springframework.bootspring-boot-maven-plugin
+
+
+
+ org.projectlombok
+ lombok
+
+
+
+
+
+
+ repackage
+
+
+
diff --git a/src/main/java/com/gpt4/copilot/controller/chatController.java b/src/main/java/com/gpt4/copilot/controller/chatController.java
index 647db3c..1db91a7 100644
--- a/src/main/java/com/gpt4/copilot/controller/chatController.java
+++ b/src/main/java/com/gpt4/copilot/controller/chatController.java
@@ -105,6 +105,38 @@ public class chatController {
private final String github_embaddings = "https://api.githubcopilot.com/embeddings";
private final String vscode_version = "vscode/1.85.2";
+ public static Integer getGpt4_sleepTime() {
+ return gpt4_sleepTime;
+ }
+
+ public static void setGpt4_sleepTime(Integer gpt4_sleepTime) {
+ chatController.gpt4_sleepTime = gpt4_sleepTime;
+ }
+
+ public static Integer getGpt3_sleepTime() {
+ return gpt3_sleepTime;
+ }
+
+ public static void setGpt3_sleepTime(Integer gpt3_sleepTime) {
+ chatController.gpt3_sleepTime = gpt3_sleepTime;
+ }
+
+ public static String getPassword() {
+ return password;
+ }
+
+ public static void setPassword(String password) {
+ chatController.password = password;
+ }
+
+ public static String getGet_token_url() {
+ return get_token_url;
+ }
+
+ public static void setGet_token_url(String get_token_url) {
+ chatController.get_token_url = get_token_url;
+ }
+
public static String selectFile() {
String projectRoot = System.getProperty("user.dir");
String parent = projectRoot + File.separator + "config.json";
@@ -126,21 +158,6 @@ public class chatController {
return parent;
}
-
- public static void setGpt4_sleepTime(Integer gpt4_sleepTime) {
- chatController.gpt4_sleepTime = gpt4_sleepTime;
- }
-
-
- public static void setGpt3_sleepTime(Integer gpt3_sleepTime) {
- chatController.gpt3_sleepTime = gpt3_sleepTime;
- }
-
-
- public static void setGet_token_url(String get_token_url) {
- chatController.get_token_url = get_token_url;
- }
-
/**
* 查询config.json里的系统值
*
@@ -222,10 +239,6 @@ public class chatController {
}
}
- public static void setPassword(String password) {
- chatController.password = password;
- }
-
/**
* 修改sleep时间
*/
diff --git a/src/main/java/com/gpt4/copilot/copilotApplication.java b/src/main/java/com/gpt4/copilot/copilotApplication.java
index 4274404..bd82bcd 100644
--- a/src/main/java/com/gpt4/copilot/copilotApplication.java
+++ b/src/main/java/com/gpt4/copilot/copilotApplication.java
@@ -1,6 +1,7 @@
package com.gpt4.copilot;
+import com.gpt4.copilot.controller.chatController;
import com.gpt4.copilot.pojo.systemSetting;
import lombok.extern.slf4j.Slf4j;
import org.json.JSONException;
@@ -13,7 +14,6 @@ import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
-import java.util.UUID;
/**
* @author YANGYANG
@@ -70,10 +70,6 @@ public class copilotApplication {
systemSetting config = new systemSetting();
config.setServerPort(getIntOrDefault(jsonObject, "serverPort", 8080));
config.setPrefix(getStringOrDefault(jsonObject, "prefix", "/"));
- config.setGpt4_sleepTime(getIntOrDefault(jsonObject, "gpt4_sleepTime", 100));
- config.setGpt3_sleepTime(getIntOrDefault(jsonObject, "gpt3_sleepTime", 0));
- config.setPassword(getStringOrDefault(jsonObject, "password", UUID.randomUUID().toString()));
- config.setGet_token_url(getStringOrDefault(jsonObject, "get_token_url", "https://api.copilot.org/copilot_internal/v2/token"));
String updatedJson = jsonObject.toString(2);
Files.write(Paths.get(configFilePath), updatedJson.getBytes());
return config;
@@ -114,20 +110,22 @@ public class copilotApplication {
}
private static void printStartupMessage(systemSetting config) {
- System.out.println("-------------------------------------------------------");
+ System.out.println("\n-------------------------------------------------------");
System.out.println("------原神gpt4-copilot-java-native v0.0.4启动成功--------");
System.out.println("* 采用graalvm打包,运行内存大幅度减小");
System.out.println("* 增加自定义获取token渠道");
System.out.println("* 增加自定义/self/*接口");
System.out.println("* 增加反代/copilot_internal/v2/token接口");
System.out.println("URL地址:http://0.0.0.0:" + config.getServerPort() + config.getPrefix() + "");
- System.out.println("-------------------------------------------------------\n");
+ System.out.println("-------------------------------------------------------");
System.out.println("---------------------配置说明---------------------------");
- System.out.println("gpt4_sleepTime:" + config.getGpt4_sleepTime());
- System.out.println("gpt3_sleepTime:" + config.getGpt3_sleepTime());
- System.out.println("get_token_url:" + config.getGet_token_url());
- System.out.println("password:" + config.getPassword());
- System.out.println("初始化接口成功!");
+ System.out.println("serverPort:" + config.getServerPort());
+ System.out.println("prefix:" + config.getPrefix());
+ System.out.println("gpt3_sleepTime:" + chatController.getGpt3_sleepTime());
+ System.out.println("gpt4_sleepTime:" + chatController.getGpt4_sleepTime());
+ System.out.println("get_token_url:" + chatController.getGet_token_url());
+ System.out.println("password:" + chatController.getPassword());
+ System.out.println("gpt4-copilot-java-native初始化接口成功!");
System.out.println("-------------------------------------------------------");
}
diff --git a/target/classes/application.properties b/target/classes/application.properties
new file mode 100644
index 0000000..a41c724
--- /dev/null
+++ b/target/classes/application.properties
@@ -0,0 +1,15 @@
+management.endpoints.web.exposure.include=metrics,health,info,prometheus
+# server.port
+server.port=8080
+# SpringBoot 2.* prefix
+server.servlet.context-path=/
+# gpt4 sleep time
+gpt4_sleepTime=100
+# gpt3 sleep time
+gpt3_sleepTime=0
+# changeSleepTime's password
+password=gpt4-copilot-java
+# self-define get_token_url
+get_token_url=https://api.cocopilot.org/copilot_internal/v2/token
+
+
diff --git a/target/classes/com/gpt4/copilot/config/CorsConfig.class b/target/classes/com/gpt4/copilot/config/CorsConfig.class
new file mode 100644
index 0000000..191e849
Binary files /dev/null and b/target/classes/com/gpt4/copilot/config/CorsConfig.class differ
diff --git a/target/classes/com/gpt4/copilot/config/WebConfig.class b/target/classes/com/gpt4/copilot/config/WebConfig.class
new file mode 100644
index 0000000..d1f2ded
Binary files /dev/null and b/target/classes/com/gpt4/copilot/config/WebConfig.class differ
diff --git a/target/classes/com/gpt4/copilot/controller/CustomErrorController.class b/target/classes/com/gpt4/copilot/controller/CustomErrorController.class
new file mode 100644
index 0000000..cbabf78
Binary files /dev/null and b/target/classes/com/gpt4/copilot/controller/CustomErrorController.class differ
diff --git a/target/classes/com/gpt4/copilot/controller/chatController$1.class b/target/classes/com/gpt4/copilot/controller/chatController$1.class
new file mode 100644
index 0000000..024e062
Binary files /dev/null and b/target/classes/com/gpt4/copilot/controller/chatController$1.class differ
diff --git a/target/classes/com/gpt4/copilot/controller/chatController.class b/target/classes/com/gpt4/copilot/controller/chatController.class
new file mode 100644
index 0000000..f24b04f
Binary files /dev/null and b/target/classes/com/gpt4/copilot/controller/chatController.class differ
diff --git a/target/classes/com/gpt4/copilot/copilotApplication.class b/target/classes/com/gpt4/copilot/copilotApplication.class
new file mode 100644
index 0000000..ffd7272
Binary files /dev/null and b/target/classes/com/gpt4/copilot/copilotApplication.class differ
diff --git a/target/classes/com/gpt4/copilot/pojo/Result.class b/target/classes/com/gpt4/copilot/pojo/Result.class
new file mode 100644
index 0000000..ba52ad2
Binary files /dev/null and b/target/classes/com/gpt4/copilot/pojo/Result.class differ
diff --git a/target/classes/com/gpt4/copilot/pojo/systemSetting.class b/target/classes/com/gpt4/copilot/pojo/systemSetting.class
new file mode 100644
index 0000000..e069ebe
Binary files /dev/null and b/target/classes/com/gpt4/copilot/pojo/systemSetting.class differ