Compare commits
3 Commits
Author | SHA1 | Date | |
---|---|---|---|
390c15a45c | |||
4472a26412 | |||
53d19cb53e |
@ -2,12 +2,3 @@ MYSQL_HOST=provm.cl
|
|||||||
MYSQL_DATABASE=incoviba
|
MYSQL_DATABASE=incoviba
|
||||||
MYSQL_USER=remote_incoviba
|
MYSQL_USER=remote_incoviba
|
||||||
MYSQL_PASSWORD=43918b603b84dd8bb29fd29a0ea21ba751de5dc90b26f36c
|
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
|
|
||||||
|
@ -3,8 +3,3 @@ FROM php:cli
|
|||||||
RUN docker-php-ext-install pdo_mysql
|
RUN docker-php-ext-install pdo_mysql
|
||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
COPY ./app /app
|
|
||||||
RUN chmod a+x /app/bin/console
|
|
||||||
|
|
||||||
#ENTRYPOINT [ "/app/bin/console" ]
|
|
||||||
CMD [ "/app/bin/console", "watch" ]
|
|
||||||
|
@ -20,6 +20,8 @@ RUN docker-php-ext-install pdo_mysql
|
|||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
COPY --from=build /code/app /app
|
COPY --from=build /code/app /app
|
||||||
|
|
||||||
|
ENTRYPOINT [ "/app/bin/console" ]
|
||||||
|
|
||||||
CMD [ "/app/bin/console", "watch" ]
|
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
|
#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" ]
|
#CMD [ "cron", "-f", "-L", "15" ]
|
||||||
|
@ -7,7 +7,6 @@ use Psr\Log\LoggerInterface;
|
|||||||
use Symfony\Component\Console\Command\Command;
|
use Symfony\Component\Console\Command\Command;
|
||||||
use Symfony\Component\Console\Input\InputInterface;
|
use Symfony\Component\Console\Input\InputInterface;
|
||||||
use Symfony\Component\Console\Output\OutputInterface;
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
use Symfony\Component\Console\Style\StyleInterface;
|
|
||||||
use Symfony\Component\Console\Style\SymfonyStyle;
|
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||||
use function Safe\shell_exec;
|
use function Safe\shell_exec;
|
||||||
|
|
||||||
@ -28,37 +27,24 @@ class Watch extends Command
|
|||||||
$io->title('Watch');
|
$io->title('Watch');
|
||||||
|
|
||||||
$period = new DateInterval($this->period);
|
$period = new DateInterval($this->period);
|
||||||
$current = $this->updateTime($period);
|
$current = new DateTimeImmutable();
|
||||||
$io->info('Starting');
|
$io->info('Starting');
|
||||||
$io->info("Start: {$current->format('Y-m-d H:i:s')}");
|
|
||||||
while(true) {
|
while(true) {
|
||||||
$io->info('Running Update');
|
$now = new DateTimeImmutable();
|
||||||
$this->runUpdate($io);
|
if ($now->diff($current) === $period) {
|
||||||
$current = $this->updateTime($period);
|
$io->info('Running Update');
|
||||||
$wait = $current->add($period);
|
$this->runUpdate();
|
||||||
$io->text("Waiting until {$wait->format('Y-m-d H:i:s')}");
|
$current = $now;
|
||||||
|
}
|
||||||
|
$wait = (new DateTimeImmutable((new DateTimeImmutable())->format('Y-m-d H:i:0')))->add(new DateInterval('PT1M'));
|
||||||
time_sleep_until($wait->getTimestamp());
|
time_sleep_until($wait->getTimestamp());
|
||||||
}
|
}
|
||||||
return Command::SUCCESS;
|
return Command::SUCCESS;
|
||||||
}
|
}
|
||||||
protected function updateTime(DateInterval $interval): DateTimeImmutable
|
protected function runUpdate(): void
|
||||||
{
|
|
||||||
$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";
|
$command = "{$this->command} update";
|
||||||
$this->logger->info("Running '{$command}'");
|
$this->logger->info("Running '{$command}'");
|
||||||
$result = shell_exec($command);
|
shell_exec($command);
|
||||||
$io->note($result);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,7 @@ return [
|
|||||||
'error_logs_file' => $_ENV['ERROR_LOGS_FILE'] ?? '/logs/remote.error.log',
|
'error_logs_file' => $_ENV['ERROR_LOGS_FILE'] ?? '/logs/remote.error.log',
|
||||||
'debug_logs_file' => $_ENV['DEBUG_LOGS_FILE'] ?? '/logs/remote.debug.log',
|
'debug_logs_file' => $_ENV['DEBUG_LOGS_FILE'] ?? '/logs/remote.debug.log',
|
||||||
'uri' => $_ENV['IPIFY_URI'] ?? 'https://api64.ipify.org',
|
'uri' => $_ENV['IPIFY_URI'] ?? 'https://api64.ipify.org',
|
||||||
'command' => $_ENV['COMMAND'] ?? 'php /app/public/index.php',
|
'command' => 'php /app/public/index.php',
|
||||||
'period' => $_ENV['WATCH_PERIOD'] ?? 'PT20M',
|
'period' => $_ENV['WATCH_PERIOD'] ?? 'PT20M',
|
||||||
'retries' => $_ENV['CONNECTION_RETRIES'] ?? 5
|
'retries' => $_ENV['CONNECTION_RETRIES'] ?? 5
|
||||||
];
|
];
|
||||||
|
@ -7,3 +7,4 @@ services:
|
|||||||
volumes:
|
volumes:
|
||||||
- ./app:/app
|
- ./app:/app
|
||||||
- ./logs:/logs
|
- ./logs:/logs
|
||||||
|
# - ./app/crontab:/var/spool/cron/crontabs/root
|
||||||
|
@ -1,6 +0,0 @@
|
|||||||
services:
|
|
||||||
remote_ip:
|
|
||||||
container_name: remote_ip
|
|
||||||
build: ./Prod.Dockerfile
|
|
||||||
restart: unless-stopped
|
|
||||||
env_file: .env
|
|
Reference in New Issue
Block a user