feat: release pipeline and env-supplied server key (#82)

* build: move group and version to gradle.properties

* ci: add release-please versioning and release pipeline

* feat(server): load the root key from the environment

* ci: publish key-free server archives on release
This commit is contained in:
Fiereu authored and GitHub committed 2026-08-03 11:38:03 +02:00
1 parent 8bd065fcb4
commit dfeabdc581
20 files changed
+271 -13

No files matched your search

+4
View File
@@ -16,3 +16,7 @@ GAME_DB_PASSWORD=changeMe!
GAME_DB_SEED_DEV=true GAME_DB_SEED_DEV=true
OPENMMO_SESSION_SECRET= OPENMMO_SESSION_SECRET=
# Private key for both servers. Leave empty for development, set one in production.
OPENMMO_GAME_PRIVATE_KEY=
OPENMMO_GAME_PRIVATE_KEY_FILE=
+24 -1
View File
@@ -13,6 +13,28 @@ concurrency:
cancel-in-progress: true cancel-in-progress: true
jobs: jobs:
pr-title:
name: Conventional PR title
if: github.event_name == 'pull_request'
runs-on: ubuntu-latest
steps:
- name: Check the title against the Conventional Commits spec
env:
PR_TITLE: ${{ github.event.pull_request.title }}
run: |
types='build|chore|ci|docs|feat|fix|perf|refactor|revert|style|test'
if [[ "$PR_TITLE" =~ ^($types)(\([a-z0-9._/-]+\))?!?:\ .+ ]]; then
echo "OK: $PR_TITLE"
exit 0
fi
echo "::error::PR title is not a Conventional Commit: $PR_TITLE"
echo "Expected '<type>(<optional scope>): <description>', for example:"
echo " feat(game): start a wild battle when a player steps in grass"
echo " fix(codegen): merge the duplicate branches in the text parser"
echo "Valid types: ${types//|/, }"
echo "Append '!' after the type or scope to mark a breaking change."
exit 1
ci: ci:
name: Spotless and check name: Spotless and check
runs-on: ubuntu-latest runs-on: ubuntu-latest
@@ -39,7 +61,8 @@ jobs:
if: >- if: >-
github.event_name == 'pull_request' && github.event_name == 'pull_request' &&
github.event.pull_request.head.repo.full_name == github.repository && github.event.pull_request.head.repo.full_name == github.repository &&
github.event.pull_request.user.login != 'renovate[bot]' github.event.pull_request.user.login != 'renovate[bot]' &&
!startsWith(github.head_ref, 'release-please--')
run: | run: |
./gradlew spotlessApply ./gradlew spotlessApply
if git diff --quiet; then if git diff --quiet; then
+76
View File
@@ -0,0 +1,76 @@
name: Release
on:
push:
branches: [ "master" ]
permissions:
contents: write
pull-requests: write
issues: write
concurrency:
group: release-${{ github.ref }}
cancel-in-progress: false
jobs:
release-please:
name: Prepare release
runs-on: ubuntu-latest
outputs:
released: ${{ steps.release.outputs.releases_created }}
tag: ${{ steps.release.outputs.tag_name }}
steps:
- name: Run release-please
id: release
uses: googleapis/release-please-action@v4
with:
# A PAT is needed for CI to run on the release pull request.
token: ${{ secrets.RELEASE_PLEASE_TOKEN || secrets.GITHUB_TOKEN }}
config-file: release-please-config.json
manifest-file: .release-please-manifest.json
publish:
name: Publish server distributions
needs: release-please
if: needs.release-please.outputs.released == 'true'
runs-on: ubuntu-latest
steps:
- name: Checkout the release tag
uses: actions/checkout@v7
with:
ref: ${{ needs.release-please.outputs.tag }}
submodules: recursive
- name: Set up JDK 25
uses: actions/setup-java@v5
with:
distribution: temurin
java-version: "25"
- name: Set up Gradle
uses: gradle/actions/setup-gradle@v6
# No ROMs on the runner, so dialog ids are placeholders.
- name: Build distributions
run: ./gradlew :server.login:assembleDist :server.game:assembleDist
- name: Check no keys are bundled
run: |
found=$(tar -tf server.login/build/distributions/*.tar \
&& tar -tf server.game/build/distributions/*.tar)
if grep -q '\.pem$' <<<"$found"; then
echo "::error::a distribution bundles a key"
grep '\.pem$' <<<"$found"
exit 1
fi
echo "No keys in the distributions."
- name: Attach distributions to the release
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh release upload "${{ needs.release-please.outputs.tag }}" \
server.login/build/distributions/* \
server.game/build/distributions/* \
--clobber
+3
View File
@@ -0,0 +1,3 @@
{
".": "0.1.0"
}
+26
View File
@@ -6,6 +6,7 @@
- [Description](#description) - [Description](#description)
- [Building](#building) - [Building](#building)
- [Configuration](#configuration) - [Configuration](#configuration)
- [Releases](#releases)
- [Documentation](#wiki) - [Documentation](#wiki)
- [License](LICENSE) - [License](LICENSE)
- [Disclaimer](#disclaimer) - [Disclaimer](#disclaimer)
@@ -49,6 +50,31 @@ For local-only tweaks to the container setup, create a
Docker Compose merges it automatically on `docker compose up`. 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. For deployment,supply a proper `.env` and run `docker compose -f docker-compose.yml up -d` to skip any override.
### Server key
Both servers share one private key. A local build generates it, so development
needs no setup.
Released archives ship no keys. Generate a pair with
`./gradlew :keys:generateGame` and pass the private key to both servers through
`OPENMMO_GAME_PRIVATE_KEY` (the PEM) or `OPENMMO_GAME_PRIVATE_KEY_FILE` (a path
to it). Clients need a patched build carrying the matching public key.
## Releases
[release-please](https://github.com/googleapis/release-please) cuts releases from
the commit history. Pull requests are squash merged, so their titles become the
commit messages it reads and must follow
[Conventional Commits](https://www.conventionalcommits.org/). CI rejects titles
that do not.
`feat` bumps the minor version, `fix` the patch version. Below `1.0.0` a
breaking change bumps the minor version instead of jumping to `1.0.0`.
Every push to `master` opens or updates a release pull request. Merging it tags
the release and attaches the server archives. The version lives in
`gradle.properties` and applies to every module, do not edit it by hand.
## Wiki ## Wiki
The documentation wiki can be found [here](https://openmmo.readthedocs.io/en/latest/). The documentation wiki can be found [here](https://openmmo.readthedocs.io/en/latest/).
+3
View File
@@ -82,6 +82,9 @@ tasks.register("copyKeys") {
dependsOn("copyKeysChat", "copyKeysGame", "copyKeysFeed") dependsOn("copyKeysChat", "copyKeysGame", "copyKeysFeed")
} }
// Generated keys are for local runs. Published archives ship none.
tasks.withType<Jar>().configureEach { exclude("*.pem") }
val keyCopyTasks = val keyCopyTasks =
listOf( listOf(
"copyPublicKeyChat", "copyPublicKeyChat",
@@ -1,5 +1,6 @@
package de.fiereu.openmmo.common.io package de.fiereu.openmmo.common.io
import java.io.File
import java.io.InputStream import java.io.InputStream
import java.security.KeyFactory import java.security.KeyFactory
import java.security.interfaces.ECPrivateKey import java.security.interfaces.ECPrivateKey
@@ -36,3 +37,15 @@ object PemKeyLoader {
fun resource(name: String): InputStream = fun resource(name: String): InputStream =
PemKeyLoader::class.java.classLoader.getResourceAsStream(name) PemKeyLoader::class.java.classLoader.getResourceAsStream(name)
?: error("classpath resource not found: $name") ?: error("classpath resource not found: $name")
/** Opens a PEM key. Inline wins over a file path, which wins over the classpath. */
fun pemStream(pem: String?, path: String?, resourceName: String): InputStream =
when {
!pem.isNullOrBlank() -> pem.byteInputStream(Charsets.US_ASCII)
!path.isNullOrBlank() -> File(path).inputStream()
else ->
PemKeyLoader::class.java.classLoader.getResourceAsStream(resourceName)
?: error(
"no private key. Set the key or key file environment variable, " +
"or run a local build that generates '$resourceName'.")
}
@@ -0,0 +1,52 @@
package de.fiereu.openmmo.common.io
import io.kotest.assertions.throwables.shouldThrow
import io.kotest.core.spec.style.FunSpec
import io.kotest.matchers.shouldBe
import java.security.KeyPairGenerator
import java.security.spec.ECGenParameterSpec
import java.util.Base64
import kotlin.io.path.createTempFile
import kotlin.io.path.writeText
private fun newKeyPem(): Pair<String, ByteArray> {
val generator = KeyPairGenerator.getInstance("EC")
generator.initialize(ECGenParameterSpec("secp256r1"))
val key = generator.generateKeyPair().private
val body = Base64.getMimeEncoder(64, "\n".toByteArray()).encodeToString(key.encoded)
return "-----BEGIN EC PRIVATE KEY-----\n$body\n-----END EC PRIVATE KEY-----\n" to key.encoded
}
private fun pemFile(pem: String) = createTempFile(suffix = ".pem").also { it.writeText(pem) }
class PemSourceTest :
FunSpec({
test("reads the key from inline content") {
val (pem, encoded) = newKeyPem()
PemKeyLoader.loadEcPrivate(pemStream(pem, null, "missing.pem")).encoded shouldBe encoded
}
test("reads the key from a file") {
val (pem, encoded) = newKeyPem()
PemKeyLoader.loadEcPrivate(pemStream(null, pemFile(pem).toString(), "missing.pem"))
.encoded shouldBe encoded
}
test("inline content wins over a file") {
val (pem, encoded) = newKeyPem()
val other = pemFile(newKeyPem().first)
PemKeyLoader.loadEcPrivate(pemStream(pem, other.toString(), "missing.pem")).encoded shouldBe
encoded
}
test("treats blank values as unset") {
val (pem, encoded) = newKeyPem()
PemKeyLoader.loadEcPrivate(pemStream(" ", pemFile(pem).toString(), "missing.pem"))
.encoded shouldBe encoded
}
test("fails with a helpful message when nothing supplies a key") {
val error = shouldThrow<IllegalStateException> { pemStream(null, null, "missing.pem") }
error.message!!.contains("environment variable") shouldBe true
}
})
+5
View File
@@ -5,6 +5,11 @@ org.gradle.configuration-cache=true
org.gradle.jvmargs=-Xmx3g -XX:MaxMetaspaceSize=1g org.gradle.jvmargs=-Xmx3g -XX:MaxMetaspaceSize=1g
kotlin.daemon.jvmargs=-Xmx2g -XX:MaxMetaspaceSize=1g kotlin.daemon.jvmargs=-Xmx2g -XX:MaxMetaspaceSize=1g
group=de.fiereu.openmmo
# x-release-please-start-version
version=0.1.0
# x-release-please-end
# May be overridden by the user # May be overridden by the user
pokemmo.executable=C:/Program Files/PokeMMO/PokeMMO.exe pokemmo.executable=C:/Program Files/PokeMMO/PokeMMO.exe
pokemmo.workingDir=C:/Program Files/PokeMMO pokemmo.workingDir=C:/Program Files/PokeMMO
+31
View File
@@ -0,0 +1,31 @@
{
"$schema": "https://raw.githubusercontent.com/googleapis/release-please/main/schemas/config.json",
"packages": {
".": {
"release-type": "simple",
"package-name": "openmmo",
"changelog-path": "CHANGELOG.md",
"include-component-in-tag": false,
"bump-minor-pre-major": true,
"extra-files": [
{
"type": "generic",
"path": "gradle.properties"
}
]
}
},
"changelog-sections": [
{ "type": "feat", "section": "Features" },
{ "type": "fix", "section": "Bug Fixes" },
{ "type": "perf", "section": "Performance Improvements" },
{ "type": "refactor", "section": "Code Refactoring" },
{ "type": "docs", "section": "Documentation" },
{ "type": "build", "section": "Build System", "hidden": true },
{ "type": "ci", "section": "Continuous Integration", "hidden": true },
{ "type": "chore", "section": "Miscellaneous Chores", "hidden": true },
{ "type": "style", "section": "Styles", "hidden": true },
{ "type": "test", "section": "Tests", "hidden": true },
{ "type": "revert", "section": "Reverts" }
]
}
-4
View File
@@ -8,10 +8,6 @@ plugins {
alias(libs.plugins.ksp) alias(libs.plugins.ksp)
} }
group = "de.fiereu.openmmo"
version = "0.1.0"
application { mainClass.set("de.fiereu.openmmo.server.game.MainKt") } application { mainClass.set("de.fiereu.openmmo.server.game.MainKt") }
jooqDb { packageName = "de.fiereu.openmmo.db.game" } jooqDb { packageName = "de.fiereu.openmmo.db.game" }
@@ -1,7 +1,11 @@
package de.fiereu.openmmo.server.game.config package de.fiereu.openmmo.server.game.config
import com.typesafe.config.Config
import com.typesafe.config.ConfigFactory import com.typesafe.config.ConfigFactory
private fun Config.stringOrNull(path: String): String? =
if (hasPath(path)) getString(path) else null
object ConfigLoader { object ConfigLoader {
fun load(): GameServerConfig { fun load(): GameServerConfig {
val config = ConfigFactory.load() val config = ConfigFactory.load()
@@ -12,6 +16,8 @@ object ConfigLoader {
port = config.getInt("server.port"), port = config.getInt("server.port"),
checksumSize = config.getInt("server.checksumSize"), checksumSize = config.getInt("server.checksumSize"),
rootKeyResource = config.getString("server.rootKeyResource"), rootKeyResource = config.getString("server.rootKeyResource"),
rootKey = config.stringOrNull("server.rootKey"),
rootKeyFile = config.stringOrNull("server.rootKeyFile"),
sessionSecret = secret.toByteArray(Charsets.UTF_8), sessionSecret = secret.toByteArray(Charsets.UTF_8),
db = db =
DbConfig( DbConfig(
@@ -7,6 +7,8 @@ data class GameServerConfig(
val rootKeyResource: String, val rootKeyResource: String,
val sessionSecret: ByteArray, val sessionSecret: ByteArray,
val db: DbConfig = DbConfig(), val db: DbConfig = DbConfig(),
val rootKey: String? = null,
val rootKeyFile: String? = null,
) { ) {
override fun equals(other: Any?): Boolean = override fun equals(other: Any?): Boolean =
other is GameServerConfig && other is GameServerConfig &&
@@ -14,6 +16,8 @@ data class GameServerConfig(
port == other.port && port == other.port &&
checksumSize == other.checksumSize && checksumSize == other.checksumSize &&
rootKeyResource == other.rootKeyResource && rootKeyResource == other.rootKeyResource &&
rootKey == other.rootKey &&
rootKeyFile == other.rootKeyFile &&
sessionSecret.contentEquals(other.sessionSecret) && sessionSecret.contentEquals(other.sessionSecret) &&
db == other.db db == other.db
@@ -22,6 +26,8 @@ data class GameServerConfig(
h = h * 31 + port h = h * 31 + port
h = h * 31 + checksumSize h = h * 31 + checksumSize
h = h * 31 + rootKeyResource.hashCode() h = h * 31 + rootKeyResource.hashCode()
h = h * 31 + rootKey.hashCode()
h = h * 31 + rootKeyFile.hashCode()
h = h * 31 + sessionSecret.contentHashCode() h = h * 31 + sessionSecret.contentHashCode()
h = h * 31 + db.hashCode() h = h * 31 + db.hashCode()
return h return h
@@ -6,7 +6,7 @@ import dagger.Module
import dagger.Provides import dagger.Provides
import de.fiereu.openmmo.common.auth.SessionTokenVerifier import de.fiereu.openmmo.common.auth.SessionTokenVerifier
import de.fiereu.openmmo.common.io.PemKeyLoader import de.fiereu.openmmo.common.io.PemKeyLoader
import de.fiereu.openmmo.common.io.resource import de.fiereu.openmmo.common.io.pemStream
import de.fiereu.openmmo.server.game.config.GameServerConfig import de.fiereu.openmmo.server.game.config.GameServerConfig
import de.fiereu.openmmo.server.game.script.ScriptRegistry import de.fiereu.openmmo.server.game.script.ScriptRegistry
import de.fiereu.openmmo.server.game.storage.CharacterRepository import de.fiereu.openmmo.server.game.storage.CharacterRepository
@@ -34,7 +34,8 @@ object GameServerModule {
@Provides @Provides
@Singleton @Singleton
fun rootKey(config: GameServerConfig): ECPrivateKey = fun rootKey(config: GameServerConfig): ECPrivateKey =
PemKeyLoader.loadEcPrivate(resource(config.rootKeyResource)) PemKeyLoader.loadEcPrivate(
pemStream(config.rootKey, config.rootKeyFile, config.rootKeyResource))
@Provides @Provides
@Singleton @Singleton
@@ -3,6 +3,8 @@ server {
port = 7777 port = 7777
checksumSize = 2 checksumSize = 2
rootKeyResource = "game.private.pem" rootKeyResource = "game.private.pem"
rootKey = ${?OPENMMO_GAME_PRIVATE_KEY}
rootKeyFile = ${?OPENMMO_GAME_PRIVATE_KEY_FILE}
sessionSecret = "dev-only-secret-do-not-use-in-production" sessionSecret = "dev-only-secret-do-not-use-in-production"
sessionSecret = ${?OPENMMO_SESSION_SECRET} sessionSecret = ${?OPENMMO_SESSION_SECRET}
} }
-4
View File
@@ -8,10 +8,6 @@ plugins {
alias(libs.plugins.ksp) alias(libs.plugins.ksp)
} }
group = "de.fiereu.openmmo"
version = "0.1.0"
application { mainClass.set("de.fiereu.openmmo.server.login.MainKt") } application { mainClass.set("de.fiereu.openmmo.server.login.MainKt") }
jooqDb { packageName = "de.fiereu.openmmo.db.login" } jooqDb { packageName = "de.fiereu.openmmo.db.login" }
@@ -1,7 +1,11 @@
package de.fiereu.openmmo.server.login.config package de.fiereu.openmmo.server.login.config
import com.typesafe.config.Config
import com.typesafe.config.ConfigFactory import com.typesafe.config.ConfigFactory
private fun Config.stringOrNull(path: String): String? =
if (hasPath(path)) getString(path) else null
object ConfigLoader { object ConfigLoader {
fun load(): LoginServerConfig { fun load(): LoginServerConfig {
val config = ConfigFactory.load() val config = ConfigFactory.load()
@@ -12,6 +16,8 @@ object ConfigLoader {
port = config.getInt("server.port"), port = config.getInt("server.port"),
checksumSize = config.getInt("server.checksumSize"), checksumSize = config.getInt("server.checksumSize"),
rootKeyResource = config.getString("server.rootKeyResource"), rootKeyResource = config.getString("server.rootKeyResource"),
rootKey = config.stringOrNull("server.rootKey"),
rootKeyFile = config.stringOrNull("server.rootKeyFile"),
sessionSecret = secret.toByteArray(Charsets.UTF_8), sessionSecret = secret.toByteArray(Charsets.UTF_8),
db = db =
DbConfig( DbConfig(
@@ -7,6 +7,8 @@ data class LoginServerConfig(
val rootKeyResource: String, val rootKeyResource: String,
val sessionSecret: ByteArray, val sessionSecret: ByteArray,
val db: DbConfig = DbConfig(), val db: DbConfig = DbConfig(),
val rootKey: String? = null,
val rootKeyFile: String? = null,
) { ) {
override fun equals(other: Any?): Boolean = override fun equals(other: Any?): Boolean =
other is LoginServerConfig && other is LoginServerConfig &&
@@ -14,6 +16,8 @@ data class LoginServerConfig(
port == other.port && port == other.port &&
checksumSize == other.checksumSize && checksumSize == other.checksumSize &&
rootKeyResource == other.rootKeyResource && rootKeyResource == other.rootKeyResource &&
rootKey == other.rootKey &&
rootKeyFile == other.rootKeyFile &&
sessionSecret.contentEquals(other.sessionSecret) && sessionSecret.contentEquals(other.sessionSecret) &&
db == other.db db == other.db
@@ -22,6 +26,8 @@ data class LoginServerConfig(
h = h * 31 + port h = h * 31 + port
h = h * 31 + checksumSize h = h * 31 + checksumSize
h = h * 31 + rootKeyResource.hashCode() h = h * 31 + rootKeyResource.hashCode()
h = h * 31 + rootKey.hashCode()
h = h * 31 + rootKeyFile.hashCode()
h = h * 31 + sessionSecret.contentHashCode() h = h * 31 + sessionSecret.contentHashCode()
h = h * 31 + db.hashCode() h = h * 31 + db.hashCode()
return h return h
@@ -7,7 +7,7 @@ import dagger.Module
import dagger.Provides import dagger.Provides
import de.fiereu.openmmo.common.auth.SessionTokenIssuer import de.fiereu.openmmo.common.auth.SessionTokenIssuer
import de.fiereu.openmmo.common.io.PemKeyLoader import de.fiereu.openmmo.common.io.PemKeyLoader
import de.fiereu.openmmo.common.io.resource import de.fiereu.openmmo.common.io.pemStream
import de.fiereu.openmmo.server.login.auth.JooqUserStore import de.fiereu.openmmo.server.login.auth.JooqUserStore
import de.fiereu.openmmo.server.login.auth.UserService import de.fiereu.openmmo.server.login.auth.UserService
import de.fiereu.openmmo.server.login.config.LoginServerConfig import de.fiereu.openmmo.server.login.config.LoginServerConfig
@@ -35,7 +35,8 @@ abstract class LoginServerModule {
@Provides @Provides
@Singleton @Singleton
fun rootKey(config: LoginServerConfig): ECPrivateKey = fun rootKey(config: LoginServerConfig): ECPrivateKey =
PemKeyLoader.loadEcPrivate(resource(config.rootKeyResource)) PemKeyLoader.loadEcPrivate(
pemStream(config.rootKey, config.rootKeyFile, config.rootKeyResource))
@Provides @Provides
@Singleton @Singleton
@@ -3,6 +3,8 @@ server {
port = 2106 port = 2106
checksumSize = 16 checksumSize = 16
rootKeyResource = "game.private.pem" rootKeyResource = "game.private.pem"
rootKey = ${?OPENMMO_GAME_PRIVATE_KEY}
rootKeyFile = ${?OPENMMO_GAME_PRIVATE_KEY_FILE}
sessionSecret = "dev-only-secret-do-not-use-in-production" sessionSecret = "dev-only-secret-do-not-use-in-production"
sessionSecret = ${?OPENMMO_SESSION_SECRET} sessionSecret = ${?OPENMMO_SESSION_SECRET}
} }