From 53c127d754fdb43802667eb0c7e9839d7efba70d Mon Sep 17 00:00:00 2001 From: Fishia <74685931+fishiatee@users.noreply.github.com> Date: Mon, 20 Apr 2026 21:31:51 +0700 Subject: [PATCH 1/3] feat: introduce docker and compose --- .dockerignore | 3 ++ Dockerfile | 29 +++++++++++++++++++ compose.yaml | 29 +++++++++++++++++++ src/main/java/emu/nebula/Config.java | 15 ++++++++-- src/main/java/emu/nebula/Nebula.java | 8 ++++- .../emu/nebula/database/DatabaseManager.java | 6 ++-- 6 files changed, 85 insertions(+), 5 deletions(-) create mode 100644 .dockerignore create mode 100644 Dockerfile create mode 100644 compose.yaml diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..7806296 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,3 @@ +*.bat +*.md +mitmproxy/ \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..f1637d8 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,29 @@ +# Build Nebula.jar +FROM eclipse-temurin:21-jdk-alpine-3.23 AS build +WORKDIR /build +RUN apk add --no-cache gradle +COPY . . +RUN gradle jar + +# Grab latest resources +FROM alpine:3.23 AS resources +WORKDIR /build +RUN apk add --no-cache git wget +RUN git clone --depth=1 https://github.com/Hiro420/StellaSoraData +RUN wget https://nova-static.stellasora.global/meta/and.html +RUN wget https://nova-static.stellasora.global/meta/win.html + +# Final image +# Resources are included in the image for the sake of convenience. +FROM eclipse-temurin:25-alpine-3.23 +WORKDIR /app +EXPOSE 80 +RUN apk add --no-cache curl +HEALTHCHECK --interval=5s --timeout=15s --retries=3 --start-period=10s CMD [ "curl", "http://127.0.0.1:80" ] +RUN mkdir /app/resources && mkdir /app/web && mkdir /app/web/meta +COPY --from=build /build/Nebula.jar . +COPY --from=resources /build/StellaSoraData/EN/bin/ /app/resources/bin/ +COPY --from=resources /build/StellaSoraData/EN/language/ /app/resources/language/ +COPY --from=resources /build/and.html /app/web/meta/and.html +COPY --from=resources /build/win.html /app/web/meta/win.html +CMD [ "java", "-jar", "/app/Nebula.jar", "-nohandbook" ] \ No newline at end of file diff --git a/compose.yaml b/compose.yaml new file mode 100644 index 0000000..bdda610 --- /dev/null +++ b/compose.yaml @@ -0,0 +1,29 @@ +services: + mongodb: + image: mongo:8.2.7 + # https://gist.github.com/maitrungduc1410/f2f7b34d2e736912471b006c6dba17e5 + healthcheck: + test: echo 'db.runCommand("ping").ok' | mongosh mongodb://localhost:27017/nebula --quiet + interval: 5s + timeout: 15s + retries: 3 + start_period: 10s + volumes: + - database:/data/db/ + restart: unless-stopped + nebula: + build: . + depends_on: + - mongodb + restart: unless-stopped + ports: + - "5000:80" + volumes: + - ./data/:/app/data/ + # - ./plugins/:/app/plugins/ + # - ./cdn/:/app/web/res + environment: + NEBULA_MONGODB_HOST: mongodb + NEBULA_MONGODB_PORT: 27017 +volumes: + database: \ No newline at end of file diff --git a/src/main/java/emu/nebula/Config.java b/src/main/java/emu/nebula/Config.java index eae62b9..8a4746d 100644 --- a/src/main/java/emu/nebula/Config.java +++ b/src/main/java/emu/nebula/Config.java @@ -36,13 +36,24 @@ public static class DatabaseInfo { public String uri = "mongodb://localhost:27017"; public String collection = "nebula"; public boolean useInternal = true; + + public String getConnectionString() { + if (System.getenv("NEBULA_MONGODB_HOST") != null) { + int port = 80; + if (System.getenv("NEBULA_MONGODB_PORT") != null) { + port = Integer.parseInt(System.getenv("NEBULA_MONGODB_PORT")); + } + this.uri = "mongodb://" + System.getenv("NEBULA_MONGODB_HOST") + ":" + port; + } + return this.uri; + } } @Getter public static class InternalMongoInfo { public String address = "localhost"; public int port = 27017; - public String filePath = "database.mv"; + public String filePath = "./data/database.mv"; } @Getter @@ -56,7 +67,7 @@ private static class ServerConfig { public boolean useSSL = false; public String bindAddress = "0.0.0.0"; public int bindPort; - public String publicAddress = "127.0.0.1"; // Will return bindAddress if publicAddress is null + public String publicAddress; // Will return bindAddress if publicAddress is null public Integer publicPort; // Will return bindPort if publicPort is null public ServerConfig(int port) { diff --git a/src/main/java/emu/nebula/Nebula.java b/src/main/java/emu/nebula/Nebula.java index 84521db..65bad60 100644 --- a/src/main/java/emu/nebula/Nebula.java +++ b/src/main/java/emu/nebula/Nebula.java @@ -27,7 +27,8 @@ public class Nebula { private static final Logger log = LoggerFactory.getLogger(Nebula.class); // Config - private static final File configFile = new File("./config.json"); + private static final File dataDir = new File("./data"); + private static final File configFile = new File("./data/config.json"); @Getter private static Config config; // Database @@ -49,6 +50,11 @@ public static void main(String[] args) { // Start Server Nebula.getLogger().info("Starting Nebula " + getJarVersion()); Nebula.getLogger().info("Git hash: " + getGitHash()); + + // Create data directory if it doesn't exist yet + if (!dataDir.exists()) { + dataDir.mkdirs(); + } // Load config and data versions first Nebula.loadConfig(); diff --git a/src/main/java/emu/nebula/database/DatabaseManager.java b/src/main/java/emu/nebula/database/DatabaseManager.java index 20303f4..cd382b6 100644 --- a/src/main/java/emu/nebula/database/DatabaseManager.java +++ b/src/main/java/emu/nebula/database/DatabaseManager.java @@ -46,10 +46,12 @@ public final class DatabaseManager { public DatabaseManager(DatabaseInfo info, ServerType type) { // Variables var internalConfig = Nebula.getConfig().getInternalMongoServer(); - String connectionString = info.getUri(); + String connectionString = info.getConnectionString(); + + boolean useMongo = System.getenv("NEBULA_MONGODB_HOST") != null; // Start local mongo server - if (info.isUseInternal()) { + if (info.isUseInternal() && !useMongo) { if (Utils.isPortOpen(internalConfig.getAddress(), internalConfig.getPort())) { connectionString = startInternalMongoServer(internalConfig); Nebula.getLogger().info("Started local MongoDB server at " + server.getConnectionString()); From 2a9707c36ea9a5ac9e8b87c1ebed2cc6e698ace3 Mon Sep 17 00:00:00 2001 From: Fishia <74685931+fishiatee@users.noreply.github.com> Date: Thu, 23 Apr 2026 12:50:53 +0700 Subject: [PATCH 2/3] feat: add public host/port env var Added `NEBULA_PUBLIC_HOST` and `NEBULA_PUBLIC_PORT` environment variables. Will override config values. --- src/main/java/emu/nebula/Config.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/main/java/emu/nebula/Config.java b/src/main/java/emu/nebula/Config.java index 8a4746d..37dbd14 100644 --- a/src/main/java/emu/nebula/Config.java +++ b/src/main/java/emu/nebula/Config.java @@ -67,7 +67,7 @@ private static class ServerConfig { public boolean useSSL = false; public String bindAddress = "0.0.0.0"; public int bindPort; - public String publicAddress; // Will return bindAddress if publicAddress is null + public String publicAddress = "127.0.0.1"; // Will return bindAddress if publicAddress is null public Integer publicPort; // Will return bindPort if publicPort is null public ServerConfig(int port) { @@ -75,6 +75,10 @@ public ServerConfig(int port) { } public String getPublicAddress() { + if (System.getenv("NEBULA_PUBLIC_HOST") != null) { + return System.getenv("NEBULA_PUBLIC_HOST"); + } + if (this.publicAddress != null && !this.publicAddress.isEmpty()) { return this.publicAddress; } @@ -83,6 +87,10 @@ public String getPublicAddress() { } public int getPublicPort() { + if (System.getenv("NEBULA_PUBLIC_PORT") != null) { + return Integer.parseInt(System.getenv("NEBULA_PUBLIC_PORT")); + } + if (this.publicPort != null && this.publicPort != 0) { return this.publicPort; } From 8638a85e46f23f023cead718e0d5922b728827e9 Mon Sep 17 00:00:00 2001 From: Fishia <74685931+fishiatee@users.noreply.github.com> Date: Thu, 23 Apr 2026 12:55:15 +0700 Subject: [PATCH 3/3] chore: update compose manifest Add `NEBULA_PUBLIC_PORT` environment variable for serverlist. --- compose.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/compose.yaml b/compose.yaml index bdda610..07fbf3e 100644 --- a/compose.yaml +++ b/compose.yaml @@ -25,5 +25,6 @@ services: environment: NEBULA_MONGODB_HOST: mongodb NEBULA_MONGODB_PORT: 27017 + NEBULA_PUBLIC_PORT: 5000 volumes: database: \ No newline at end of file