add docker, update gradle wrapper

- added Dockerfile and simple example docker-compose.yml
- upgrade gradle wrapper: 7.5.1 -> 8.2.1
- tiny code refactor
This commit is contained in:
A.C.Sukazyo Eyre 2023-08-15 14:10:13 +08:00
parent 518bde9404
commit 69a33933f5
Signed by: Eyre_S
GPG Key ID: C17CE40291207874
7 changed files with 79 additions and 26 deletions

17
.dockerignore Normal file
View File

@ -0,0 +1,17 @@
# IDE
.idea/
.vscode/
.gradle/
.settings/
/src/test/java/test/*
/src/test/resources/test/*
#build
/build/
/bin/
.project
lcoal.properties
# debug dir
/run/

21
Dockerfile Normal file
View File

@ -0,0 +1,21 @@
FROM eclipse-temurin:20-jdk as build
LABEL authors="A.C.Sukazyo Eyre"
COPY . /app/source/
WORKDIR /app
RUN cd ./source \
&& ./gradlew shadowJar -PdockerBuild \
&& cd .. \
&& cp ./source/build/libs/morny-coeur-docker-build.jar ./morny-coeur.jar
#&& rm -r ./source \
#&& rm -r /root/.gradle \
FROM eclipse-temurin:20-jre
COPY --from=build /app/morny-coeur.jar /app/morny-coeur.jar
WORKDIR /app
ENTRYPOINT ["java", "-jar", "morny-coeur.jar"]
CMD ["-q", "-v"]

View File

@ -1,36 +1,36 @@
import org.ajoberstar.grgit.Status
import java.nio.charset.Charset
import java.nio.charset.StandardCharsets
plugins { plugins {
id 'java' id 'java'
id 'java-library' id 'java-library'
id 'application' id 'application'
id 'maven-publish' id 'maven-publish'
id 'com.github.johnrengelman.shadow' version '7.1.2' id 'com.github.johnrengelman.shadow' version '8.1.1'
id 'com.github.gmazzo.buildconfig' version '3.1.0' id 'com.github.gmazzo.buildconfig' version '3.1.0'
id 'org.ajoberstar.grgit' version '5.0.0' id 'org.ajoberstar.grgit' version '5.2.0'
} }
import org.ajoberstar.grgit.Status
import java.nio.charset.Charset
import java.nio.charset.StandardCharsets
final boolean proj_git = grgit!=null final boolean proj_git = grgit!=null
final String proj_store = MORNY_CODE_STORE final String proj_store = MORNY_CODE_STORE
final String proj_commit = proj_git ? grgit.head().id : null final String proj_commit = proj_git ? grgit.head().id : null
final String proj_commit_path = MORNY_COMMIT_PATH final String proj_commit_path = MORNY_COMMIT_PATH
final boolean proj_clean = isCleanBuild() final boolean proj_clean = isCleanBuild()
if (!proj_git) if (!proj_git)
print "[MornyBuild] git repository not available for current working space! git version tag will be disabled." println "[MornyBuild] git repository not available for current working space! git version tag will be disabled."
else if (isCleanBuild()) { else if (isCleanBuild()) {
print "git: clean build at ${grgit.head().id}" println "git: clean build at ${grgit.head().id}"
} else { } else {
final Status status = grgit.status() final Status status = grgit.status()
print "git: non-clean-build" println "git: non-clean-build"
if (!status.unstaged.allChanges.empty) { if (!status.unstaged.allChanges.empty) {
print "\ngit: unstaged changes" println "git: unstaged changes"
listChanges(status.unstaged) listChanges(status.unstaged)
} }
if (!status.staged.allChanges.empty) { if (!status.staged.allChanges.empty) {
print "\ngit: staged changes" println "git: staged changes"
listChanges(status.staged) listChanges(status.staged)
} }
} }
@ -134,7 +134,15 @@ buildConfig {
} }
shadowJar { shadowJar {
archiveClassifier.set "fat" archiveClassifier.set "fat"
if (project.hasProperty("dockerBuild")) {
println "shadow-jar: using docker build name"
archiveVersion.set ""
archiveClassifier.set "docker-build"
}
} }
@SuppressWarnings("all") @SuppressWarnings("all")
@ -151,11 +159,11 @@ boolean isCleanBuild () {
void listChanges (Status.Changes listing) { void listChanges (Status.Changes listing) {
for (String file in listing.added) for (String file in listing.added)
print "\n add: ${file}" println " add: ${file}"
for (String file in listing.modified) for (String file in listing.modified)
print "\n mod: ${file}" println " mod: ${file}"
for (String file in listing.removed) for (String file in listing.removed)
print "\n del: ${file}" println " del: ${file}"
} }
publishing { publishing {

4
docker-compose.yml Normal file
View File

@ -0,0 +1,4 @@
services:
coeur-app:
build: .
command: -v

View File

@ -5,7 +5,7 @@ MORNY_ARCHIVE_NAME = morny-coeur
MORNY_CODE_STORE = https://github.com/Eyre-S/Coeur-Morny-Cono MORNY_CODE_STORE = https://github.com/Eyre-S/Coeur-Morny-Cono
MORNY_COMMIT_PATH = https://github.com/Eyre-S/Coeur-Morny-Cono/commit/%s MORNY_COMMIT_PATH = https://github.com/Eyre-S/Coeur-Morny-Cono/commit/%s
VERSION = 1.0.0-RC3.7 VERSION = 1.0.0-RC3.8
USE_DELTA = false USE_DELTA = false
VERSION_DELTA = VERSION_DELTA =

View File

@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip distributionUrl=https\://services.gradle.org/distributions/gradle-8.2.1-bin.zip
zipStoreBase=GRADLE_USER_HOME zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists zipStorePath=wrapper/dists

View File

@ -97,6 +97,7 @@ public class ServerMain {
List<String> unknownArgs = new ArrayList<>(); List<String> unknownArgs = new ArrayList<>();
//# 从命令行参数设置启动参数
for (int i = 0; i < args.length; i++) { for (int i = 0; i < args.length; i++) {
if (args[i].startsWith("-")) { if (args[i].startsWith("-")) {
@ -200,6 +201,17 @@ public class ServerMain {
} }
//# 从环境变量设置启动参数
String propToken = null;
String propTokenKey = null;
for (String iKey : MornyConfig.PROP_TOKEN_KEY) {
if (System.getenv(iKey) != null) {
propToken = System.getenv(iKey);
propTokenKey = iKey;
}
}
//# //#
//# 启动信息输出 //# 启动信息输出
//# 启动相关参数的检查和处理 //# 启动相关参数的检查和处理
@ -215,15 +227,6 @@ public class ServerMain {
logger.debug("Debug log output enabled."); logger.debug("Debug log output enabled.");
String propToken = null;
String propTokenKey = null;
for (String iKey : MornyConfig.PROP_TOKEN_KEY) {
if (System.getenv(iKey) != null) {
propToken = System.getenv(iKey);
propTokenKey = iKey;
}
}
if (versionEchoMode) { if (versionEchoMode) {
logger.info(String.format(""" logger.info(String.format("""