Commit 3924cff0 authored by Romain Loth's avatar Romain Loth

use the same ENV => INI => default strategy for SQL_HOST in php that we have...

use the same ENV => INI => default strategy for SQL_HOST in php that we have had for all config vars in py services
parent 0f92148f
......@@ -5,17 +5,40 @@
$min_num_friends=0;// nombre minimal de voisin que doit avoir un scholar pour être affiché
// $compress='No';
/* parametres externes: nom de l'hôte SQL*/
$params = parse_ini_file("config/parametres_comex.ini");
/* reading external param for SQL config
=====================================
/* tout pour le MySQL */
$host = $params['SQL_HOST'];
We attempt in order:
1 - retrieve SQL_HOST from bash ENV (set by docker-compose or admin)
2 - otherwise retrieve from INI file (buggy)
3 - otherwise try 172.17.0.2 (first docker IP)
POSSIBLE: use same behavior for the other sql vars (port, db, user & pass)
...but not absolutely necessary because they seldom change
*/
# 1 - ENV read
$sql_host = getenv("SQL_HOST");
# 2 - INI file read
if (empty($sql_host)) {
// TODO debug
$params = parse_ini_file("config/parametres_comex.ini");
$sql_host = $params['SQL_HOST'] ;
}
# 3 - default val
if (empty($sql_host)) {
$sql_host = "172.17.0.2" ;
}
# other sql vars
$db = 'comex_shared';
$user = 'root';
$pass = 'very-safe-pass';
$charset = 'utf8';
$dsn = "mysql:host=$host;dbname=$db;charset=$charset";
/* final MySQL config: will be used for all php db connections */
$dsn = "mysql:host=$sql_host;dbname=$db;charset=$charset";
$opt = [
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
......
......@@ -28,7 +28,14 @@
- "32790:9090"
links:
- comex_db_test
- doors_test
volumes:
# /!\ this uses outside conf to replace :contained conf
- ../../config:/comex2/config
environment:
# override values from parametres_comex.ini
# for a triple reason:
# - both apps have ENV vals preempt INI vals
# - the php app INI support is buggy
# - if we're here (in docker-compose) then by definition the mysql must be coming from comex_db_test container
- SQL_HOST=comex_db_test
- SQL_PORT=3306
<?php
include("php_library/parametres.php");
echo "<body><p>behold the final mysql parameters<ul><li>dsn: '$dsn',</li> <li>user: '$user',</li> <li>pass: '$pass',</li> </ul></p></body>"
// <li>opt: [".implode(",",$opt)."] </li>
?>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment