Add host details and refactor env handling
Added hostname and version information to the worker status response. Refactored environment variable handling for better readability and modularity. Updated .dockerignore to exclude `docker-compose.yml`.
This commit is contained in:
@@ -0,0 +1 @@
|
|||||||
|
/docker-compose.yml
|
||||||
+89
-33
@@ -42,37 +42,93 @@ date_default_timezone_set('Europe/Copenhagen');
|
|||||||
/**
|
/**
|
||||||
* Check if the environment variables are set (If we are running in a Docker container)
|
* Check if the environment variables are set (If we are running in a Docker container)
|
||||||
*/
|
*/
|
||||||
if (!isset($_ENV['USE_ENV']) || $_ENV['USE_ENV'] !== 'true') {
|
if (isset($_ENV['USE_ENV']) && $_ENV['USE_ENV'] === 'true') {
|
||||||
return;
|
// Set the configuration from the environment variables
|
||||||
}
|
$ENV_VARIABLES = [
|
||||||
$ENV_VARIABLES = [
|
'CONFIG_DB_HOST' => 'host',
|
||||||
'CONFIG_DB_HOST' => 'host',
|
'CONFIG_DB_USER' => 'user',
|
||||||
'CONFIG_DB_USER' => 'user',
|
'CONFIG_DB_PASSWORD' => 'password',
|
||||||
'CONFIG_DB_PASSWORD' => 'password',
|
'CONFIG_DB_DATABASE' => 'database',
|
||||||
'CONFIG_DB_DATABASE' => 'database',
|
'DEBUG' => 'DEBUG',
|
||||||
'DEBUG' => 'DEBUG',
|
'ENCRYPTION_KEY' => 'ENCRYPTION_KEY',
|
||||||
'ENCRYPTION_KEY' => 'ENCRYPTION_KEY',
|
'CORS' => 'CORS',
|
||||||
'CORS' => 'CORS',
|
'ECONOMIC_API_APP_ACCESS_GRANT' => 'app_access_grant',
|
||||||
'ECONOMIC_API_APP_ACCESS_GRANT' => 'app_access_grant',
|
'ECONOMIC_API_APP_ACCESS_GRANT2' => 'app_access_grant2',
|
||||||
'ECONOMIC_API_APP_ACCESS_GRANT2' => 'app_access_grant2',
|
'ECONOMIC_API_APP_SECRET_TOKEN' => 'app_secret_token',
|
||||||
'ECONOMIC_API_APP_SECRET_TOKEN' => 'app_secret_token',
|
'WORDPRESS_STATIC_TOKEN' => 'WORDPRESS_STATIC_TOKEN',
|
||||||
'WORDPRESS_STATIC_TOKEN' => 'WORDPRESS_STATIC_TOKEN',
|
'EMAIL_WASH_CERTIFICATE_TOKEN' => 'EMAIL_WASH_CERTIFICATE_TOKEN',
|
||||||
'EMAIL_WASH_CERTIFICATE_TOKEN' => 'EMAIL_WASH_CERTIFICATE_TOKEN',
|
'WORDPRESS_API_URL' => 'WORDPRESS_API_URL',
|
||||||
'WORDPRESS_API_URL' => 'WORDPRESS_API_URL',
|
'MINIO_ENDPOINT' => 'endpoint',
|
||||||
'MINIO_ENDPOINT' => 'endpoint',
|
'MINIO_ACCESS_KEY' => 'access_key',
|
||||||
'MINIO_ACCESS_KEY' => 'access_key',
|
'MINIO_SECRET_KEY' => 'secret_key',
|
||||||
'MINIO_SECRET_KEY' => 'secret_key',
|
'SLACK_DEFAULT_WEBHOOK' => 'SLACK_DEFAULT_WEBHOOK',
|
||||||
'SLACK_DEFAULT_WEBHOOK' => 'SLACK_DEFAULT_WEBHOOK',
|
'REDIS_CONFIG_HOST' => 'host',
|
||||||
'REDIS_CONFIG_HOST' => 'host',
|
'REDIS_CONFIG_DATABASE' => 'database',
|
||||||
'REDIS_CONFIG_DATABASE' => 'database',
|
'REDIS_CONFIG_PASSWORD' => 'password'
|
||||||
'REDIS_CONFIG_PASSWORD' => 'password'
|
];
|
||||||
];
|
/**
|
||||||
foreach ( $ENV_VARIABLES as $env => $config ) {
|
* Set the db configuration
|
||||||
if (isset($_ENV[$env])) {
|
*/
|
||||||
if ($config === 'DEBUG' || $config === 'USE_PROD_ECONOMIC_IN_DEBUG') {
|
$CONFIG_DB = [
|
||||||
$GLOBALS[$config] = $_ENV[$env] === 'true';
|
'host' => $_ENV['CONFIG_DB_HOST'],
|
||||||
} else {
|
'user' => $_ENV['CONFIG_DB_USER'],
|
||||||
$GLOBALS[$config] = $_ENV[$env];
|
'password' => $_ENV['CONFIG_DB_PASSWORD'],
|
||||||
}
|
'database' => $_ENV['CONFIG_DB_DATABASE']
|
||||||
}
|
];
|
||||||
|
/**
|
||||||
|
* Set the debug configuration
|
||||||
|
*/
|
||||||
|
$DEBUG = $_ENV['DEBUG'];
|
||||||
|
/**
|
||||||
|
* Set the encryption key
|
||||||
|
*/
|
||||||
|
$ENCRYPTION_KEY = $_ENV['ENCRYPTION_KEY'];
|
||||||
|
/**
|
||||||
|
* Set the CORS configuration
|
||||||
|
*/
|
||||||
|
$CORS = $_ENV['CORS'];
|
||||||
|
/**
|
||||||
|
* Set the economic API configuration
|
||||||
|
*/
|
||||||
|
$ECONOMIC_API = [
|
||||||
|
'app_access_grant' => $_ENV['ECONOMIC_API_APP_ACCESS_GRANT'],
|
||||||
|
'app_access_grant2' => $_ENV['ECONOMIC_API_APP_ACCESS_GRANT2'],
|
||||||
|
'app_secret_token' => $_ENV['ECONOMIC_API_APP_SECRET_TOKEN']
|
||||||
|
];
|
||||||
|
/**
|
||||||
|
* Set the WordPress static token
|
||||||
|
*/
|
||||||
|
$WORDPRESS_STATIC_TOKEN = $_ENV['WORDPRESS_STATIC_TOKEN'];
|
||||||
|
/**
|
||||||
|
* Set the email wash certificate token
|
||||||
|
*/
|
||||||
|
$EMAIL_WASH_CERTIFICATE_TOKEN = $_ENV['EMAIL_WASH_CERTIFICATE_TOKEN'];
|
||||||
|
/**
|
||||||
|
* Set the WordPress API URL
|
||||||
|
*/
|
||||||
|
$WORDPRESS_API_URL = $_ENV['WORDPRESS_API_URL'];
|
||||||
|
/**
|
||||||
|
* Set the Minio configuration
|
||||||
|
*/
|
||||||
|
$MINIO = [
|
||||||
|
'endpoint' => $_ENV['MINIO_ENDPOINT'],
|
||||||
|
'access_key' => $_ENV['MINIO_ACCESS_KEY'],
|
||||||
|
'secret_key' => $_ENV['MINIO_SECRET_KEY']
|
||||||
|
];
|
||||||
|
/**
|
||||||
|
* Set the Slack default webhook
|
||||||
|
*/
|
||||||
|
$SLACK_DEFAULT_WEBHOOK = $_ENV['SLACK_DEFAULT_WEBHOOK'];
|
||||||
|
/**
|
||||||
|
* Set the Redis configuration
|
||||||
|
*/
|
||||||
|
$REDIS_CONFIG = [
|
||||||
|
'host' => $_ENV['REDIS_CONFIG_HOST'],
|
||||||
|
'database' => $_ENV['REDIS_CONFIG_DATABASE'],
|
||||||
|
'password' => $_ENV['REDIS_CONFIG_PASSWORD']
|
||||||
|
];
|
||||||
|
|
||||||
|
// Set the timezone
|
||||||
|
date_default_timezone_set($_ENV['CONFIG_TIMEZONE']) ?? 'Europe/Copenhagen';
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -12,7 +12,7 @@ class workerRoute
|
|||||||
{
|
{
|
||||||
$this->get('/worker/status', function () {
|
$this->get('/worker/status', function () {
|
||||||
global $response;
|
global $response;
|
||||||
$response->success(['message' => 'Worker is running', 'status' => 'OK', 'time' => date('Y-m-d H:i:s'), 'timezone' => date_default_timezone_get()]);
|
$response->success(['message' => 'Worker is running', 'status' => 'OK', 'time' => date('Y-m-d H:i:s'), 'timezone' => date_default_timezone_get(), 'host' => gethostname(), 'version' => '1.0.1']);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user