Last active
November 27, 2023 16:52
-
-
Save emaia/71bf0437acab4bc785d6b0856f02583f to your computer and use it in GitHub Desktop.
Simple CI/CD api script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use Hyperf\Nano\Factory\AppFactory; | |
use Hyperf\HttpServer\Contract\RequestInterface; | |
require_once __DIR__.'/vendor/autoload.php'; | |
$app = AppFactory::create('0.0.0.0', 9051); | |
$app->post('/deployer/api/webhook/gh', function (RequestInterface $request) { | |
$secret = "mysupersecretkey"; // github webhook secret key | |
$signature = $request->getHeaders()['x-hub-signature'][0] ?? ''; | |
if ($signature) { | |
$hash = "sha1=".hash_hmac('sha1', $request->getBody(), $secret); | |
if (strcmp($signature, $hash) == 0) { | |
session_write_close(); | |
shell_exec("/home/ubuntu/deployer/deploy.sh > /dev/null 2>/dev/null &"); | |
return ['status' => 'processed']; | |
} | |
} | |
return ['status' => 'ok']; | |
}); | |
$app->run(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[program:deployer-api] | |
command=php /home/ubuntu/deployer/api-deployer.php start | |
user=ubuntu | |
autostart=true | |
autorestart=true | |
starttries=3 | |
stdout_logfile=/home/ubuntu/app/storage/logs/deploy-worker.log |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "deployer/php-api-deployer", | |
"require": { | |
"hyperf/nano": "^2.0" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
cd /home/ubuntu/app/ | |
git pull | |
php /usr/local/bin/composer install --no-interaction --prefer-dist --optimize-autoloader --no-dev | |
/home/ubuntu/.bun/bin/bun install | |
/home/ubuntu/.bun/bin/bun run build | |
php artisan cache:clear | |
php artisan responsecache:clear | |
php artisan optimize | |
php artisan octane:reload | |
cd storage/logs && touch deployed.log && echo 'Deployed at '$(date '+%Y-%m-%d %H:%M:%S') >> deployed.log |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment