diff --git a/.env.example b/.env.example index dedd5f15..3865c9fb 100644 --- a/.env.example +++ b/.env.example @@ -28,6 +28,7 @@ CONFIG_DB_HOST= CONFIG_DB_USER= CONFIG_DB_PASSWORD= CONFIG_DB_DATABASE= +CONFIG_DB_PORT=3306 CONFIG_DB_SSL_MODE=DISABLED # Debug DB credentials (used when CONFIG_DB_TARGET=debug) @@ -36,4 +37,19 @@ CONFIG_DB_DEBUG_HOST=mysql-debug CONFIG_DB_DEBUG_USER=root CONFIG_DB_DEBUG_PASSWORD=debug_root_password CONFIG_DB_DEBUG_DATABASE=nnks_db_debug +CONFIG_DB_DEBUG_PORT=3306 CONFIG_DB_DEBUG_SSL_MODE=DISABLED + +# Redis credentials +REDIS_CONFIG_HOST=redis +REDIS_CONFIG_DATABASE=0 +REDIS_CONFIG_PASSWORD= +REDIS_CONFIG_PORT=6379 +REDIS_CONFIG_USER=default + +# Redis debug credentials +REDIS_CONFIG_DEBUG_HOST=redis +REDIS_CONFIG_DEBUG_DATABASE=0 +REDIS_CONFIG_DEBUG_PASSWORD= +REDIS_CONFIG_DEBUG_PORT=6379 +REDIS_CONFIG_DEBUG_USER=default diff --git a/config.example.php b/config.example.php index ffa2c492..1f2dac15 100644 --- a/config.example.php +++ b/config.example.php @@ -72,7 +72,8 @@ if (isset($_ENV['USE_ENV']) && $_ENV['USE_ENV'] === 'true') { 'REDIS_CONFIG_DATABASE' => 'database', 'REDIS_CONFIG_PASSWORD' => 'password', 'REDIS_CONFIG_PORT' => 'port', - 'REDIS_CONFIG_USER' => 'user' + 'REDIS_CONFIG_USER' => 'user', + 'REDIS_CONFIG_DEBUG_PASSWORD' => 'debug_password' ]; $dbTarget = strtolower(trim((string)($_ENV['CONFIG_DB_TARGET'] ?? 'live'))); if ($dbTarget !== 'live' && $dbTarget !== 'debug') { diff --git a/services/nginx/app/config.php b/services/nginx/app/config.php index feae1854..05de4172 100644 --- a/services/nginx/app/config.php +++ b/services/nginx/app/config.php @@ -28,7 +28,8 @@ if (isset($_ENV['USE_ENV']) && $_ENV['USE_ENV'] === 'true') { 'REDIS_CONFIG_DATABASE' => 'database', 'REDIS_CONFIG_PASSWORD' => 'password', 'REDIS_CONFIG_PORT' => 'port', - 'REDIS_CONFIG_USER' => 'user' + 'REDIS_CONFIG_USER' => 'user', + 'REDIS_CONFIG_DEBUG_PASSWORD' => 'debug_password' ]; $dbTarget = strtolower(trim((string)($_ENV['CONFIG_DB_TARGET'] ?? 'live'))); if ($dbTarget !== 'live' && $dbTarget !== 'debug') { diff --git a/services/nginx/app/routes/workerRoute.php b/services/nginx/app/routes/workerRoute.php index 5bcb59bb..b25c81aa 100644 --- a/services/nginx/app/routes/workerRoute.php +++ b/services/nginx/app/routes/workerRoute.php @@ -125,7 +125,7 @@ class workerRoute }); $this->get('/worker/status', function () { global /** @var router $router */ - $response, $router, $db; + $response, $router, $db, $REDIS_CONFIG, $CONFIG_DB; $response->success([ 'message' => 'Worker is running', 'status' => 'OK', @@ -135,18 +135,17 @@ class workerRoute 'version' => '1.0.1', 'routes' => $router->countRoutes(), 'redis' => [ - 'host' => $_ENV['REDIS_CONFIG_HOST'], - 'user' => $_ENV['REDIS_CONFIG_USER'], - 'database' => $_ENV['REDIS_CONFIG_DATABASE'], - //'password' => $_ENV['REDIS_CONFIG_PASSWORD'], - - 'port' => $_ENV['REDIS_CONFIG_PORT'], - 'status' => redis->ping() ? 'OK' : 'ERROR', + 'host' => $REDIS_CONFIG['host'], + 'user' => $REDIS_CONFIG['user'], + 'database' => $REDIS_CONFIG['database'], + 'password' => $REDIS_CONFIG['password'] ? '********' : 'NOT_SET', + 'port' => $REDIS_CONFIG['port'], + 'status' => (new \classes\redis())->ping() ? 'OK' : 'ERROR', ], 'database' => [ - 'host' => $_ENV['CONFIG_DB_HOST'], - 'database' => $_ENV['CONFIG_DB_DATABASE'], - 'user' => $_ENV['CONFIG_DB_USER'], + 'host' => $CONFIG_DB['host'], + 'database' => $CONFIG_DB['database'], + 'user' => $CONFIG_DB['user'], 'status' => $db->testConnection() ? 'OK' : 'ERROR', ], ]); diff --git a/services/php/docker-entrypoint.sh b/services/php/docker-entrypoint.sh index 34ee78e4..8c07eaf2 100644 --- a/services/php/docker-entrypoint.sh +++ b/services/php/docker-entrypoint.sh @@ -12,13 +12,20 @@ AUTO_COMPOSER_INSTALL="${AUTO_COMPOSER_INSTALL:-true}" log() { printf "[entrypoint] %s\n" "$*"; } wait_for_redis() { - host="${REDIS_CONFIG_HOST:-redis}" - port="${REDIS_CONFIG_PORT:-6379}" - pass="${REDIS_CONFIG_PASSWORD:-}" + db_target="${CONFIG_DB_TARGET:-live}" + if [ "$db_target" = "debug" ]; then + host="${REDIS_CONFIG_DEBUG_HOST:-${REDIS_CONFIG_HOST:-redis}}" + port="${REDIS_CONFIG_DEBUG_PORT:-${REDIS_CONFIG_PORT:-6379}}" + pass="${REDIS_CONFIG_DEBUG_PASSWORD:-${REDIS_CONFIG_PASSWORD:-}}" + else + host="${REDIS_CONFIG_HOST:-redis}" + port="${REDIS_CONFIG_PORT:-6379}" + pass="${REDIS_CONFIG_PASSWORD:-}" + fi timeout="${REDIS_WAIT_TIMEOUT:-60}" i=0 - log "Waiting for Redis at ${host}:${port} (timeout: ${timeout}s) ..." + log "Waiting for Redis at ${host}:${port} (target: ${db_target}, timeout: ${timeout}s) ..." while [ "$i" -lt "$timeout" ]; do if [ -n "$pass" ]; then if redis-cli -h "$host" -p "$port" -a "$pass" PING >/dev/null 2>&1; then