Last active
October 26, 2018 05:25
-
-
Save kresnasatya/81b2301312b8ae6a9942bd06339748c4 to your computer and use it in GitHub Desktop.
Setup CI/CD Laravel Deployer in Gitlab
This file contains hidden or 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 | |
return [ | |
/* | |
|-------------------------------------------------------------------------- | |
| Default deployment strategy | |
|-------------------------------------------------------------------------- | |
| | |
| This option defines which deployment strategy to use by default on all | |
| of your hosts. Laravel Deployer provides some strategies out-of-box | |
| for you to choose from explained in detail in the documentation. | |
| | |
| Supported: 'basic', 'firstdeploy', 'local', 'pull'. | |
| | |
*/ | |
'default' => 'basic', | |
/* | |
|-------------------------------------------------------------------------- | |
| Custom deployment strategies | |
|-------------------------------------------------------------------------- | |
| | |
| Here, you can easily set up new custom strategies as a list of tasks. | |
| Any key of this array are supported in the `default` option above. | |
| Any key matching Laravel Deployer's strategies overrides them. | |
| | |
*/ | |
'strategies' => [ | |
'staging' => [ | |
'hook:start', | |
'deploy:prepare', | |
'deploy:lock', | |
'deploy:release', | |
'deploy:update_code', | |
'upload', | |
'deploy:shared', | |
'deploy:vendors', | |
'copy_env:staging_value', // Perhatikan | |
'deploy:writable', | |
'hook:ready', // Di sini task artisan:generate berjalan | |
'deploy:symlink', | |
'deploy:unlock', | |
'cleanup', | |
'hook:done', | |
], | |
'production' => [ | |
'hook:start', | |
'deploy:prepare', | |
'deploy:lock', | |
'deploy:release', | |
'deploy:update_code', | |
'upload', | |
'deploy:shared', | |
'deploy:vendors', | |
'copy_env:production_value', // Perhatikan | |
'deploy:writable', | |
'hook:ready', // Di sini task artisan:generate berjalan | |
'deploy:symlink', | |
'deploy:unlock', | |
'cleanup', | |
'hook:done', | |
] | |
], | |
/* | |
|-------------------------------------------------------------------------- | |
| Hooks | |
|-------------------------------------------------------------------------- | |
| | |
| Hooks let you customize your deployments conveniently by pushing tasks | |
| into strategic places of your deployment flow. Each of the official | |
| strategies invoke hooks in different ways to implement their logic. | |
| | |
*/ | |
'hooks' => [ | |
// Right before we start deploying. | |
'start' => [ | |
// | |
], | |
// Code and composer vendors are ready but nothing is built. | |
'build' => [ | |
'npm:install', | |
'npm:production', | |
], | |
// Deployment is done but not live yet (before symlink) | |
'ready' => [ | |
'artisan:generate', // Task yang berasal dari my_recipe.php | |
'artisan:storage:link', | |
'artisan:view:clear', | |
'artisan:cache:clear', | |
'artisan:config:cache', | |
'artisan:optimize', | |
'artisan:migrate', | |
], | |
// Deployment is done and live | |
'done' => [ | |
'fpm:reload', | |
], | |
// Deployment succeeded. | |
'success' => [ | |
// | |
], | |
// Deployment failed. | |
'fail' => [ | |
// | |
], | |
], | |
/* | |
|-------------------------------------------------------------------------- | |
| Deployment options | |
|-------------------------------------------------------------------------- | |
| | |
| Options follow a simple key/value structure and are used within tasks | |
| to make them more configurable and reusable. You can use options to | |
| configure existing tasks or to use whithin your own custom tasks. | |
| | |
*/ | |
'options' => [ | |
'application' => env('APP_NAME', 'Mabatama'), | |
'repository' => '[email protected]:mabatama/mabatama.git', | |
'php_fpm_service' => 'php7.2-fpm', | |
], | |
/* | |
|-------------------------------------------------------------------------- | |
| Hosts | |
|-------------------------------------------------------------------------- | |
| | |
| Here, you can define any domain or subdomain you want to deploy to. | |
| You can provide them with roles and stages to filter them during | |
| deployment. Read more about how to configure them in the docs. | |
| | |
*/ | |
'hosts' => [ | |
'laravel-basic.com' => [ | |
'deploy_path' => '/var/www/laravel-basic', | |
'user' => 'deployer', | |
], | |
'test.laravel-basic.com' => [ | |
'deploy_path' => '/var/www/laravel-basic', | |
'user' => 'deployer', | |
], | |
], | |
/* | |
|-------------------------------------------------------------------------- | |
| Localhost | |
|-------------------------------------------------------------------------- | |
| | |
| This localhost option give you the ability to deploy directly on your | |
| local machine, without needing any SSH connection. You can use the | |
| same configurations used by hosts to configure your localhost. | |
| | |
*/ | |
'localhost' => [ | |
// | |
], | |
/* | |
|-------------------------------------------------------------------------- | |
| Include additional Deployer recipes | |
|-------------------------------------------------------------------------- | |
| | |
| Here, you can add any third party recipes to provide additional tasks, | |
| options and strategies. Therefore, it also allows you to create and | |
| include your own recipes to define more complex deployment flows. | |
| | |
*/ | |
'include' => [ | |
'recipe/my_recipe.php', | |
'recipe/production_recipe.php', | |
'recipe/staging_recipe.php', | |
], | |
/* | |
|-------------------------------------------------------------------------- | |
| Use a custom Deployer file | |
|-------------------------------------------------------------------------- | |
| | |
| If you know what you are doing and want to take complete control over | |
| Deployer's file, you can provide its path here. Note that, without | |
| this configuration file, the root's deployer file will be used. | |
| | |
*/ | |
'custom_deployer_file' => false, | |
]; |
This file contains hidden or 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 | |
namespace Deployer; | |
task('artisan:generate', function() { | |
run('{{bin/php}} {{release_path}}/artisan key:generate'); | |
}); |
This file contains hidden or 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 | |
namespace Deployer; | |
desc('Copy env production value'); | |
task('copy_env:production_value', function() { | |
run('cp /home/deployer/env-laravel/laravel-basic/production/.env /var/www/laravel-basic/shared/'); | |
}); |
This file contains hidden or 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 | |
namespace Deployer; | |
desc('Copy env staging value'); | |
task('copy_env:staging_value', function() { | |
run('cp /home/deployer/env-laravel/laravel-basic/staging/.env /var/www/test-laravel-basic/shared/'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment