68publishers/health-check-microservice

v0.1.2 2021-08-17 23:13 UTC

This package is auto-updated.

Last update: 2024-09-18 05:48:46 UTC


README

Total Downloads Latest Version on Packagist

💗 Really simple Nette application based on our package 68publishers/health-check

The application can be used as a standalone microservice or can be used directly from your main application.

Standalone usage

Firstly simply download the package:

$ git clone https://github.com/68publishers/health-check-microservice.git
$ cd health-check-microservice

Installation with included docker-compose

Install the application using the following script:

$ ./installer

Once the installation is successful you can edit the ENV variables in a file .env.

Then open a file config/health_check_service_checkers.neon and modify definitions of a service checkers according to own requirements.

Now open this URL in a browser http://localhost:8888 respectively http://localhost:8888/{HEALTH_CHECK_URL_PATH}.

Installation without Docker

Requirements:

  • Webserver (Apache/Nginx)
  • PHP 7.4
  • Composer
$ composer install
$ cp .env.dist .env
$ cp config/health_check_service_checkers.neon.dist config/health_check_service_checkers.neon

Open the file config/health_check_service_checkers.neon and modify definitions of service checkers according to your own requirements. You can pass parameters directly into the definition, of course. Usage of the ENV variable for service checkers is not necessary.

Also open the file .env where you can edit the ENV variables. Variables for services like postgres, redis etc. can be removed if not used.

Usage inside another application

Run following command in your application

$ composer require 68publishers/health-check-microservice

Create NEON file with service checker definitions like in the standalone usage and declare the ENV variables:

HEALTH_CHECK_URL_PATH=/health
HEALTH_CHECK_ARRAY_EXPORT_MODE=full
HEALTH_CHECK_TEMP_DIR={{PATH TO TEMP DIR IN THE MAIN APPLICATION}}
HEALTH_CHECK_LOG_DIR={{PATH TO LOG DIR IN THE MAIN APPLICATION}}
HEALTH_CHECK_SERVICE_CHECKERS_CONFIG={{PATH TO CONFIG FILE IN THE MAIN APPLICATION}}

Then modify index.php in the application:

<?php

declare(strict_types=1);

use App\Bootstrap as AppBootstrap;
use SixtyEightPublishers\HealthCheckMicroservice\Bootstrap as HealthCheckBootstrap;
use Nette\Application\Application;

require __DIR__ . '/../vendor/autoload.php';

$configurator =  '/health' === $_SERVER['REQUEST_URI'] ? HealthCheckBootstrap::boot() : AppBootstrap::boot();

$configurator->createContainer()
	->getByType(Application::class)
	->run();

That's all, a health check endpoint will be accessible on the address domain.com/health :)

ENV Variables

Contributing

Before committing any changes, don't forget to run

$ composer run php-cs-fixer

and

$ composer run tests