Merge branch 'feature/redis-requests' into develop
This commit is contained in:
commit
4a84b2db98
5
.env
5
.env
|
@ -35,3 +35,8 @@ MAILER_SENDER=example@localhost
|
|||
ASSET_BASE_URL=null
|
||||
UMAMI_URL=null
|
||||
|
||||
INFLUXDB_URL=
|
||||
INFLUXDB_TOKEN=
|
||||
INFLUXDB_BUCKET=
|
||||
INFLUXDB_ORG=
|
||||
INFLUXDB_DEBUG=1
|
||||
|
|
|
@ -1,17 +1,17 @@
|
|||
variables:
|
||||
- &volumes
|
||||
- node16_cache:/root/.npm
|
||||
- node16_cache:/root/.npm
|
||||
- /data/deblan/deblan.io-murph:/data/deblan/deblan.io-murph
|
||||
|
||||
when:
|
||||
event: [push, pull_request, tag, manual]
|
||||
branch: [master, master-*, develop, develop-*, feature/*]
|
||||
|
||||
pipeline:
|
||||
db-wait:
|
||||
image: gitnet.fr/deblan/timeout:latest
|
||||
commands:
|
||||
- /bin/timeout -t 30 -v -c 'while true; do nc -z -v db 3306 2>&1 | grep succeeded && exit 0; sleep 0.5; done'
|
||||
when:
|
||||
event: [push, pull_request, tag, manual]
|
||||
branch: [master, master-*, develop, develop-*, feature/*]
|
||||
|
||||
db-create:
|
||||
image: mariadb:10.3
|
||||
|
@ -19,9 +19,6 @@ pipeline:
|
|||
commands:
|
||||
- mysql -hdb -uroot -proot -e "CREATE DATABASE app"
|
||||
- eval "$MYSQLDUMP" | mysql -hdb -uroot -proot app
|
||||
when:
|
||||
event: [push, pull_request, tag, manual]
|
||||
branch: [master, master-*, develop, develop-*, feature/*]
|
||||
|
||||
app-config:
|
||||
image: deblan/php:8.1
|
||||
|
@ -29,18 +26,12 @@ pipeline:
|
|||
- echo APP_ENV=prod >> .env.local
|
||||
- echo APP_SECRET=$(openssl rand -hex 32) >> .env.local
|
||||
- echo DATABASE_URL=mysql://root:root@db/app >> .env.local
|
||||
when:
|
||||
event: [push, pull_request, tag, manual]
|
||||
branch: [master, master-*, develop, develop-*, feature/*]
|
||||
|
||||
php-composer:
|
||||
image: deblan/php:8.1
|
||||
commands:
|
||||
- apt-get update && apt-get -y install git
|
||||
- composer install --no-scripts
|
||||
when:
|
||||
event: [push, pull_request, tag, manual]
|
||||
branch: [master, master-*, develop, develop-*, feature/*]
|
||||
|
||||
db-migrate:
|
||||
image: deblan/php:8.1
|
||||
|
@ -48,17 +39,11 @@ pipeline:
|
|||
- PHP=php
|
||||
commands:
|
||||
- ./bin/doctrine-migrate
|
||||
when:
|
||||
event: [push, pull_request, tag, manual]
|
||||
branch: [master, master-*, develop, develop-*, feature/*]
|
||||
|
||||
app-jsroutes:
|
||||
image: deblan/php:8.1
|
||||
commands:
|
||||
- php bin/console fos:js-routing:dump --format=json --target=public/js/fos_js_routes.json
|
||||
when:
|
||||
event: [push, pull_request, tag, manual]
|
||||
branch: [master, master-*, develop, develop-*, feature/*]
|
||||
|
||||
node-build:
|
||||
image: node:16-alpine
|
||||
|
@ -74,18 +59,12 @@ pipeline:
|
|||
- yarn
|
||||
- test -f public/js/fos_js_routes.json || echo "{}" > public/js/fos_js_routes.json
|
||||
- npm run build
|
||||
when:
|
||||
event: [push, pull_request, tag, manual]
|
||||
branch: [master, master-*, develop, develop-*, feature/*]
|
||||
|
||||
security-check:
|
||||
image: gitnet.fr/deblan/osv-detector:v0.9
|
||||
commands:
|
||||
- osv-detector composer.lock yarn.lock
|
||||
failure: ignore
|
||||
when:
|
||||
event: [push, pull_request, tag, manual]
|
||||
branch: [master, master-*, develop, develop-*, feature/*]
|
||||
|
||||
cache-build:
|
||||
image: deblan/php:8.1
|
||||
|
@ -93,29 +72,6 @@ pipeline:
|
|||
commands:
|
||||
- cd /data/deblan/deblan.io-murph/
|
||||
- mv "$CI_WORKSPACE" "$CI_COMMIT_SHA"
|
||||
when:
|
||||
event: [push, pull_request, tag, manual]
|
||||
branch: [master, master-*, develop, develop-*, feature/*]
|
||||
|
||||
app-deploy:
|
||||
image: deblan/php:8.1
|
||||
secrets: [ssh_user, ssh_host, ssh_priv_key, app_directory]
|
||||
volumes: *volumes
|
||||
commands:
|
||||
- apt-get update && apt-get -y install rsync openssh-client
|
||||
- cd "/data/deblan/deblan.io-murph/$CI_COMMIT_SHA"
|
||||
- mkdir "$HOME/.ssh"
|
||||
- echo "$SSH_PRIV_KEY" > "$HOME/.ssh/id_ed25519"
|
||||
- chmod 700 "$HOME/.ssh"
|
||||
- chmod 600 "$HOME/.ssh/id_ed25519"
|
||||
- composer global require andres-montanez/magallanes
|
||||
- cp .mage.yml.dist .mage.yml
|
||||
- sed -i "s/ssh_user/$SSH_USER/g" .mage.yml
|
||||
- sed -i "s/ssh_host/$SSH_HOST/g" .mage.yml
|
||||
- sed -i "s#app_directory#$APP_DIRECTORY#g" .mage.yml
|
||||
- /root/.config/composer/vendor/bin/mage deploy "$CI_BUILD_DEPLOY_TARGET"
|
||||
when:
|
||||
event: [deployment]
|
||||
|
||||
services:
|
||||
db:
|
25
.woodpecker/deploy.yml
Normal file
25
.woodpecker/deploy.yml
Normal file
|
@ -0,0 +1,25 @@
|
|||
variables:
|
||||
- &volumes
|
||||
- /data/deblan/deblan.io-murph:/data/deblan/deblan.io-murph
|
||||
|
||||
when:
|
||||
event: [deployment]
|
||||
|
||||
pipeline:
|
||||
app-deploy:
|
||||
image: deblan/php:8.1
|
||||
secrets: [ssh_user, ssh_host, ssh_priv_key, app_directory]
|
||||
volumes: *volumes
|
||||
commands:
|
||||
- apt-get update && apt-get -y install rsync openssh-client
|
||||
- cd "/data/deblan/deblan.io-murph/$CI_COMMIT_SHA"
|
||||
- mkdir "$HOME/.ssh"
|
||||
- echo "$SSH_PRIV_KEY" > "$HOME/.ssh/id_ed25519"
|
||||
- chmod 700 "$HOME/.ssh"
|
||||
- chmod 600 "$HOME/.ssh/id_ed25519"
|
||||
- composer global require andres-montanez/magallanes
|
||||
- cp .mage.yml.dist .mage.yml
|
||||
- sed -i "s/ssh_user/$SSH_USER/g" .mage.yml
|
||||
- sed -i "s/ssh_host/$SSH_HOST/g" .mage.yml
|
||||
- sed -i "s#app_directory#$APP_DIRECTORY#g" .mage.yml
|
||||
- /root/.config/composer/vendor/bin/mage deploy "$CI_BUILD_DEPLOY_TARGET"
|
|
@ -8,6 +8,8 @@
|
|||
"beberlei/doctrineextensions": "^1.3",
|
||||
"friendsofsymfony/jsrouting-bundle": "^2.7",
|
||||
"gregwar/captcha-bundle": "^2.2",
|
||||
"guzzlehttp/guzzle": "^7.8",
|
||||
"influxdata/influxdb-client-php": "^3.4",
|
||||
"knplabs/knp-markdown-bundle": "^1.9",
|
||||
"knplabs/knp-menu-bundle": "^3.1",
|
||||
"murph/murph-core": "dev-master",
|
||||
|
@ -31,7 +33,8 @@
|
|||
"sort-packages": true,
|
||||
"allow-plugins": {
|
||||
"symfony/flex": true,
|
||||
"symfony/runtime": true
|
||||
"symfony/runtime": true,
|
||||
"php-http/discovery": true
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
|
|
|
@ -4,6 +4,11 @@
|
|||
# Put parameters here that don't need to change on each machine where the app is deployed
|
||||
# https://symfony.com/doc/current/best_practices/configuration.html#application-related-configuration
|
||||
parameters:
|
||||
influxdb_url: '%env(INFLUXDB_URL)%'
|
||||
influxdb_token: '%env(INFLUXDB_TOKEN)%'
|
||||
influxdb_bucket: '%env(INFLUXDB_BUCKET)%'
|
||||
influxdb_org: '%env(INFLUXDB_ORG)%'
|
||||
influxdb_debug: '%env(INFLUXDB_DEBUG)%'
|
||||
|
||||
services:
|
||||
# default configuration for services in *this* file
|
||||
|
@ -47,6 +52,14 @@ services:
|
|||
resource: '../src/Controller/'
|
||||
tags: ['controller.service_arguments']
|
||||
|
||||
App\Api\InfluxDB:
|
||||
arguments:
|
||||
$url: '%influxdb_url%'
|
||||
$token: '%influxdb_token%'
|
||||
$bucket: '%influxdb_bucket%'
|
||||
$org: '%influxdb_org%'
|
||||
$debug: '%influxdb_debug%'
|
||||
|
||||
site.route_loader:
|
||||
class: App\Core\Router\SiteRouteLoader
|
||||
tags: [routing.loader]
|
||||
|
@ -69,5 +82,9 @@ services:
|
|||
tags:
|
||||
- {name: markdown.parser, alias: comment}
|
||||
|
||||
App\EventListener\StatListener:
|
||||
tags:
|
||||
- { name: kernel.event_listener, event: kernel.request }
|
||||
|
||||
# add more service definitions when explicit configuration is needed
|
||||
# please note that last definitions always *replace* previous ones
|
||||
|
|
46
src/Api/InfluxDB.php
Normal file
46
src/Api/InfluxDB.php
Normal file
|
@ -0,0 +1,46 @@
|
|||
<?php
|
||||
|
||||
namespace App\Api;
|
||||
|
||||
use InfluxDB2\Client;
|
||||
use InfluxDB2\Model\WritePrecision;
|
||||
|
||||
/**
|
||||
* class InfluxDB.
|
||||
*
|
||||
* @author Simon Vieille <simon@deblan.fr>
|
||||
*/
|
||||
class InfluxDB
|
||||
{
|
||||
protected ?Client $client = null;
|
||||
|
||||
public function __construct(
|
||||
protected ?string $url,
|
||||
protected ?string $token,
|
||||
protected ?string $bucket,
|
||||
protected ?string $org,
|
||||
protected bool $debug = false
|
||||
) {
|
||||
if (isset($this->url, $this->token, $this->bucket, $this->org)) {
|
||||
$this->client = new Client([
|
||||
'url' => $this->url,
|
||||
'token' => $this->token,
|
||||
'bucket' => $this->bucket,
|
||||
'org' => $this->org,
|
||||
'debug' => $this->debug,
|
||||
'precision' => WritePrecision::S,
|
||||
'timeout' => 1,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
public function isAvailable(): bool
|
||||
{
|
||||
return $this->getClient() !== null;
|
||||
}
|
||||
|
||||
public function getClient(): ?Client
|
||||
{
|
||||
return $this->client;
|
||||
}
|
||||
}
|
41
src/EventListener/StatListener.php
Normal file
41
src/EventListener/StatListener.php
Normal file
|
@ -0,0 +1,41 @@
|
|||
<?php
|
||||
|
||||
namespace App\EventListener;
|
||||
|
||||
use App\Api\InfluxDB;
|
||||
use Symfony\Component\HttpKernel\Event\RequestEvent;
|
||||
use InfluxDB2\WriteType;
|
||||
use InfluxDB2\Point;
|
||||
|
||||
/**
|
||||
* class StatListener.
|
||||
*
|
||||
* @author Simon Vieille <simon@deblan.fr>
|
||||
*/
|
||||
class StatListener
|
||||
{
|
||||
public function __construct(protected InfluxDB $influxDB)
|
||||
{
|
||||
}
|
||||
|
||||
public function onKernelRequest(RequestEvent $event)
|
||||
{
|
||||
if (!$this->influxDB->isAvailable()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$client = $this->influxDB->getClient();
|
||||
|
||||
$writeApi = $client->createWriteApi(['writeType' => WriteType::SYNCHRONOUS]);
|
||||
$pageView = new Point('page_view');
|
||||
$pageView
|
||||
->addTag('request', 'view')
|
||||
->addField('value', 1)
|
||||
->time(time())
|
||||
;
|
||||
|
||||
$writeApi->write($pageView);
|
||||
$writeApi->close();
|
||||
$client->close();
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue