feat: configure the game from env variables
This commit is contained in:
parent
bc5a70c4c6
commit
8ffcccb1e8
5 changed files with 39 additions and 8 deletions
|
@ -43,6 +43,15 @@ services:
|
||||||
size: 1g
|
size: 1g
|
||||||
- planets:/opt/lwb5/site/static/beta5/pics/pl:ro
|
- planets:/opt/lwb5/site/static/beta5/pics/pl:ro
|
||||||
- pgen:/var/spool/pgen:rw
|
- pgen:/var/spool/pgen:rw
|
||||||
|
environment:
|
||||||
|
LW_DB_HOST: db
|
||||||
|
LW_DB_ADMIN_PASS_FILE: /run/secrets/lw_db_admin_pass
|
||||||
|
LW_DB_USER_PASS_FILE: /run/secrets/lw_db_user_pass
|
||||||
|
LW_SEND_MAIL: ${LW_SEND_MAIL}
|
||||||
|
LW_STATIC_URL: ${LW_STATIC_URL}
|
||||||
|
secrets:
|
||||||
|
- lw_db_user_pass
|
||||||
|
- lw_db_admin_pass
|
||||||
|
|
||||||
planetgen:
|
planetgen:
|
||||||
build:
|
build:
|
||||||
|
|
|
@ -1,6 +1,11 @@
|
||||||
# Password for the database superuser
|
# Password for the database superuser
|
||||||
DB_PASSWORD=...
|
DB_PASSWORD=...
|
||||||
|
|
||||||
|
# URL of the static assets from an external perspective
|
||||||
|
LW_STATIC_URL=http://localhost/static
|
||||||
|
# Send email? (yes or no)
|
||||||
|
LW_SEND_MAIL=no
|
||||||
|
|
||||||
# Legacyworlds database - Main user
|
# Legacyworlds database - Main user
|
||||||
LW_DB_USER_PASS=...
|
LW_DB_USER_PASS=...
|
||||||
# Legacyworlds database - Admin user
|
# Legacyworlds database - Admin user
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
$config = array(
|
$config = array(
|
||||||
// Path and URL to static contents
|
// Path and URL to static contents
|
||||||
"staticdir" => __DIR__ . "/../site/static",
|
"staticdir" => __DIR__ . "/../site/static",
|
||||||
"staticurl" => "http://localhost/static",
|
"staticurl" => getenv("LW_STATIC_URL") ?: "http://localhost/static",
|
||||||
|
|
||||||
// Path to game scripts
|
// Path to game scripts
|
||||||
"scriptdir" => __DIR__,
|
"scriptdir" => __DIR__,
|
||||||
|
@ -40,7 +40,7 @@ $config = array(
|
||||||
"trace" => array(),
|
"trace" => array(),
|
||||||
|
|
||||||
// Do we need to actually send emails?
|
// Do we need to actually send emails?
|
||||||
"sendmails" => false
|
"sendmails" => (getenv("LW_SEND_MAIL") ?: "no") == "yes",
|
||||||
);
|
);
|
||||||
|
|
||||||
if (file_exists($config['cachedir'] . "/maintenance.ser")) {
|
if (file_exists($config['cachedir'] . "/maintenance.ser")) {
|
||||||
|
|
|
@ -4,10 +4,10 @@
|
||||||
<!-- Global parameters -->
|
<!-- Global parameters -->
|
||||||
<MainParams>
|
<MainParams>
|
||||||
<!-- Database connection -->
|
<!-- Database connection -->
|
||||||
<Param name="dbhost" value="localhost" />
|
<Param name="dbhost" from-env="LW_DB_HOST" value="127.0.0.1" />
|
||||||
<Param name="dbuser" value="legacy" />
|
<Param name="dbname" from-env="LW_DB_NAME" value="legacyworlds" />
|
||||||
<Param name="dbpass" value="" />
|
<Param name="dbuser" from-env="LW_DB_USER_NAME" value="legacyworlds" />
|
||||||
<Param name="dbname" value="legacy" />
|
<Param name="dbpass" from-env="LW_DB_USER_PASS" />
|
||||||
|
|
||||||
<!-- Cookies -->
|
<!-- Cookies -->
|
||||||
<Param name="trackname" value="legacy_alpha_trk" />
|
<Param name="trackname" value="legacy_alpha_trk" />
|
||||||
|
|
|
@ -12,16 +12,33 @@ class xml_config {
|
||||||
private static $games = null;
|
private static $games = null;
|
||||||
private static $defGame = null;
|
private static $defGame = null;
|
||||||
|
|
||||||
|
private static function readFromEnv(string $varName, string $default): string {
|
||||||
|
if ($varName == '') {
|
||||||
|
return $default;
|
||||||
|
}
|
||||||
|
|
||||||
|
$fileVarName = $varName . '_FILE';
|
||||||
|
$fileName = getenv($fileVarName);
|
||||||
|
if ($fileName !== false) {
|
||||||
|
$value = @file_get_contents($fileName);
|
||||||
|
} else {
|
||||||
|
$value = getenv($varName);
|
||||||
|
}
|
||||||
|
return $value ?: $default;
|
||||||
|
}
|
||||||
|
|
||||||
private static function parseMainParams($root) {
|
private static function parseMainParams($root) {
|
||||||
$node = $root->firstChild;
|
$node = $root->firstChild;
|
||||||
|
|
||||||
while ($node) {
|
while ($node) {
|
||||||
if ($node->nodeType == XML_ELEMENT_NODE && $node->nodeName == 'Param') {
|
if ($node->nodeType == XML_ELEMENT_NODE && $node->nodeName == 'Param') {
|
||||||
$aName = $node->getAttribute('name');
|
$aName = $node->getAttribute('name');
|
||||||
$aValue = $node->getAttribute('value');
|
if ($aName == '') {
|
||||||
if ($aName == "") {
|
|
||||||
l::warn("CONFIG: a main parameter is missing a 'name' attribute");
|
l::warn("CONFIG: a main parameter is missing a 'name' attribute");
|
||||||
} elseif (!isset(xml_config::$mGame->params[$aName])) {
|
} elseif (!isset(xml_config::$mGame->params[$aName])) {
|
||||||
|
$aValue = $node->getAttribute('value');
|
||||||
|
$aFromEnv = $node->getAttribute('from-env');
|
||||||
|
$aValue = self::readFromEnv($aFromEnv, $aValue);
|
||||||
xml_config::$mGame->params[$aName] = $aValue;
|
xml_config::$mGame->params[$aName] = $aValue;
|
||||||
} else {
|
} else {
|
||||||
l::notice("CONFIG: duplicate main parameter '$aName'");
|
l::notice("CONFIG: duplicate main parameter '$aName'");
|
||||||
|
|
Loading…
Add table
Reference in a new issue