From f75be1fcaff47fd3765a8d6c0ecbb23ad2b9e7db Mon Sep 17 00:00:00 2001 From: Jeroen De Meerleer Date: Thu, 13 Jun 2024 17:35:10 +0200 Subject: [PATCH] Added git installation and version endpoint 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. --- dockerfile | 3 +++ index.php | 8 ++++++++ templates/404.twig | 1 + 3 files changed, 12 insertions(+) diff --git a/dockerfile b/dockerfile index 4bb7165..371f68b 100644 --- a/dockerfile +++ b/dockerfile @@ -13,6 +13,9 @@ COPY --from=composer:latest /usr/bin/composer /usr/bin/composer # Activeer mod_rewrite RUN a2enmod rewrite +# Installeer git +RUN DEBIAN_FRONTEND=noninteractive apt update && apt install -y git + # Installeer de Process Control extension RUN curl -sSL https://github.com/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions -o - | sh -s pcntl zip diff --git a/index.php b/index.php index 441d62d..0d7825a 100644 --- a/index.php +++ b/index.php @@ -6,6 +6,14 @@ if($_SERVER["REQUEST_URI"] == '/metrics') { $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); diff --git a/templates/404.twig b/templates/404.twig index f0b30e9..76ee3af 100644 --- a/templates/404.twig +++ b/templates/404.twig @@ -8,5 +8,6 @@

404 Uri {{ path }} not found

/metrics

+

/version

\ No newline at end of file