Compare commits

2 Commits

Author SHA1 Message Date
c53f7b6719 Merge branch 'develop' into release 2023-06-18 23:26:57 -04:00
98adc9f572 Fixes 2023-06-18 23:26:44 -04:00
7 changed files with 45 additions and 14 deletions

View File

@ -2,3 +2,12 @@ MYSQL_HOST=provm.cl
MYSQL_DATABASE=incoviba
MYSQL_USER=remote_incoviba
MYSQL_PASSWORD=43918b603b84dd8bb29fd29a0ea21ba751de5dc90b26f36c
MYSQL_TABLE=remote_ip
ERROR_LOGS_FILE=php://stderr
DEBUG_LOGS_FILE=php://stdout
IPIFY_URI=https://api64.ipify.org
COMMAND=/app/bin/console
WATCH_PERIOD=PT20M
CONNECTION_RETRIES=5

View File

@ -3,3 +3,8 @@ FROM php:cli
RUN docker-php-ext-install pdo_mysql
WORKDIR /app
COPY ./app /app
RUN chmod a+x /app/bin/console
#ENTRYPOINT [ "/app/bin/console" ]
CMD [ "/app/bin/console", "watch" ]

View File

@ -20,8 +20,6 @@ RUN docker-php-ext-install pdo_mysql
WORKDIR /app
COPY --from=build /code/app /app
ENTRYPOINT [ "/app/bin/console" ]
CMD [ "/app/bin/console", "watch" ]
#RUN apt-get update && apt-get install -yq --no-install-recommends cron && rm -r /var/lib/apt/lists/* && cp /app/crontab /var/spool/cron/crontabs/root
#CMD [ "cron", "-f", "-L", "15" ]

View File

@ -7,6 +7,7 @@ use Psr\Log\LoggerInterface;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\StyleInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use function Safe\shell_exec;
@ -27,24 +28,37 @@ class Watch extends Command
$io->title('Watch');
$period = new DateInterval($this->period);
$current = new DateTimeImmutable();
$current = $this->updateTime($period);
$io->info('Starting');
$io->info("Start: {$current->format('Y-m-d H:i:s')}");
while(true) {
$now = new DateTimeImmutable();
if ($now->diff($current) === $period) {
$io->info('Running Update');
$this->runUpdate();
$current = $now;
}
$wait = (new DateTimeImmutable((new DateTimeImmutable())->format('Y-m-d H:i:0')))->add(new DateInterval('PT1M'));
$io->info('Running Update');
$this->runUpdate();
$current = $this->updateTime($period);
$wait = $current->add($period);
$io->text("Waiting until {$wait->format('Y-m-d H:i:s')}");
time_sleep_until($wait->getTimestamp());
}
return Command::SUCCESS;
}
protected function runUpdate(): void
protected function updateTime(DateInterval $interval): DateTimeImmutable
{
$t0 = new DateTimeImmutable((new DateTimeImmutable())->format('Y-m-d 00:00:00'));
$tf = new DateTimeImmutable((new DateTimeImmutable())->add(new DateInterval('P1D'))->format('Y-m-d 00:00:00'));
$now = new DateTimeImmutable();
for ($t = $t0; $t < $tf; $t = $t->add($interval)) {
$t1 = $t->add($interval);
if ($t < $now and $now < $t1) {
return $t;
}
}
return $now;
}
protected function runUpdate(StyleInterface $io): void
{
$command = "{$this->command} update";
$this->logger->info("Running '{$command}'");
shell_exec($command);
$result = shell_exec($command);
$io->note($result);
}
}

View File

@ -16,7 +16,7 @@ return [
'error_logs_file' => $_ENV['ERROR_LOGS_FILE'] ?? '/logs/remote.error.log',
'debug_logs_file' => $_ENV['DEBUG_LOGS_FILE'] ?? '/logs/remote.debug.log',
'uri' => $_ENV['IPIFY_URI'] ?? 'https://api64.ipify.org',
'command' => 'php /app/public/index.php',
'command' => $_ENV['COMMAND'] ?? 'php /app/public/index.php',
'period' => $_ENV['WATCH_PERIOD'] ?? 'PT20M',
'retries' => $_ENV['CONNECTION_RETRIES'] ?? 5
];

View File

@ -7,4 +7,3 @@ services:
volumes:
- ./app:/app
- ./logs:/logs
# - ./app/crontab:/var/spool/cron/crontabs/root

6
prod.docker-compose.yml Normal file
View File

@ -0,0 +1,6 @@
services:
remote_ip:
container_name: remote_ip
build: ./Prod.Dockerfile
restart: unless-stopped
env_file: .env