Dockerize Nebula (#31)

* feat: introduce docker and compose

* feat: add public host/port env var

Added `NEBULA_PUBLIC_HOST` and `NEBULA_PUBLIC_PORT` environment variables. Will override config values.

* chore: update compose manifest

Add `NEBULA_PUBLIC_PORT` environment variable for serverlist.
This commit is contained in:
Fishia
2026-04-23 03:09:23 -07:00
committed by GitHub
parent 995f67e86c
commit 8f07ae06d8
6 changed files with 93 additions and 4 deletions
+20 -1
View File
@@ -36,13 +36,24 @@ public class Config {
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
@@ -64,6 +75,10 @@ public class Config {
}
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;
}
@@ -72,6 +87,10 @@ public class Config {
}
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;
}
+7 -1
View File
@@ -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 class Nebula {
// 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();
@@ -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());