From 746ab7921bec74686836fc7b4b07513580075825 Mon Sep 17 00:00:00 2001 From: Arnaud RITTI Date: Fri, 15 Apr 2022 22:09:16 +0200 Subject: [PATCH] Fix deploy --- .env | 3 +++ Dockerfile | 2 ++ config/packages/webpack_encore.yaml | 2 +- config/services.yaml | 10 +++++++--- deploy.php | 4 ++-- package.json | 2 +- src/Manager/BinManager.php | 12 ++++++------ 7 files changed, 22 insertions(+), 13 deletions(-) diff --git a/.env b/.env index 2d9fa1f..e4b9935 100644 --- a/.env +++ b/.env @@ -47,3 +47,6 @@ CORS_ALLOW_ORIGIN='^https?://(localhost|127\.0\.0\.1)(:[0-9]+)?$' TRUSTED_PROXIES=127.0.0.1,REMOTE_ADDR BUCKET_MODE="path" +BUCKET_REQUEST_LIMIT=50 +# Duration in hours +BUCKET_EXPIRE_AFTER=48 diff --git a/Dockerfile b/Dockerfile index 4eb6ad9..7c41aa2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -27,6 +27,8 @@ RUN rm -rf node_modules ENV APP_ENV "prod" ENV BUCKET_MODE "path" +ENV BUCKET_REQUEST_LIMIT 50 +ENV BUCKET_EXPIRE_AFTER 48 ENV CORS_ALLOW_ORIGIN "^https?://(localhost|127\.0\.0\.1)(:[0-9]+)?$" ENV TRUSTED_PROXIES "127.0.0.1,REMOTE_ADDR" diff --git a/config/packages/webpack_encore.yaml b/config/packages/webpack_encore.yaml index b30abc1..f8ac7f8 100644 --- a/config/packages/webpack_encore.yaml +++ b/config/packages/webpack_encore.yaml @@ -18,7 +18,7 @@ webpack_encore: crossorigin: 'anonymous' # Preload all rendered script and link tags automatically via the HTTP/2 Link header - preload: true + preload: false # Throw an exception if the entrypoints.json file is missing or an entry is missing from the data # strict_mode: false diff --git a/config/services.yaml b/config/services.yaml index e48920e..68bae77 100644 --- a/config/services.yaml +++ b/config/services.yaml @@ -5,8 +5,12 @@ # https://symfony.com/doc/current/best_practices.html#use-parameters-for-application-configuration parameters: buckets_dirs: '%kernel.project_dir%/var/bins' - bucket_mode: '%env(default:default_bucket_mode:BUCKET_MODE)%' - default_bucket_mode: 'path' + buckets_request_limit: '%env(default:default_buckets_request_limit:BUCKET_REQUEST_LIMIT)%' + default_buckets_request_limit: 50 + buckets_expire_after: '%env(default:default_buckets_expire_after:BUCKET_EXPIRE_AFTER)%' + default_buckets_expire_after: 48 + buckets_mode: '%env(default:default_buckets_mode:BUCKET_MODE)%' + default_buckets_mode: 'path' services: # default configuration for services in *this* file @@ -49,7 +53,7 @@ services: App\EventListener\CurrentBinEventSubscriber: arguments: - '@bin_manager' - - '%bucket_mode%' + - '%buckets_mode%' tags: - { name: kernel.event_subscriber } diff --git a/deploy.php b/deploy.php index fa228c8..2cd98be 100644 --- a/deploy.php +++ b/deploy.php @@ -44,11 +44,11 @@ task('npm:build', static function (): void { runLocally('npm run build'); upload('public/build/', '{{release_path}}/public/build/'); + run('cd {{release_or_current_path}} && {{bin/console}} cache:clear {{console_options}}'); }); task('database:fixture', static function (): void { - runLocally('npm run build'); - run('cd {{release_or_current_path}} && {{bin/console}} doctrine:fixtures:load --purge-with-truncate {{console_options}}'); + run('cd {{release_or_current_path}} && {{bin/console}} doctrine:fixtures:load {{console_options}}'); }); before('deploy:symlink', 'npm:build'); diff --git a/package.json b/package.json index 37e4ffe..5cb4be9 100644 --- a/package.json +++ b/package.json @@ -28,7 +28,7 @@ "release": "release-it" }, "lint-staged": { - "*.php": [ + "{src,tests}/**/*.php": [ "vendor/bin/php-cs-fixer fix --diff --config .php-cs-fixer.dist.php --no-ansi", "vendor/bin/phpstan analyse --no-ansi --no-progress" ], diff --git a/src/Manager/BinManager.php b/src/Manager/BinManager.php index 7b97a7e..dbd354a 100644 --- a/src/Manager/BinManager.php +++ b/src/Manager/BinManager.php @@ -20,8 +20,6 @@ class BinManager { - public const LIMIT = 50; - public const EXPIRATION = 48; private ?Bin $currentBin = null; private BinConnectionWrapper $binConnectionWrapper; @@ -49,7 +47,7 @@ public function getBinUrls(): array $host = $request->getHttpHost(); $subdomain = sprintf('%s://%s.%s', $scheme, (string) $this->getCurrentBin(), $host); $path = sprintf('%s://%s/b/%s', $scheme, $host, (string) $this->getCurrentBin()); - $bucketMode = $this->parameterBag->get('bucket_mode'); + $bucketMode = $this->parameterBag->get('buckets_mode'); if (filter_var($request->getHost(), FILTER_VALIDATE_IP) && 'both' === $bucketMode) { $bucketMode = 'path'; @@ -64,7 +62,7 @@ public function getBinUrls(): array public function getMax(): int { - return self::LIMIT; + return (int) $this->parameterBag->get('buckets_request_limit'); } public function getCurrentBin(): ?Bin @@ -125,11 +123,13 @@ public function getRequests(): ArrayCollection public function isExpired(): bool { $qb = $this->binConnectionWrapper->createQueryBuilder(); + $expiration = (int) $this->parameterBag->get('buckets_expire_after'); + $hasExpiredRequest = (bool) $qb->select('id') ->from('requests') ->orderBy('date', 'ASC') ->where('date <= :date') - ->setParameter('date', new DateTime(sprintf('-%s hour', self::EXPIRATION)), Types::DATETIME_MUTABLE) + ->setParameter('date', new DateTime(sprintf('-%s hour', $expiration)), Types::DATETIME_MUTABLE) ->setMaxResults(1) ->fetchOne(); @@ -137,7 +137,7 @@ public function isExpired(): bool $binFile = sprintf('%s/%s.db', $this->parameterBag->get('buckets_dirs'), $this->currentBin->getId()); if (file_exists($binFile.'.lock')) { $fileStat = stat($binFile.'.lock'); - $hasExpiredLock = (new DateTime('@'.$fileStat['mtime'])) <= (new DateTime(sprintf('-%s hour', self::EXPIRATION))); + $hasExpiredLock = (new DateTime('@'.$fileStat['mtime'])) <= (new DateTime(sprintf('-%s hour', $expiration))); } return $hasExpiredRequest || $hasExpiredLock;