Skip to content

Instantly share code, notes, and snippets.

@jjanvier
Last active June 13, 2021 21:24
Show Gist options
  • Save jjanvier/9137e13c9cd8ba12c3ccd01818a3c16b to your computer and use it in GitHub Desktop.
Save jjanvier/9137e13c9cd8ba12c3ccd01818a3c16b to your computer and use it in GitHub Desktop.
Deploying a Symfony4 Application with Deployer
<?php
// see the full blog post on http://jjanvier.com/blog/deploying-a-symfony4-application-with-deployer
namespace Deployer;
require 'recipe/symfony4.php';
// if .env variables are needed here, check https://github.com/deployphp/deployer/issues/1446
// and require __DIR__ . '/vendor/symfony/dotenv/Dotenv.php';
// Project name
set('application', 'jjanvier.com');
set('allow_anonymous_stats', false);
// Hosts
inventory('.deployer.yml');
// Tasks
desc('Build project LOCALLY');
task(
'build',
function () {
// build frontend
run('sh bin/build-front');
// build backend
run('composer install --no-ansi --no-dev --no-interaction --no-progress --no-scripts --optimize-autoloader');
}
)->local();
desc('Upload project');
task('upload', function () {
upload(__DIR__ . '/*', '{{release_path}}', ['options' =>
[
"--exclude='.env'",
"--exclude='.git/'",
"--exclude='.gitignore'",
"--exclude='.idea/'",
"--exclude='.*.xml.dist'",
"--exclude='.*.yml'",
"--exclude='.*.yml.dist'",
"--exclude='phpstan.neon'",
"--exclude='semantic.json'",
"--exclude='symfony.lock'",
"--exclude='node_modules/'",
"--exclude='semantic/'",
"--exclude='tests/'",
"--exclude='var/'",
]
]);
});
desc('Reinstall local vendors');
task(
'local-vendors',
function () {
run('composer install'); // all devs tools have been previously deleted with --no-dev, let's put them back!
}
)->local();
desc('Deploy project');
task('deploy', [ // override the default Symfony4 deploy task
'build',
'deploy:info',
'deploy:prepare',
'deploy:lock',
'deploy:release',
'upload',
'deploy:shared',
'deploy:cache:clear',
'deploy:cache:warmup',
'deploy:symlink',
'deploy:unlock',
'cleanup',
]);
after('deploy', 'local-vendors');
after('deploy', 'success');
// [Optional] if deploy fails automatically unlock.
after('deploy:failed', 'deploy:unlock');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment