Skip to content

Instantly share code, notes, and snippets.

@makasim
Last active March 20, 2020 11:23
Show Gist options
  • Save makasim/a1030ce6ed0de93e2cfbbb5bde66a6ff to your computer and use it in GitHub Desktop.
Save makasim/a1030ce6ed0de93e2cfbbb5bde66a6ff to your computer and use it in GitHub Desktop.
Auto update telegram webhook url on docker compose up
version: '3.4'
services:
app:
image: 'formapro/nginx-php-fpm:latest-all-exts'
working_dir: '/app'
volumes:
- './:/app:cached'
env_file: '.env'
networks:
- default
- bot_ngrok
ports:
- '80:80'
environment:
- NGINX_WEB_ROOT=/app/public
- NGINX_PHP_FALLBACK=/index.php
- NGINX_PHP_LOCATION=^/index\.php(/|$$)
ngrok:
image: wernight/ngrok
entrypoint: ngrok http app:80
ports:
- 4040:4040
networks:
- bot_ngrok
networks:
bot_ngrok: ~
#!/usr/bin/env bash
sleep 3 && php bin/setup-telegram-hook.php &
docker-compose up
<?php
namespace Acme;
use Symfony\Component\Process\Process;
include __DIR__.'/../vendor/autoload.php';
$process = new Process('curl $(docker port eukvartal_ngrok_1 4040)/api/tunnels');
$process->mustRun();
$output = $process->getOutput();
if (false == $data = json_decode($output, true)) {
throw new \LogicException('Cannot parse json');
}
$httpsPublicUrl = null;
foreach ($data['tunnels'] as $tunnel) {
if ('https' === $tunnel['proto']) {
$httpsPublicUrl = $tunnel['public_url'];
break;
}
}
if (false == $httpsPublicUrl) {
throw new \LogicException('The HTTPS public url has not been found');
}
$process = new Process('docker-compose exec -T app bin/console app:bot:set-webhook '.$httpsPublicUrl);
$process->mustRun();
echo $process->getOutput().PHP_EOL;
echo PHP_EOL.PHP_EOL.$httpsPublicUrl.PHP_EOL;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment