Skip to content

Instantly share code, notes, and snippets.

@andersbjorkland
Created April 22, 2021 10:25
Show Gist options
  • Save andersbjorkland/7a7ba7d7c54fd937e115695ad986f037 to your computer and use it in GitHub Desktop.
Save andersbjorkland/7a7ba7d7c54fd937e115695ad986f037 to your computer and use it in GitHub Desktop.
Example of a Deployer recipe for deploying to a shared host. It is assumed Deployer is a Composer dependency in the current project.
<?php
namespace Deployer;
require 'recipe/symfony4.php';
/*
* Run either 'deploy' (Symfony 4 apps) or 'mydeploy' (adjusted for shared host one.com).
* If running deployer as a project dependency on Windows you may need to run this:
* php vendor/deployer/deployer/bin/dep deploy
* instead of php vendor/bin/dep deploy
*/
// Project name
set('application', 'homepage');
// Project repository
// You can use either the URL for SSH or this way, if you have a public repo
set('repository', 'https://github.com/username/reponame');
set('git_tty', false);
set('ssh_multiplexing', false);
set('composer_options', '{{composer_action}} --prefer-dist --no-progress --no-interaction --no-dev --optimize-autoloader');
// Shared files/dirs between deploys
add('shared_files', []);
add('shared_dirs', []);
// Writable dirs by web server
add('writable_dirs', []);
set('allow_anonymous_stats', false);
// Hosts
// The host_name can be the one you have configured in your .ssh/config file. It's a good idea to do that, as it makes it easy to access
// the host this way. Make sure to add your public ssh key to the remote server's ~/.ssh/authorized-keys file.
host('host_name')
->set('deploy_path', '~/{{application}}')
->set('http_user', 'remote_user') // Exclude this if you want Deployer to figure it out itself.
;
// Tasks
task('symlink:public', function() {
run('ln -s {{release_path}}/public/* /www && ln -s {{release_path}}/public/.[^.]* /www');
});
/* Is used when symlink from public folder doesn't behave as expected.
* The downside of using it this way is that it doesn't remove files no longer present in git repo.
* Assumed public directory is /www
*/
task('copy:public', function() {
run('cp -R {{release_path}}/public/* /www && cp -R {{release_path}}/public/.[^.]* /www');
});
task('build', function () {
run('cd {{release_path}} && build');
});
task('initialize', [
'deploy:info',
'deploy:prepare',
'deploy:lock',
'deploy:release',
'deploy:update_code',
'deploy:shared',
'deploy:unlock',
'cleanup',
]);
task('mydeploy', [
'deploy:info',
'deploy:prepare',
'deploy:lock',
'deploy:release',
'deploy:update_code',
'deploy:shared',
'deploy:vendors',
'deploy:cache:clear',
'deploy:cache:warmup',
'deploy:symlink',
'copy:public',
'deploy:unlock',
'cleanup',
]);
// [Optional] if deploy fails automatically unlock.
after('deploy:failed', 'deploy:unlock');
// Migrate database before symlink new release.
before('deploy:symlink', 'database:migrate');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment