From 11cd92abca9ee2ace6c0fdf7a3ac04e1c1ededc9 Mon Sep 17 00:00:00 2001 From: MBorne Date: Tue, 3 Dec 2024 10:12:44 +0100 Subject: [PATCH] fix: docker app.ini for PHP and healthchecks --- .docker/Dockerfile | 4 ++-- docker-compose.yml | 2 +- src/Controller/Api/HealthController.php | 22 ++++++++++------------ 3 files changed, 13 insertions(+), 15 deletions(-) diff --git a/.docker/Dockerfile b/.docker/Dockerfile index 572822f..403366f 100755 --- a/.docker/Dockerfile +++ b/.docker/Dockerfile @@ -87,8 +87,8 @@ RUN ln -sfT /dev/stderr "/var/log/apache2/error.log" \ #---------------------------------------------------------------------- # Configure PHP #---------------------------------------------------------------------- -COPY .docker/php.ini /etc/php/8.3/apache2/php.ini -# TODO .docker/php.ini /etc/php/8.3/cli/php.ini +COPY .docker/php.ini /etc/php/8.3/apache2/conf.d/99-app.ini +COPY .docker/php.ini /etc/php/8.3/cli/conf.d/99-app.ini #---------------------------------------------------------------------- # Configure apache diff --git a/docker-compose.yml b/docker-compose.yml index 3e60f8e..f7fac61 100755 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -20,7 +20,7 @@ services: - DB_UPGRADE=1 - POSTGRES_USER=${POSTGRES_USER} - POSTGRES_PASSWORD=${POSTGRES_PASSWORD} - - DATABASE_URL=postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@database:5432/validator_api?serverVersion=15&charset=utf8 + - DATABASE_URL=postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@database:5432/validator_api?serverVersion=13&charset=utf8 - S3_ENDPOINT=${S3_ENDPOINT} - S3_ACCESS_KEY=${S3_ACCESS_KEY} - S3_SECRET_KEY=${S3_SECRET_KEY} diff --git a/src/Controller/Api/HealthController.php b/src/Controller/Api/HealthController.php index a8a721e..ddcb665 100644 --- a/src/Controller/Api/HealthController.php +++ b/src/Controller/Api/HealthController.php @@ -6,6 +6,7 @@ use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\Routing\Annotation\Route; use Doctrine\ORM\EntityManager; +use Doctrine\ORM\EntityManagerInterface; use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Response; use League\Flysystem\FilesystemOperator; @@ -21,15 +22,15 @@ class HealthController extends AbstractController * * @Route("/db", name="health_db") */ - public function healthDB(EntityManager $entityManager) + public function healthDB(EntityManagerInterface $entityManager) { + $sql = "SELECT postgis_version() as postgis_version"; try{ - $entityManager->getConnection()->connect(); - $check = $entityManager->getConnection()->isConnected(); - $httpCode = $check ? Response::HTTP_OK : Response::HTTP_SERVICE_UNAVAILABLE; - return new JsonResponse($check, $httpCode); + $stmt = $entityManager->getConnection()->prepare($sql); + $result = $stmt->executeQuery(); + return new JsonResponse($result->fetchOne(), Response::HTTP_OK); } catch (Exception $e){ - return new JsonResponse(False, Response::HTTP_NOT_FOUND); + return new JsonResponse($e->getMessage(), Response::HTTP_NOT_FOUND); } } @@ -41,12 +42,9 @@ public function healthDB(EntityManager $entityManager) public function healthS3(FilesystemOperator $dataStorage) { try { - $files = $dataStorage->listContents('.', TRUE); - $response = []; - foreach ($files as $file) { - $response[] = $file->path(); - } - return new JsonResponse($response, Response::HTTP_OK); + $files = $dataStorage->listContents('.', false); + $numFiles = count($files->toArray()); + return new JsonResponse('found '.$numFiles.' files', Response::HTTP_OK); } catch (Exception $e) { return new JsonResponse(False, Response::HTTP_NOT_FOUND); }