From 1510413a1632f7545155b383a1de06ddde11f488 Mon Sep 17 00:00:00 2001 From: Fiereu Date: Mon, 8 Jun 2026 15:42:23 +0200 Subject: [PATCH] chore: remove .env file --- .env => .env.example | 22 ++++++++++++++-------- .gitignore | 9 ++++++++- README.md | 18 ++++++++++++++++++ build.gradle.kts | 34 ++-------------------------------- compose-dev.yaml | 21 --------------------- docker-compose.yml | 29 +++++++++++++++++++++++++++++ gradle.properties | 10 ---------- gradle/libs.versions.toml | 4 +++- server.game/build.gradle.kts | 5 +++++ server.login/build.gradle.kts | 5 +++++ 10 files changed, 84 insertions(+), 73 deletions(-) rename .env => .env.example (57%) delete mode 100644 compose-dev.yaml create mode 100644 docker-compose.yml diff --git a/.env b/.env.example similarity index 57% rename from .env rename to .env.example index e5039ef..18f3bdb 100644 --- a/.env +++ b/.env.example @@ -1,8 +1,14 @@ -LOGIN_DB_PORT=20011 -LOGIN_DB_NAME=openmmo_login_db -LOGIN_DB_USER=openmmo_login_user -LOGIN_DB_PASSWORD=changeMe! -GAME_DB_PORT=20021 -GAME_DB_NAME=openmmo_game_db -GAME_DB_USER=openmmo_game_user -GAME_DB_PASSWORD=changeMe! +# Copy this file to `.env` and adjust the values for your environment. +# `.env` is gitignored and must never be committed. + +LOGIN_DB_PORT=20011 +LOGIN_DB_NAME=openmmo_login_db +LOGIN_DB_USER=openmmo_login_user +LOGIN_DB_PASSWORD=changeMe! + +GAME_DB_PORT=20021 +GAME_DB_NAME=openmmo_game_db +GAME_DB_USER=openmmo_game_user +GAME_DB_PASSWORD=changeMe! + +OPENMMO_SESSION_SECRET= \ No newline at end of file diff --git a/.gitignore b/.gitignore index 108d567..4b3784b 100644 --- a/.gitignore +++ b/.gitignore @@ -39,4 +39,11 @@ bin/ .vscode/ ### Mac OS ### -.DS_Store \ No newline at end of file +.DS_Store + ++### Local environment / secrets ### ++# Never commit local config or secrets. Use `.env.example` as the template. ++.env ++.env.* ++!.env.example ++docker-compose.override.yml diff --git a/README.md b/README.md index a34f4b6..d679d20 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,7 @@ ## ToC - [Description](#description) +- [Configuration](#configuration) - [Documentation](#wiki) - [License](LICENSE) - [Disclaimer](#disclaimer) @@ -15,6 +16,23 @@ OpenMMO is an open-source implementation of the PokeMMO server. The goal is it to provide a free and open-source alternative to the PokeMMO server. +## Configuration + +All local configuration and secrets live in a `.env` file at the repository +root. It is **gitignored**, never commit it. Use the tracked +[`.env.example`](.env.example) as the template: + +```bash +cp .env.example .env # then edit the values +docker compose up -d # start all docker containers +./gradlew runAll # build and run the servers +``` + +For local-only tweaks to the container setup, create a +`docker-compose.override.yml` (also gitignored). +Docker Compose merges it automatically on `docker compose up`. +For deployment,supply a proper `.env` and run `docker compose -f docker-compose.yml up -d` to skip any override. + ## Wiki The documentation wiki can be found [here](https://forge.fiereu.de/OpenMMO/OpenMMO/wiki). diff --git a/build.gradle.kts b/build.gradle.kts index 3b2298e..d59b2eb 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,33 +1,3 @@ -allprojects { - beforeEvaluate { - loadEnvFile("${rootDir.absolutePath}/.env") - } +plugins { + alias(libs.plugins.dotenv) } - -fun loadEnvFile(fileName: String) { - val file = rootProject.file(fileName) - if (file.exists()) { - file.forEachLine { line -> - if (line.isNotBlank() && !line.startsWith("#")) { - val parts = line.split("=", limit = 2) - if (parts.size == 2) { - System.setProperty(parts[0].trim(), parts[1].trim()) - } else { - throw IllegalArgumentException("Invalid line in env file: $line") - } - } - } - } else { - throw IllegalArgumentException("Env file '$fileName' does not exist.") - } -} - -tasks.register("runAll") { - group = "application" - description = "Runs all servers and the patcher" - listOf( - ":server.login:run", - ":server.game:run", - ":patcher:run" - ).forEach { dependsOn(it) } -} \ No newline at end of file diff --git a/compose-dev.yaml b/compose-dev.yaml deleted file mode 100644 index 5e3f516..0000000 --- a/compose-dev.yaml +++ /dev/null @@ -1,21 +0,0 @@ -services: - login-db: - image: postgres:latest - container_name: login-db - restart: unless-stopped - environment: - POSTGRES_DB: $LOGIN_DB_NAME - POSTGRES_USER: $LOGIN_DB_USER - POSTGRES_PASSWORD: $LOGIN_DB_PASSWORD - ports: - - $LOGIN_DB_PORT:5432 - game-db: - image: postgres:latest - container_name: game-db - restart: unless-stopped - environment: - POSTGRES_DB: $GAME_DB_NAME - POSTGRES_USER: $GAME_DB_USER - POSTGRES_PASSWORD: $GAME_DB_PASSWORD - ports: - - $GAME_DB_PORT:5432 \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..ddf76c0 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,29 @@ +services: + login-db: + image: postgres:18 + container_name: login-db + restart: unless-stopped + environment: + POSTGRES_DB: ${LOGIN_DB_NAME:-openmmo_login_db} + POSTGRES_USER: ${LOGIN_DB_USER:-openmmo_login_user} + POSTGRES_PASSWORD: ${LOGIN_DB_PASSWORD:?LOGIN_DB_PASSWORD is required (see .env.example)} + ports: + - ${LOGIN_DB_PORT:-20011}:5432 + volumes: + - login_db_data:/var/lib/postgresql + game-db: + image: postgres:18 + container_name: game-db + restart: unless-stopped + environment: + POSTGRES_DB: ${GAME_DB_NAME:-openmmo_game_db} + POSTGRES_USER: ${GAME_DB_USER:-openmmo_game_user} + POSTGRES_PASSWORD: ${GAME_DB_PASSWORD:?GAME_DB_PASSWORD is required (see .env.example)} + ports: + - ${GAME_DB_PORT:-20021}:5432 + volumes: + - game_db_data:/var/lib/postgresql + +volumes: + login_db_data: + game_db_data: \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index f0d09dc..fa76952 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,16 +1,6 @@ org.gradle.caching=true org.gradle.configuration-cache=true -# Database settings -openmmo.db.login.port=${LOGIN_DB_PORT} -openmmo.db.login.name=${LOGIN_DB_NAME} -openmmo.db.login.user=${LOGIN_DB_USER} -openmmo.db.login.password=${LOGIN_DB_PASSWORD} -openmmo.db.game.port=${GAME_DB_PORT} -openmmo.db.game.name=${GAME_DB_NAME} -openmmo.db.game.user=${GAME_DB_USER} -openmmo.db.game.password=${GAME_DB_PASSWORD} - # PokeMMO constants pokemmo.mainClass=com.pokeemu.client.Client diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 7340b3a..564c12c 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -21,6 +21,7 @@ typesafe-config = "1.4.4" dagger = "2.57" ksp = "2.3.8" ineter = "0.3.1" +dotenv = "4.0.0" [libraries] kotlinGradlePlugin = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kotlin" } @@ -68,4 +69,5 @@ kotest = ["kotest-core", "kotest-assertions", "kotest-framework"] kotlin-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" } jooq = { id = "org.jooq.jooq-codegen-gradle", version.ref = "jooq" } flyway = { id = "org.flywaydb.flyway", version.ref = "flyway" } -ksp = { id = "com.google.devtools.ksp", version.ref = "ksp" } \ No newline at end of file +ksp = { id = "com.google.devtools.ksp", version.ref = "ksp" } +dotenv = { id = "co.uzzu.dotenv.gradle", version.ref = "dotenv" } diff --git a/server.game/build.gradle.kts b/server.game/build.gradle.kts index 2f54a58..15b41c0 100644 --- a/server.game/build.gradle.kts +++ b/server.game/build.gradle.kts @@ -31,6 +31,11 @@ dependencies { testImplementation(libs.kotlinx.coroutines.test) } +tasks.named("run") { + listOf("OPENMMO_SESSION_SECRET", "GAME_DB_PORT", "GAME_DB_NAME", "GAME_DB_USER", "GAME_DB_PASSWORD") + .forEach { key -> env.fetchOrNull(key)?.let { environment(key, it) } } +} + listOf("classes", "processResources").forEach { taskName -> tasks.named(taskName) { dependsOn("copyPublicKeyGame", "copyPrivateKeyGame") } } diff --git a/server.login/build.gradle.kts b/server.login/build.gradle.kts index fa52cd6..f365dcc 100644 --- a/server.login/build.gradle.kts +++ b/server.login/build.gradle.kts @@ -30,6 +30,11 @@ dependencies { testImplementation(libs.kotlinx.coroutines.test) } +tasks.named("run") { + listOf("OPENMMO_SESSION_SECRET", "LOGIN_DB_PORT", "LOGIN_DB_NAME", "LOGIN_DB_USER", "LOGIN_DB_PASSWORD") + .forEach { key -> env.fetchOrNull(key)?.let { environment(key, it) } } +} + listOf("classes", "processResources").forEach { taskName -> tasks.named(taskName) { dependsOn("copyPublicKeyGame", "copyPrivateKeyGame") } }