-
-
Save mvvitorsilvati/c7f13ef2a3bf06c5f98488c4495a91ec to your computer and use it in GitHub Desktop.
Deploying with Deployer PHP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Note that you have to first install deployer (https://deployer.org/download) | |
// Then put this script at the root of your project | |
// To deploy to development, run `dep deploy development` | |
namespace Deployer; | |
require 'recipe/common.php'; | |
// Servers | |
// Content of servers.yml shown in file below | |
serverList('servers.yml'); | |
set('ssh_type', 'native'); | |
set('ssh_multiplexing', true); | |
set('keep_releases', 5); | |
set('repository', 'git@gitlab.com:project-name/api.git'); | |
set('composer_options', 'install --verbose'); | |
add('shared_files', []); | |
add('shared_dirs', ['tmp']); | |
add('writable_dirs', ['tmp']); | |
/** | |
* Copy env variables | |
* You can rewrite this to suit your purposes. In my case, I copy the environment variables from my local system to the server | |
* depending on the environment variable decalred in servers.yml | |
*/ | |
task('deploy:copy_env_vars', function () { | |
upload(__DIR__ . '/v1.0/application/env/.env.{{APPLICATION_ENV}}', '{{release_path}}/v1.0/application/env/.env'); | |
})->desc('Copy Environment Variables'); | |
// Tasks | |
/** | |
* Main task | |
*/ | |
task('deploy', [ | |
'deploy:prepare', | |
'deploy:release', | |
'deploy:copy_dirs', | |
'deploy:update_code', | |
'deploy:shared', | |
'deploy:vendors', | |
'deploy:copy_env_vars', | |
'deploy:symlink', | |
'deploy:writable', | |
'cleanup', | |
])->desc('Deploy Project'); | |
// [Optional] if deploy fails automatically unlock. | |
after('deploy:failed', 'deploy:unlock'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
development: | |
host: ****** | |
user: ****** | |
stage: development | |
identity_file: | |
public_key: '~/.ssh/id_rsa.pub' | |
private_key: '~/.ssh/id_rsa' | |
password: 'key-password' | |
deploy_path: '/var/www/html/project-name' | |
branch: dev | |
DB_HOST: ****** | |
DB_NAME: ****** | |
DB_USERNAME: ****** | |
DB_PASSWORD: ****** | |
APPLICATION_ENV: 'development' | |
local_path: '/Users/tega/Codes/php/project-name' | |
production: | |
host: ****** | |
user: ****** | |
stage: production | |
identity_file: | |
public_key: '~/.ssh/id_rsa.pub' | |
private_key: '~/.ssh/id_rsa' | |
deploy_path: '/var/www/html/project-name' | |
branch: master | |
DB_HOST: ****** | |
DB_NAME: ****** | |
DB_USERNAME: ****** | |
DB_PASSWORD: ****** | |
APPLICATION_ENV: 'production' | |
local_path: '/Users/tega/Codes/php/project-name' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment