John Davidson

php - How to deploy the latest release version by deployer

0 comments
Message:


I using a deployer to deploy my Laravel project. like below


<?php
namespace Deployer;

require 'recipe/laravel.php';

// Project repository
set('repository', '[email protected]');

// Shared files/dirs between deploys
add('shared_files', []);
add('shared_dirs', []);

// Writable dirs by web server
add('writable_dirs', []);

// copy relies
add('copy_dirs', ['node_modules', 'vendor']);
before('deploy:vendors', 'deploy:copy_dirs');

// Hosts
host('ip')
->user('www-data')
->identityFile('~/.ssh/id_rsa')
->set('deploy_path', '/var/www/example.com.deploy');

// [Optional] if deploy fails automatically unlock.
after('deploy:failed', 'deploy:unlock');

// Migrate database before symlink new release.
before('deploy:symlink', 'artisan:migrate');

But the deployer will deploy the code from main branch, what I want is delpoying the code of latest release branch.


How can I do this? I read the document, but nothing helps. Thanks a lot!



My Answer:
To deploy the latest release version using deployer, you can specify the branch to deploy from in your deploy script. You can do this by adding the following line to your deploy script:

php
set('branch', 'release_branch_name');


Replace 'release_branch_name' with the name of the branch you want to deploy from. This will tell deployer to deploy the code from the specified branch instead of the main branch.

Your updated deploy script will look like this:

php
namespace Deployer;

require 'recipe/laravel.php';

// Project repository
set('repository', '[email protected]');

// Shared files/dirs between deploys
add('shared_files', []);
add('shared_dirs', []);

// Writable dirs by web server
add('writable_dirs', []);

// copy relies
add('copy_dirs', ['node_modules', 'vendor']);
before('deploy:vendors', 'deploy:copy_dirs');

// Hosts
host('ip')
->user('www-data')
->identityFile('~/.ssh/id_rsa')
->set('deploy_path', '/var/www/example.com.deploy');

// Specify branch to deploy from
set('branch', 'release_branch_name');

// [Optional] if deploy fails automatically unlock.
after('deploy:failed', 'deploy:unlock');

// Migrate database before symlink new release.
before('deploy:symlink', 'artisan:migrate');


Now when you run the deploy command, deployer will deploy the code from the specified release branch.

Rate this post

5 of 5 based on 9519 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us