Skip to content

Commit

Permalink
Merge 9c7fd48 into 64b5ac0
Browse files Browse the repository at this point in the history
  • Loading branch information
shrikeh committed May 30, 2022
2 parents 64b5ac0 + 9c7fd48 commit 7fc596c
Show file tree
Hide file tree
Showing 133 changed files with 2,715 additions and 119 deletions.
13 changes: 9 additions & 4 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# https://symfony.com/doc/current/best_practices.html#use-environment-variables-for-infrastructure-configuration

###> symfony/framework-bundle ###
APP_ENV=test
APP_ENV=prod
APP_DEBUG=true
APP_SECRET=e4fab8533e85795651f9963db77469ea

Expand All @@ -26,8 +26,13 @@ APP_SECRET=e4fab8533e85795651f9963db77469ea
# MESSENGER_TRANSPORT_DSN=amqp://guest:guest@localhost:5672/%2f/messages
# MESSENGER_TRANSPORT_DSN=redis://localhost:6379/messages
###< symfony/messenger ###
APP_ENV=test
APP_CODE_DIR='/cushon/app'
APP_BUILD_DIR=$(PWD)/build
APP_CACHE_DIR=${APP_BUILD_DIR}/cache/symfony
APP_LOG_DIR=$(PWD)/build/logs
APP_BUILD_DIR=build
APP_CACHE_DIR=build/cache/symfony
APP_LOG_DIR=build/logs
HOST_NGINX_PORT=9010
NULL_DEPENDENCY_NAME='A fake dependency'

DB_READ_PASSWORD=cushon_health_reader
DB_WRITE_PASSWORD=cushon_health_writer
1 change: 1 addition & 0 deletions .env.test
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ APP_SECRET='$ecretf0rt3st'
SYMFONY_DEPRECATIONS_HELPER=999999
PANTHER_APP_ENV=panther
PANTHER_ERROR_SCREENSHOT_DIR=./var/error-screenshots
APP_ENV=test
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ app export-ignore
docker export-ignore
features export-ignore
tests export-ignore
.github export-ignore
.editorconfig export-ignore
.env export-ignore
.env.test export-ignore
Expand Down
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ craft: .craft test quality

console: .composer-console

health: APP_ENV = prod
health: .composer-health

brew:
Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ Additionally, files to run testing and quality tooling (e.g. `infection.json`, `
## Testing & Quality
The bundle is tested with both unit testing and behavioural testing with [phpUnit][phpunit] and [behat][behat] respectively.

***
[![GitHub issues](https://img.shields.io/github/issues/Smarterly/symfony-health-bundle.svg)](https://github.com/Smarterly/symfony-health-bundle/issues)
[![Coverage Status](https://coveralls.io/repos/github/Smarterly/symfony-health-bundle/badge.svg?branch=main)](https://coveralls.io/github/Smarterly/symfony-health-bundle?branch=main)
[![Technical Debt](https://sonarcloud.io/api/project_badges/measure?project=Smarterly_symfony-health-bundle&metric=sqale_index)](https://sonarcloud.io/summary/new_code?id=Smarterly_symfony-health-bundle)
Expand Down
17 changes: 5 additions & 12 deletions app/config/bundles.php
Original file line number Diff line number Diff line change
@@ -1,16 +1,9 @@
<?php

declare(strict_types=1);

use Cushon\HealthBundle\CushonHealthBundle;
use Symfony\Bundle\FrameworkBundle\FrameworkBundle;
use FriendsOfBehat\SymfonyExtension\Bundle\FriendsOfBehatSymfonyExtensionBundle;

return [
FrameworkBundle::class => ['all' => true],
FriendsOfBehatSymfonyExtensionBundle::class => [
'test' => true,
'dev' => true,
],
CushonHealthBundle::class => ['all' => true],
Symfony\Bundle\FrameworkBundle\FrameworkBundle::class => ['all' => true],
FriendsOfBehat\SymfonyExtension\Bundle\FriendsOfBehatSymfonyExtensionBundle::class => ['test' => true, 'dev' => true],
Cushon\HealthBundle\CushonHealthBundle::class => ['all' => true],
Doctrine\Bundle\DoctrineBundle\DoctrineBundle::class => ['all' => true],
Doctrine\Bundle\MigrationsBundle\DoctrineMigrationsBundle::class => ['all' => true],
];
41 changes: 41 additions & 0 deletions app/config/packages/doctrine.prod.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
---
parameters:
env(DB_READ_HOST): '127.0.0.1'
env(DB_READ_NAME): 'cushon_health_test'
env(DB_READ_USER): 'cushon_read'
env(DB_READ_VERSION): 'mariadb-10.7.3'
env(DB_READ_PORT): 33010

env(DB_WRITE_HOST): '127.0.0.1'
env(DB_WRITE_NAME): 'cushon_health_test'
env(DB_WRITE_USER): 'cushon_write'
env(DB_WRITE_VERSION): 'mariadb-10.7.3'
env(DB_WRITE_PORT): 33010

doctrine:
dbal:
default_connection: 'read'
connections:
read:
# Connection used for read operations
host: '%env(string:DB_READ_HOST)%'
dbname: '%env(string:DB_READ_NAME)%'
user: '%env(string:DB_READ_USER)%'
password: '%env(string:DB_READ_PASSWORD)%'
server_version: '%env(string:DB_READ_VERSION)%'
port: '%env(int:DB_READ_PORT)%'
driver: 'pdo_mysql'
options:
LoginTimeout: 2
write:
# Connection used for write operations
host: '%env(string:DB_WRITE_HOST)%'
dbname: '%env(string:DB_WRITE_NAME)%'
user: '%env(string:DB_WRITE_USER)%'
password: '%env(string:DB_WRITE_PASSWORD)%'
server_version: '%env(string:DB_WRITE_VERSION)%'
port: '%env(int:DB_WRITE_PORT)%'
driver: 'pdo_mysql'
options:
LoginTimeout: 2

8 changes: 8 additions & 0 deletions app/config/packages/doctrine_migrations.prod.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
doctrine_migrations:
connection: 'write'
migrations_paths:
# namespace is arbitrary but should be different from App\Migrations
# as migrations classes should NOT be autoloaded
'App\DoctrineMigrations': '%kernel.project_dir%/migrations'
enable_profiler: '%kernel.debug%'
43 changes: 25 additions & 18 deletions app/config/packages/framework.yaml
Original file line number Diff line number Diff line change
@@ -1,24 +1,31 @@
# see https://symfony.com/doc/current/reference/configuration/framework.html
framework:
secret: '%env(APP_SECRET)%'
#csrf_protection: true
http_method_override: false
secret: '%env(APP_SECRET)%'
#csrf_protection: true
http_method_override: false

# Enables session support. Note that the session will ONLY be started if you read or write from it.
# Remove or comment this section to explicitly disable session support.
session:
handler_id: null
cookie_secure: auto
cookie_samesite: lax
storage_factory_id: session.storage.factory.native
# Enables session support. Note that the session will ONLY be started if you read or write from it.
# Remove or comment this section to explicitly disable session support.
session:
handler_id: null
cookie_secure: auto
cookie_samesite: lax
storage_factory_id: session.storage.factory.native

#esi: true
#fragments: true
php_errors:
log: true
#esi: true
#fragments: true
php_errors:
log: true
when@prod: &prod
framework:
http_client:
# https://www.random.org/integers/?num=10&min=1&max=6&col=1&base=10&format=plain&rnd=new
scoped_clients:
random.client:
base_uri: 'https://www.random.org'

when@test:
framework:
test: true
session:
storage_factory_id: session.storage.factory.mock_file
framework:
test: true
session:
storage_factory_id: session.storage.factory.mock_file
13 changes: 13 additions & 0 deletions app/config/packages/translation.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
framework:
default_locale: en
translator:
default_path: '%kernel.project_dir%/translations'
fallbacks:
- en
# providers:
# crowdin:
# dsn: '%env(CROWDIN_DSN)%'
# loco:
# dsn: '%env(LOCO_DSN)%'
# lokalise:
# dsn: '%env(LOKALISE_DSN)%'
17 changes: 14 additions & 3 deletions app/config/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,35 @@
# Put parameters here that don't need to change on each machine where the bundle is deployed
# https://symfony.com/doc/current/best_practices.html#use-parameters-for-application-configuration
parameters:
env(NULL_DEPENDENCY_NAME): 'Some dependency'
app.app_health.null_dependency.name: '%env(string:NULL_DEPENDENCY_NAME)%'
app.app_health.null_dependency.health: true

services:
# default configuration for services in *this* file
_defaults:
autowire: true # Automatically injects dependencies in your services.
autoconfigure: true # Automatically registers your services as commands, event subscribers, etc.

# makes classes in src/ available to be used as services
# this creates a service per class whose id is the fully-qualified class name
App\:
resource: '%kernel.project_dir%/src/'
exclude:
- '%kernel.project_dir%/src/{DependencyInjection/,Kernel.php}'

_instanceof:
App\ApplicationHealth\DependencyCheck\DatabaseCheck\DatabaseUserCheck:
tags:
- 'app.health.check.db'

App\ApplicationHealth\DependencyCheck\DatabaseCheck:
arguments:
- !tagged_iterator app.health.check.db

# add more service definitions when explicit configuration is needed
# please note that last definitions always *replace* previous ones
App\ApplicationHealth\DependencyCheck\NullDependencyCheck:
arguments:
$name: 'Null dependency'
$health: true
$name: '%app.app_health.null_dependency.name%'
$health: '%app.app_health.null_dependency.health%'
$info: 'Some info about the fake dependency'
5 changes: 3 additions & 2 deletions app/config/services_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ services:
autowire: true
autoconfigure: true

# Disable the example Null Dependency Check in test
App\ApplicationHealth\DependencyCheck\NullDepdencyCheck:
# Disable the example Dependency Checks in test
App\ApplicationHealth\DependencyCheck\:
resource: '%kernel.project_dir%/src/ApplicationHealth/DependencyCheck/'
autowire: false
autoconfigure: false

Expand Down
38 changes: 38 additions & 0 deletions app/data/health.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
-- MariaDB dump 10.19 Distrib 10.7.3-MariaDB, for debian-linux-gnu (x86_64)
--
-- Host: localhost Database: uuid_example
-- ------------------------------------------------------
-- Server version 10.7.3-MariaDB-1:10.7.3+maria~focal

/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8mb4 */;
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
/*!40103 SET TIME_ZONE='+00:00' */;
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;

CREATE SCHEMA IF NOT EXISTS cushon_health_test;

CREATE USER 'cushon_read'@'%';
CREATE USER 'cushon_write'@'%';

GRANT ALL PRIVILEGES ON `cushon_health_test`.* TO 'cushon_write'@'%' IDENTIFIED BY 'cushon_health_writer';
GRANT SELECT ON `cushon_health_test`.* TO 'cushon_read'@'%' IDENTIFIED BY 'cushon_health_reader';

FLUSH PRIVILEGES;

/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;

/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;

-- Dump completed on 2022-03-23 15:47:25
Empty file added app/migrations/.gitignore
Empty file.
36 changes: 36 additions & 0 deletions app/migrations/Version20220530155854.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

declare(strict_types=1);

namespace App\DoctrineMigrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\DBAL\Types\Types;
use Doctrine\Migrations\AbstractMigration;
use Ramsey\Uuid\Doctrine\UuidBinaryType;

/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20220530155854 extends AbstractMigration
{
public function getDescription(): string
{
return 'Create a simple table for health checks';
}

public function up(Schema $schema): void
{
$health = $schema->createTable('health');
$health->addColumn(
'last_checked',
Types::DATETIME_IMMUTABLE
);

}

public function down(Schema $schema): void
{
$schema->dropTable('health');
}
}
53 changes: 53 additions & 0 deletions app/src/ApplicationHealth/DependencyCheck/DatabaseCheck.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

declare(strict_types=1);

namespace App\ApplicationHealth\DependencyCheck;

use App\ApplicationHealth\DependencyCheck\DatabaseCheck\DatabaseUserCheck;
use App\ApplicationHealth\DependencyCheck\DatabaseCheck\Exception\NoDatabaseChecksProvided;
use Cushon\HealthBundle\ApplicationHealth\DependencyCheck;
use Ds\Set;
use Generator;

final class DatabaseCheck implements DependencyCheck
{
/**
* @var Set<DatabaseUserCheck>
*/
private Set $dependencyRepositories;

/**
* @param iterable<DatabaseUserCheck> $dependencyRepositories
*/
public function __construct(iterable $dependencyRepositories)
{
$this->dependencyRepositories = new Set();
foreach ($dependencyRepositories as $dependencyRepository) {
$this->addDatabaseUserCheck($dependencyRepository);
}

if (!$this->dependencyRepositories->count()) {
throw NoDatabaseChecksProvided::create();
}
}

/**
* @inheritDoc
*/
public function check(): Generator
{
foreach ($this->dependencyRepositories as $dependencyRepository) {
yield $dependencyRepository->checkUser();
}
}

/**
* @param DatabaseUserCheck $databaseUserChecks
* @return void
*/
private function addDatabaseUserCheck(DatabaseUserCheck $databaseUserChecks): void
{
$this->dependencyRepositories->add($databaseUserChecks);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

declare(strict_types=1);

namespace App\ApplicationHealth\DependencyCheck\DatabaseCheck;

use Cushon\HealthBundle\ApplicationHealth\HealthReport\DependencyStatus;

interface DatabaseUserCheck
{
/**
* @return DependencyStatus
*/
public function checkUser(): DependencyStatus;
}

0 comments on commit 7fc596c

Please sign in to comment.