Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*.bat
*.md
mitmproxy/
29 changes: 29 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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" ]
30 changes: 30 additions & 0 deletions compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
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
NEBULA_PUBLIC_PORT: 5000
volumes:
database:
21 changes: 20 additions & 1 deletion src/main/java/emu/nebula/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -64,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;
}
Expand All @@ -72,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;
}
Expand Down
8 changes: 7 additions & 1 deletion src/main/java/emu/nebula/Nebula.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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();
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/emu/nebula/database/DatabaseManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
Loading