Skip to content

Instantly share code, notes, and snippets.

@leeuwd
Last active November 8, 2022 11:57
Show Gist options
  • Save leeuwd/90553eb63178a439912f710f58989f1e to your computer and use it in GitHub Desktop.
Save leeuwd/90553eb63178a439912f710f58989f1e to your computer and use it in GitHub Desktop.
Deployer configuration Akeneo PIM. Assumes .env file in project root.
<?php
namespace Deployer;
require 'recipe/symfony3.php';
require 'recipe/yarn.php';
// Load .env
$dotenv = new \Symfony\Component\Dotenv\Dotenv();
$dotenv->load(__DIR__ . '/.env');
// Settings
set('ssh_type', 'native');
set('ssh_multiplexing', true);
set('default_stage', 'production');
set('application', getenv('APP_NAME'));
set('repository', getenv('GIT_REPOSITORY'));
// Symfony
set('shared_files', ['app/config/parameters.yml', '.env']);
set('shared_dirs', ['app/archive', 'app/file_storage', 'app/uploads', 'var/logs', 'var/sessions', 'var/backups']);
set('writable_dirs', [
'app/archive',
'app/file_storage',
'app/uploads',
'bin/backup',
'var/cache',
'var/logs',
'var/sessions',
'web/media',
]);
// Production
host('production')
->user(getenv('REMOTE_USER'))
->configFile('~/.ssh/config')
->identityFile('~/.ssh/id_rsa')
->hostname(getenv('REMOTE_HOSTNAME'))
->stage('production')
->set('branch', 'master')
->set('deploy_path', getenv('REMOTE_DEPLOY_PATH') . '/production');
// Tasks
task('deploy', [
'deploy:info',
'deploy:confirm',
'deploy:prepare',
'deploy:lock',
'deploy:release',
'deploy:update_code',
'deploy:clear_paths',
'deploy:create_cache_dir',
'deploy:shared',
'deploy:assets',
'deploy:vendors',
'pim:installer:dump-require-paths',
'pim:installer:assets',
'yarn:install',
'yarn:compile',
'deploy:assets:install',
'deploy:assetic:dump',
'deploy:cache:clear',
'deploy:cache:warmup',
'deploy:writable',
'database:migrate',
'deploy:symlink',
'php:restart',
'deploy:unlock',
'cleanup',
]);
// Custom task yarn:compile
desc('Execute yarn:compile');
task('yarn:compile', function () {
run('cd {{release_path}} && {{bin/yarn}} run webpack');
});
// Custom task to confirm
desc('Please confirm the deployment');
task('deploy:confirm', function () {
if (! askConfirmation('Are you sure you want to deploy?', true)) {
die('As you wish. Bye.');
}
});
// Custom task to dump require paths
desc('Execute pim:installer:dump-require-paths');
task('pim:installer:dump-require-paths', function () {
run('{{bin/php}} {{bin/console}} pim:installer:dump-require-paths');
});
// Custom task to dump require paths
desc('Execute pim:installer:assets');
task('pim:installer:assets', function () {
run('{{bin/php}} {{bin/console}} pim:installer:assets --symlink --clean {{console_options}}');
});
// Custom task to restart PHP FPM to fix a
// very aggressive cache of Twig templates.
desc('Restart PHP FPM');
task('php:restart', function () {
run('sudo /usr/sbin/service php7.1-fpm restart');
});
// Failure
after('deploy:failed', 'deploy:unlock');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment