Skip to content

Instantly share code, notes, and snippets.

@yaapis
Last active September 17, 2021 10:40
Show Gist options
  • Save yaapis/a54156ee3717d66e3fd42856262079a2 to your computer and use it in GitHub Desktop.
Save yaapis/a54156ee3717d66e3fd42856262079a2 to your computer and use it in GitHub Desktop.
deploy.php for Laravel
<?php
namespace Deployer;
require 'recipe/laravel.php';
require 'deploy/recipe/rsync.php';
set('rsync_src', __DIR__ . '/public');
set('rsync_dest', '{{release_path}}/public');
// Project name
set('application', 'Project');
// Project repository
set('repository', getenv('CI_REPOSITORY_URL'));
// [Optional] Allocate tty for git clone. Default value is false.
set('git_tty', false);
set('allow_anonymous_stats', false);
set('keep_releases', 1);
// Shared files/dirs between deploys
add(
'shared_dirs',
[
'public/uploads',
'public/thumbs',
]
);
// Writable dirs by web server
set(
'writable_dirs',
[
// 'storage',
// 'public/uploads',
// 'public/thumbs',
]
);
//github token
set('github_oauth_token', '66ef4719f............00eae');
set(
'composer_options',
'{{composer_action}} --verbose --prefer-dist --no-progress --no-interaction --no-dev --optimize-autoloader'
);
set(
'rsync',
[
'exclude' => [],
'exclude-file' => false,
'include' => [
// 'public/css',
// '*/',
// 'js/**'
],
'include-file' => false,
'filter' => [],
'filter-file' => false,
'filter-perdir' => false,
'flags' => 'rz', // Recursive, with compress
// 'options' => ['delete'],
'options' => [],
'timeout' => 360,
]
);
// Hosts
host(getenv('DEPLOY_SERVER'))
->set('branch', getenv('CI_COMMIT_REF_NAME'))
->set('deploy_path', getenv('DEPLOY_BASE_DIR'))
->stage(getenv('CI_COMMIT_REF_NAME'))
->user(getenv('DEPLOY_USER'))
->set('bin/php', getenv('BIN_PHP'))
->set('bin/composer', getenv('BIN_COMPOSER'))
->forwardAgent(true)
->multiplexing(true)
->addSshOption('UserKnownHostsFile', '/dev/null')
->addSshOption('StrictHostKeyChecking', 'no');
// Tasks
// [Optional] if deploy fails automatically unlock.
after('deploy:failed', 'deploy:unlock');
// Migrate database before symlink new release.
before('deploy:symlink', 'artisan:migrate');
desc('Execute artisan config:clear');
task('artisan:config:clear', function () {
run('{{bin/php}} {{release_path}}/artisan config:clear');
});
task(
'deploy',
[
'deploy:info',
'deploy:prepare',
'deploy:lock',
'deploy:release',
'deploy:update_code',
'rsync',
'deploy:shared',
'deploy:vendors',
// 'deploy:writable',
'artisan:storage:link',
'artisan:view:cache',
'artisan:cache:clear',
'artisan:config:clear',
// 'artisan:optimize',
'deploy:symlink',
'deploy:unlock',
'cleanup',
]
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment