Skip to content

Instantly share code, notes, and snippets.

@lcharette
Last active February 19, 2021 18:48
Show Gist options
  • Save lcharette/91edc141d55918a5c2d9589f83c7dc82 to your computer and use it in GitHub Desktop.
Save lcharette/91edc141d55918a5c2d9589f83c7dc82 to your computer and use it in GitHub Desktop.
Grav Deployment on Push Using GitHub Webhook
<?php
namespace Deployer;
require 'recipe/common.php';
// Project name
set('application', 'MyGravSite');
// Project repository
set('repository', 'https://github.com/lcharette/website.git');
set('grav_repository', 'https://github.com/getgrav/grav.git');
// Set grav dir, relative to `deploy_path`
set('grav_dir', 'grav');
// Shared files/dirs between deploys
set('shared_files', []);
set('shared_dirs', []);
// Writable dirs by web server
set('writable_dirs', []);
// Hosts
localhost()
->set('deploy_path', '/var/www/grav'); // <--- Edit destination here
// Grav exist
set('grav_exist', function () {
return test('[ -x "$(command -v {{deploy_path}}/{{grav_dir}}/bin/grav)" ]');
});
task('deploy:whoami', function () {
$result = run('whoami');
writeln($result);
});
// Grav install task
task('grav:install', function () {
within('{{deploy_path}}/{{grav_dir}}', function () {
run('bin/grav install');
});
});
// Grav clear-cache
task('grav:clearcache', function () {
within('{{deploy_path}}/{{grav_dir}}', function () {
run('bin/grav clear-cache');
});
});
// Grav clone - Install Grav from scratch
task('grav:clone', function () {
if (!get('grav_exist')) {
$git = get('bin/git');
$quiet = isQuiet() ? '-q' : '';
$options = [
'tty' => get('git_tty', false),
];
run("$git clone $quiet {{grav_repository}} {{deploy_path}}/{{grav_dir}} 2>&1", $options);
}
});
// Grav self update
task('grav:update', function() {
within('{{deploy_path}}/{{grav_dir}}', function () {
run('bin/gpm selfupgrade -f');
});
});
task('grav:symlink', function () {
run('rm -rf {{deploy_path}}/{{grav_dir}}/user');
run("{{bin/symlink}} {{deploy_path}}/current {{deploy_path}}/{{grav_dir}}/user");
});
// Tasks
desc('Deploy your project');
task('deploy', [
'deploy:info',
'deploy:whoami',
'deploy:prepare',
'deploy:lock',
'grav:clone',
'grav:update',
'deploy:release',
'deploy:update_code',
'deploy:shared',
'deploy:writable',
'deploy:clear_paths',
'deploy:symlink',
'grav:symlink',
'grav:install',
'grav:clearcache',
'deploy:unlock',
'cleanup',
'success'
]);
// [Optional] If deploy fails automatically unlock.
after('deploy:failed', 'deploy:unlock');
[
{
"id": "bbq",
"execute-command": "/usr/local/bin/dep",
"command-working-directory": "/var/www/webhooks",
"include-command-output-in-response": true,
"include-command-output-in-response-on-err": true,
"pass-arguments-to-command":
[
{
"source": "string",
"name": "--file=deploy-bbq.php"
},
{
"source": "string",
"name": "deploy"
}
]
}
]
[Unit]
Description=Small server for creating HTTP endpoints (hooks)
Documentation=https://github.com/adnanh/webhook/
[Service]
User=www-data
Group=www-data
ExecStart=/usr/bin/webhook -nopanic -hooks /var/www/webhooks/hooks.json -verbose -secure -cert /etc/letsencrypt/live/domain.com/fullchain.pem -key /etc/letsencrypt/live/domain.com/privkey.pem
[Install]
WantedBy=multi-user.target
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment