mirror of
https://github.com/Melledy/Nebula.git
synced 2026-09-19 17:19:58 +02:00
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:
@@ -0,0 +1,3 @@
|
|||||||
|
*.bat
|
||||||
|
*.md
|
||||||
|
mitmproxy/
|
||||||
+29
@@ -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" ]
|
||||||
@@ -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:
|
||||||
@@ -36,13 +36,24 @@ public class Config {
|
|||||||
public String uri = "mongodb://localhost:27017";
|
public String uri = "mongodb://localhost:27017";
|
||||||
public String collection = "nebula";
|
public String collection = "nebula";
|
||||||
public boolean useInternal = true;
|
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
|
@Getter
|
||||||
public static class InternalMongoInfo {
|
public static class InternalMongoInfo {
|
||||||
public String address = "localhost";
|
public String address = "localhost";
|
||||||
public int port = 27017;
|
public int port = 27017;
|
||||||
public String filePath = "database.mv";
|
public String filePath = "./data/database.mv";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
@@ -64,6 +75,10 @@ public class Config {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public String getPublicAddress() {
|
public String getPublicAddress() {
|
||||||
|
if (System.getenv("NEBULA_PUBLIC_HOST") != null) {
|
||||||
|
return System.getenv("NEBULA_PUBLIC_HOST");
|
||||||
|
}
|
||||||
|
|
||||||
if (this.publicAddress != null && !this.publicAddress.isEmpty()) {
|
if (this.publicAddress != null && !this.publicAddress.isEmpty()) {
|
||||||
return this.publicAddress;
|
return this.publicAddress;
|
||||||
}
|
}
|
||||||
@@ -72,6 +87,10 @@ public class Config {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public int getPublicPort() {
|
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) {
|
if (this.publicPort != null && this.publicPort != 0) {
|
||||||
return this.publicPort;
|
return this.publicPort;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,7 +27,8 @@ public class Nebula {
|
|||||||
private static final Logger log = LoggerFactory.getLogger(Nebula.class);
|
private static final Logger log = LoggerFactory.getLogger(Nebula.class);
|
||||||
|
|
||||||
// Config
|
// 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;
|
@Getter private static Config config;
|
||||||
|
|
||||||
// Database
|
// Database
|
||||||
@@ -50,6 +51,11 @@ public class Nebula {
|
|||||||
Nebula.getLogger().info("Starting Nebula " + getJarVersion());
|
Nebula.getLogger().info("Starting Nebula " + getJarVersion());
|
||||||
Nebula.getLogger().info("Git hash: " + getGitHash());
|
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
|
// Load config and data versions first
|
||||||
Nebula.loadConfig();
|
Nebula.loadConfig();
|
||||||
Nebula.loadDataVersions();
|
Nebula.loadDataVersions();
|
||||||
|
|||||||
@@ -46,10 +46,12 @@ public final class DatabaseManager {
|
|||||||
public DatabaseManager(DatabaseInfo info, ServerType type) {
|
public DatabaseManager(DatabaseInfo info, ServerType type) {
|
||||||
// Variables
|
// Variables
|
||||||
var internalConfig = Nebula.getConfig().getInternalMongoServer();
|
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
|
// Start local mongo server
|
||||||
if (info.isUseInternal()) {
|
if (info.isUseInternal() && !useMongo) {
|
||||||
if (Utils.isPortOpen(internalConfig.getAddress(), internalConfig.getPort())) {
|
if (Utils.isPortOpen(internalConfig.getAddress(), internalConfig.getPort())) {
|
||||||
connectionString = startInternalMongoServer(internalConfig);
|
connectionString = startInternalMongoServer(internalConfig);
|
||||||
Nebula.getLogger().info("Started local MongoDB server at " + server.getConnectionString());
|
Nebula.getLogger().info("Started local MongoDB server at " + server.getConnectionString());
|
||||||
|
|||||||
Reference in New Issue
Block a user