Jeroen De Meerleer
f75be1fcaf
In the Dockerfile, a new command has been added to install git. This allows for more flexibility in managing code versions within the container. In addition, a new endpoint '/version' has been introduced in index.php which returns JSON data about the last commit, its timestamp and the current branch. This provides an easy way to check versioning information directly from the application.
25 lines
977 B
PHP
25 lines
977 B
PHP
<?php
|
|
|
|
if($_SERVER["REQUEST_URI"] == '/metrics') {
|
|
header('Content-Type: text/plain; version=0.0.4');
|
|
$config = getenv('CONFIG_FILE');
|
|
$phpbin = getenv('PHP_BINARY');
|
|
$output = shell_exec('CONFIG_FILE="' . $config . '" ' . $phpbin . ' ' . $_SERVER['DOCUMENT_ROOT'] . 'script.php');
|
|
echo $output;
|
|
} elseif ($_SERVER["REQUEST_URI"] == '/version') {
|
|
header('Content-Type: application/json');
|
|
$git = [
|
|
'lastCommit' => trim(shell_exec('git rev-parse HEAD')),
|
|
'lastCommitTimestamp' => trim(shell_exec('git log -1 --format=%cd')),
|
|
'branch' => trim(shell_exec('git rev-parse --abbrev-ref HEAD')),
|
|
];
|
|
echo json_encode($git);
|
|
} else {
|
|
require_once('vendor/autoload.php');
|
|
http_response_code(404);
|
|
$loader = new \Twig\Loader\FilesystemLoader('templates');
|
|
$twig = new \Twig\Environment($loader, [
|
|
'cache' => 'twig_cache',
|
|
]);
|
|
echo $twig->render('404.twig', ['path' => $_SERVER["REQUEST_URI"]]);
|
|
} |