Skip to content

Commit 3744ca5

Browse files
committed
[FEATURE] Improve Docker support
1 parent 90820ec commit 3744ca5

5 files changed

Lines changed: 42 additions & 7 deletions

File tree

Dockerfile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
FROM azul/zulu-openjdk-debian:24-latest AS build
2+
WORKDIR /app
3+
COPY . /app
4+
RUN chmod +x && ./gradlew build --no-daemon
5+
FROM azul/zulu-openjdk-debian:24-latest AS prod
6+
WORKDIR /app/data
7+
ENV APP_HOME=/app
8+
ENV LISTEN_PORT=9274
9+
EXPOSE 9274
10+
COPY --from=build /app/components/launchserver/build/install/launchserver/* /app
11+
ENTRYPOINT ["/app/bin/launchserver"]

components/launchserver/build.gradle.kts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ dependencies {
3232
implementation(libs.jjwt.impl)
3333
implementation(libs.jjwt.gson)
3434
implementation(libs.log4j.core)
35+
implementation(libs.log4j.slf4j.impl)
3536
implementation(libs.netty.transport.epoll)
3637
implementation(libs.netty.transport.io.uring)
3738
implementation(libs.progressbar)
@@ -44,6 +45,7 @@ dependencies {
4445
implementation(libs.db.h2)
4546
implementation(libs.jline.terminal)
4647
implementation(libs.jline.reader)
48+
implementation(libs.jansi)
4749
api(project(":components:launcher-api"))
4850
annotationProcessor(libs.log4j.core)
4951
launcherInside(project(mapOf("path" to ":components:launcher-runtime", "configuration" to "shadow")))

components/launchserver/src/main/java/pro/gravit/launchserver/LaunchServer.java

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -438,17 +438,17 @@ public static class LaunchServerDirectories {
438438
public void collect() {
439439
if (updatesDir == null) updatesDir = getPath(UPDATES_NAME);
440440
if (trustStore == null) trustStore = getPath(TRUSTSTORE_NAME);
441-
if (launcherLibrariesDir == null) launcherLibrariesDir = getPath(LAUNCHERLIBRARIES_NAME);
441+
if (launcherLibrariesDir == null) launcherLibrariesDir = getStaticPath(LAUNCHERLIBRARIES_NAME);
442442
if (launcherLibrariesCompileDir == null)
443-
launcherLibrariesCompileDir = getPath(LAUNCHERLIBRARIESCOMPILE_NAME);
443+
launcherLibrariesCompileDir = getStaticPath(LAUNCHERLIBRARIESCOMPILE_NAME);
444444
if (launcherPackDir == null)
445445
launcherPackDir = getPath(LAUNCHERPACK_NAME);
446446
if (keyDirectory == null) keyDirectory = getPath(KEY_NAME);
447447
if (modules == null) modules = getPath(MODULES);
448448
if (launcherModules == null) launcherModules = getPath(LAUNCHER_MODULES);
449-
if (librariesDir == null) librariesDir = getPath(LIBRARIES);
449+
if (librariesDir == null) librariesDir = getStaticPath(LIBRARIES);
450450
if (controlFile == null) controlFile = getPath(CONTROL_FILE);
451-
if (proguardDir == null) proguardDir = getPath(PROGUARD_DIR);
451+
if (proguardDir == null) proguardDir = getStaticPath(PROGUARD_DIR);
452452
if (tmpDir == null)
453453
tmpDir = Paths.get(System.getProperty("java.io.tmpdir")).resolve("launchserver-%s".formatted(SecurityHelper.randomStringToken()));
454454
}
@@ -458,5 +458,18 @@ private Path getPath(String dirName) {
458458
if (property == null) return dir.resolve(dirName);
459459
else return Paths.get(property);
460460
}
461+
462+
private Path getStaticPath(String dirName) {
463+
String property = System.getProperty("launchserver.dir." + dirName, null);
464+
if (property == null) {
465+
String appHome = System.getenv("APP_HOME");
466+
if(appHome != null) {
467+
return Path.of(appHome).resolve(dirName);
468+
} else {
469+
return dir.resolve(dirName);
470+
}
471+
}
472+
else return Paths.get(property);
473+
}
461474
}
462475
}

components/launchserver/src/main/java/pro/gravit/launchserver/LaunchServerStarter.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -226,15 +226,23 @@ public static void generateConfigIfNotExists(Path configFile, CommandHandler com
226226
logger.error("ProjectName null. Using MineCraft");
227227
newConfig.projectName = "MineCraft";
228228
}
229-
int port = 9274;
230-
if(address.contains(":")) {
231-
String portString = address.substring(address.indexOf(':')+1);
229+
String portString = System.getenv("LISTEN_PORT");
230+
if(portString == null) {
231+
portString = System.getProperty("launchserver.listenport", null);
232+
}
233+
int port;
234+
if(portString != null) {
235+
port = Integer.parseInt(portString);
236+
} else if(address.contains(":")) {
237+
portString = address.substring(address.indexOf(':')+1);
232238
try {
233239
port = Integer.parseInt(portString);
234240
} catch (NumberFormatException e) {
241+
port = 9274;
235242
logger.warn("Unknown port {}, using 9274", portString);
236243
}
237244
} else {
245+
port = 9274;
238246
logger.info("Address {} doesn't contains port (you want to use nginx?)", address);
239247
}
240248
newConfig.netty.address = "ws://" + address + "/api";

gradle/libs.versions.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ oshi = { module = "com.github.oshi:oshi-core", version.ref = "oshi" }
2929
# LaunchServer libraries
3030
log4j-api = { module = "org.apache.logging.log4j:log4j-api", version.ref = "log4j" }
3131
log4j-core = { module = "org.apache.logging.log4j:log4j-core", version.ref = "log4j" }
32+
log4j-slf4j-impl = { module = "org.apache.logging.log4j:log4j-slf4j2-impl", version.ref = "log4j" }
3233
netty-codec-http = { module = "io.netty:netty-codec-http", version.ref = "netty" }
3334
netty-transport-epoll = { module = "io.netty:netty-transport-native-epoll", version.ref = "netty" }
3435
netty-transport-io-uring = { module = "io.netty:netty-transport-native-io_uring", version.ref = "netty" }

0 commit comments

Comments
 (0)