mirror of
https://github.com/manualdousuario/marreta.git
synced 2025-04-07 22:29:09 +00:00
adicionada ferramenta para limpar cache
This commit is contained in:
parent
abb1966b33
commit
91176050c0
6 changed files with 114 additions and 4 deletions
|
@ -10,6 +10,7 @@ RUN apt-get update && apt-get install -y \
|
||||||
zip \
|
zip \
|
||||||
git \
|
git \
|
||||||
htop \
|
htop \
|
||||||
|
cron \
|
||||||
libzip-dev \
|
libzip-dev \
|
||||||
libsqlite3-dev \
|
libsqlite3-dev \
|
||||||
&& docker-php-ext-install zip opcache pdo_sqlite \
|
&& docker-php-ext-install zip opcache pdo_sqlite \
|
||||||
|
@ -45,7 +46,9 @@ COPY default.conf /etc/nginx/sites-available/default
|
||||||
|
|
||||||
# Copy and configure initialization script permissions
|
# Copy and configure initialization script permissions
|
||||||
COPY docker-entrypoint.sh /usr/local/bin/
|
COPY docker-entrypoint.sh /usr/local/bin/
|
||||||
RUN chmod +x /usr/local/bin/docker-entrypoint.sh
|
COPY bin/cleanup /usr/local/bin/
|
||||||
|
RUN chmod +x /usr/local/bin/docker-entrypoint.sh \
|
||||||
|
&& chmod +x /usr/local/bin/cleanup
|
||||||
|
|
||||||
# Create cache, database, and logs folders
|
# Create cache, database, and logs folders
|
||||||
RUN mkdir -p /app/cache /app/cache/database /app/logs
|
RUN mkdir -p /app/cache /app/cache/database /app/logs
|
||||||
|
|
|
@ -40,5 +40,10 @@ S3_ENDPOINT=
|
||||||
# Selenium Configuration
|
# Selenium Configuration
|
||||||
SELENIUM_HOST=localhost:4444
|
SELENIUM_HOST=localhost:4444
|
||||||
|
|
||||||
# Debug Settings
|
# Debug Settings
|
||||||
DEBUG=false
|
DEBUG=false
|
||||||
|
|
||||||
|
# Cache Cleanup Settings
|
||||||
|
# Number of days to keep cache files (*.gz)
|
||||||
|
# If not set, no files will be cleaned
|
||||||
|
CLEANUP_DAYS=7
|
||||||
|
|
|
@ -5,7 +5,8 @@
|
||||||
"php-curl-class/php-curl-class": "^11.0",
|
"php-curl-class/php-curl-class": "^11.0",
|
||||||
"php-webdriver/webdriver": "^1.15",
|
"php-webdriver/webdriver": "^1.15",
|
||||||
"monolog/monolog": "^3.8.1",
|
"monolog/monolog": "^3.8.1",
|
||||||
"nikic/fast-route": "^1.3"
|
"nikic/fast-route": "^1.3",
|
||||||
|
"league/climate": "^3.8"
|
||||||
},
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"psr-4": {
|
"psr-4": {
|
||||||
|
|
|
@ -30,6 +30,7 @@ try {
|
||||||
define('SITE_NAME', $_ENV['SITE_NAME']);
|
define('SITE_NAME', $_ENV['SITE_NAME']);
|
||||||
define('SITE_DESCRIPTION', $_ENV['SITE_DESCRIPTION']);
|
define('SITE_DESCRIPTION', $_ENV['SITE_DESCRIPTION']);
|
||||||
define('SITE_URL', $_ENV['SITE_URL']);
|
define('SITE_URL', $_ENV['SITE_URL']);
|
||||||
|
define('CLEANUP_DAYS', $_ENV['CLEANUP_DAYS'] ?? 0);
|
||||||
|
|
||||||
// Optional settings with defaults
|
// Optional settings with defaults
|
||||||
define('DNS_SERVERS', $_ENV['DNS_SERVERS'] ?? '1.1.1.1, 8.8.8.8');
|
define('DNS_SERVERS', $_ENV['DNS_SERVERS'] ?? '1.1.1.1, 8.8.8.8');
|
||||||
|
|
99
bin/cleanup
Normal file
99
bin/cleanup
Normal file
|
@ -0,0 +1,99 @@
|
||||||
|
#!/usr/bin/env php
|
||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Cache Cleanup Script
|
||||||
|
*
|
||||||
|
* Removes *.gz files from the cache directory that are older than the number
|
||||||
|
* of days specified in the define('CLEANUP_DAYS') environment variable.
|
||||||
|
* If define('CLEANUP_DAYS') is not set, no files will be cleaned.
|
||||||
|
*/
|
||||||
|
|
||||||
|
require_once __DIR__ . '/../app/vendor/autoload.php';
|
||||||
|
|
||||||
|
use League\CLImate\CLImate;
|
||||||
|
use Dotenv\Dotenv;
|
||||||
|
|
||||||
|
$climate = new CLImate();
|
||||||
|
$climate->bold()->out('Cache Cleanup Tool');
|
||||||
|
$climate->br();
|
||||||
|
|
||||||
|
$cleanupDays = 0;
|
||||||
|
|
||||||
|
// Load environment variables from .env file
|
||||||
|
try {
|
||||||
|
$dotenv = Dotenv::createImmutable(__DIR__ . '/../app');
|
||||||
|
$dotenv->load();
|
||||||
|
$climate->out('Environment variables loaded');
|
||||||
|
$cleanupDays = $_ENV['CLEANUP_DAYS'];
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
$climate->yellow()->out('Warning: ' . $e->getMessage());
|
||||||
|
// Continue execution even if .env file is not found
|
||||||
|
}
|
||||||
|
|
||||||
|
// Define cache directory constant if not already defined
|
||||||
|
if (!defined('CACHE_DIR')) {
|
||||||
|
define('CACHE_DIR', __DIR__ . '/../app/cache');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if define('CLEANUP_DAYS') is set
|
||||||
|
if ($cleanupDays == 0) {
|
||||||
|
$climate->yellow()->out('CLEANUP_DAYS variable not set or 0. No files will be cleaned.');
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Validate define('CLEANUP_DAYS') is a positive integer
|
||||||
|
$cleanupDays = (int)$cleanupDays;
|
||||||
|
if ($cleanupDays <= 0) {
|
||||||
|
$climate->red()->out('CLEANUP_DAYS must be a positive integer. No files will be cleaned.');
|
||||||
|
exit(1);
|
||||||
|
};
|
||||||
|
|
||||||
|
// Calculate the cutoff timestamp
|
||||||
|
$cutoffTime = time() - ($cleanupDays * 86400);
|
||||||
|
|
||||||
|
// Get cache directory path
|
||||||
|
$cacheDir = CACHE_DIR;
|
||||||
|
|
||||||
|
$climate->out("Cleaning cache files older than {$cleanupDays} days from: {$cacheDir}");
|
||||||
|
|
||||||
|
// Check if cache directory exists
|
||||||
|
if (!is_dir($cacheDir)) {
|
||||||
|
$climate->red()->out("Cache directory not found: {$cacheDir}");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Find all .gz files in the cache directory
|
||||||
|
$gzFiles = glob($cacheDir . '/*.gz');
|
||||||
|
$totalFiles = count($gzFiles);
|
||||||
|
$deletedFiles = 0;
|
||||||
|
|
||||||
|
if ($totalFiles === 0) {
|
||||||
|
$climate->out('No .gz files found in cache directory.');
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
$climate->out("Found {$totalFiles} .gz files in cache directory.");
|
||||||
|
|
||||||
|
$progress = $climate->progress()->total($totalFiles);
|
||||||
|
|
||||||
|
// Process each file
|
||||||
|
foreach ($gzFiles as $index => $file) {
|
||||||
|
$progress->current($index + 1);
|
||||||
|
|
||||||
|
// Get file modification time
|
||||||
|
$fileTime = filemtime($file);
|
||||||
|
|
||||||
|
// Check if file is older than cutoff time
|
||||||
|
if ($fileTime < $cutoffTime) {
|
||||||
|
// Delete the file
|
||||||
|
if (unlink($file)) {
|
||||||
|
$deletedFiles++;
|
||||||
|
} else {
|
||||||
|
$climate->red()->out("Failed to delete: " . basename($file));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$climate->br();
|
||||||
|
$climate->green()->out("Cleanup complete: {$deletedFiles} files deleted.");
|
|
@ -16,6 +16,7 @@ services:
|
||||||
- LANGUAGE=${LANGUAGE:-pt-br}
|
- LANGUAGE=${LANGUAGE:-pt-br}
|
||||||
- LOG_LEVEL=${LOG_LEVEL:-WARNING}
|
- LOG_LEVEL=${LOG_LEVEL:-WARNING}
|
||||||
- SELENIUM_HOST=${SELENIUM_HOST:-selenium-hub:4444}
|
- SELENIUM_HOST=${SELENIUM_HOST:-selenium-hub:4444}
|
||||||
|
- CLEANUP_DAYS=7 # Optional
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
# Selenium
|
# Selenium
|
||||||
selenium-hub:
|
selenium-hub:
|
||||||
|
|
Loading…
Add table
Reference in a new issue