Skip to content

Commit

Permalink
perf: support native image and executable jar
Browse files Browse the repository at this point in the history
  • Loading branch information
lichong-a committed Aug 11, 2024
1 parent 5f9c9c9 commit a6d3a3b
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 33 deletions.
9 changes: 5 additions & 4 deletions .github/actions/setup-env/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ inputs:
runs:
using: "composite"
steps:
- name: Setup JDK
uses: actions/setup-java@v4
- name: Setup graalvm
uses: graalvm/setup-graalvm@v1
with:
distribution: "temurin"
distribution: "liberica"
cache: "gradle"
java-version: ${{ inputs.java-version }}
java-version: ${{ inputs.java-version }}
java-package: 'jdk+fx'
11 changes: 9 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,15 @@ jobs:
- name: Setup Environment
uses: ./.github/actions/setup-env

- name: Build APP
run: ./gradlew clean && ./gradlew :starter:build
- name: Show paths
run: |
echo "GRAALVM_HOME: $GRAALVM_HOME"
echo "JAVA_HOME: $JAVA_HOME"
java --version
native-image --version
- name: Build APP jar
run: ./gradlew clean && ./gradlew :starter:bootJar

- name: Upload Artifacts
uses: actions/upload-artifact@v4
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.NestedConfigurationProperty;

/**
* @author 李冲
Expand All @@ -17,6 +18,7 @@
@ConfigurationProperties(prefix = "application")
public class ApplicationConfig {

@NestedConfigurationProperty
private final Security security;

/**
Expand All @@ -28,12 +30,12 @@ public class ApplicationConfig {
*/
public record Security(String adminUsername,
String adminPassword,
Token token,
@NestedConfigurationProperty Token token,
String logoutSuccessUrl,
String loginPage) {
/**
* @param signingKey 签名密钥
* @param expiration access-token过期时间,单位:分钟
* @param signingKey 签名密钥
* @param expiration access-token过期时间,单位:分钟
* @param refreshExpiration refresh-token的过期时间,单位:分钟
*/
public record Token(String signingKey,
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://mirrors.cloud.tencent.com/gradle/gradle-8.8-bin.zip
distributionUrl=https\://mirrors.cloud.tencent.com/gradle/gradle-8.9-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
44 changes: 27 additions & 17 deletions starter/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ plugins {
java {
toolchain {
languageVersion = JavaLanguageVersion.of(21)
vendor = JvmVendorSpec.BELLSOFT
}
}

Expand All @@ -16,31 +17,40 @@ configurations {
}

springBoot {
mainClass = 'org.funcode.portal.server.starter.PortalServerApplication'
bootBuildImage {
imageName = "${rootProject.name}"
docker {
if (System.getProperty('os.name').toLowerCase().contains('windows')){
host = "//./pipe/dockerDesktopLinuxEngine"
}
}
verboseLogging = true
}
buildInfo {
properties {
artifact = 'portal-server'
name = 'portal-server'
artifact = "${rootProject.name}"
name = "${rootProject.name}"
}
}
bootJar {
launchScript()
archiveClassifier = 'boot'
archiveBaseName = "${rootProject.name}"
manifest {
attributes 'Implementation-Title': "${rootProject.name} Application",
'Implementation-Vendor': "${rootProject.name} Team",
'Start-Class': 'org.funcode.portal.server.starter.PortalServerApplication'
}
}
}

bootJar {
archiveBaseName = 'portal-server'
manifest {
attributes 'Implementation-Title': 'portal-server Application',
'Implementation-Vendor': 'portal-server Team'
}
jar {
archiveClassifier = ''
}

graalvmNative {
toolchainDetection = true
binaries {
main {
imageName = 'portal-server'
mainClass = 'org.funcode.portal.server.starter.PortalServerApplication'
verbose = true
}
}
clean {
delete rootProject.file('logs')
}

dependencies {
Expand Down
12 changes: 6 additions & 6 deletions starter/src/main/resources/docker/.env
Original file line number Diff line number Diff line change
Expand Up @@ -13,29 +13,29 @@ ADMIN_PASSWORD=admin
# Database
############
PG_DB=portal
PG_HOST=jd.lichong.host
PG_HOST=postgresql
PG_PORT=5432
PG_USER=lichong
PG_PASS=p32ggh_5dfrd_pF7a7N
PG_PASS=lichong

############
# Redis
############
REDIS_HOST=jd.lichong.host
REDIS_HOST=redis
REDIS_PORT=6379
REDIS_USER=default
REDIS_PASS=yjB4FXKcQKchREYx
REDIS_PASS=password

############
# Nacos
############
NACOS_ENABLE=false
NACOS_IP=jd.lichong.host
NACOS_IP=nacos
NACOS_PORT=8848
NACOS_NAMESPACE=public
NACOS_GROUP=DEFAULT_GROUP
NACOS_USERNAME=nacos
NACOS_PASS=lichong
NACOS_PASS=nacos

############
# API doc
Expand Down

0 comments on commit a6d3a3b

Please sign in to comment.