Fixes
This commit is contained in:
@ -2,3 +2,12 @@ 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,3 +3,8 @@ 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,8 +20,6 @@ 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,6 +7,7 @@ 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;
|
||||||
|
|
||||||
@ -27,24 +28,37 @@ class Watch extends Command
|
|||||||
$io->title('Watch');
|
$io->title('Watch');
|
||||||
|
|
||||||
$period = new DateInterval($this->period);
|
$period = new DateInterval($this->period);
|
||||||
$current = new DateTimeImmutable();
|
$current = $this->updateTime($period);
|
||||||
$io->info('Starting');
|
$io->info('Starting');
|
||||||
|
$io->info("Start: {$current->format('Y-m-d H:i:s')}");
|
||||||
while(true) {
|
while(true) {
|
||||||
$now = new DateTimeImmutable();
|
$io->info('Running Update');
|
||||||
if ($now->diff($current) === $period) {
|
$this->runUpdate();
|
||||||
$io->info('Running Update');
|
$current = $this->updateTime($period);
|
||||||
$this->runUpdate();
|
$wait = $current->add($period);
|
||||||
$current = $now;
|
$io->text("Waiting until {$wait->format('Y-m-d H:i:s')}");
|
||||||
}
|
|
||||||
$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 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";
|
$command = "{$this->command} update";
|
||||||
$this->logger->info("Running '{$command}'");
|
$this->logger->info("Running '{$command}'");
|
||||||
shell_exec($command);
|
$result = 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' => 'php /app/public/index.php',
|
'command' => $_ENV['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,4 +7,3 @@ services:
|
|||||||
volumes:
|
volumes:
|
||||||
- ./app:/app
|
- ./app:/app
|
||||||
- ./logs:/logs
|
- ./logs:/logs
|
||||||
# - ./app/crontab:/var/spool/cron/crontabs/root
|
|
||||||
|
6
prod.docker-compose.yml
Normal file
6
prod.docker-compose.yml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
services:
|
||||||
|
remote_ip:
|
||||||
|
container_name: remote_ip
|
||||||
|
build: ./Prod.Dockerfile
|
||||||
|
restart: unless-stopped
|
||||||
|
env_file: .env
|
Reference in New Issue
Block a user