Last active
December 8, 2022 16:31
-
-
Save mtwalsh/fce3c4aa416996e5900e8ac9f471dd6c to your computer and use it in GitHub Desktop.
Deployer recipe for Craft CMS 3 projects.
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 | |
namespace Deployer; | |
require 'recipe/common.php'; | |
// Project name | |
set('application', 'enovate.co.uk'); | |
// Project repository | |
set('repository', '[email protected]:enovatedesign/project.git'); | |
// Shared files/dirs between deploys | |
set('shared_files', [ | |
'.env' | |
]); | |
set('shared_dirs', [ | |
'storage' | |
]); | |
// Writable dirs by web server | |
set('writable_dirs', [ | |
'storage', | |
'storage/runtime', | |
'storage/logs', | |
'storage/rebrand', | |
'public/cpresources' | |
]); | |
// Set the worker process user | |
set('http_user', 'worker'); | |
// Set the default deploy environment to production | |
set('default_stage', 'production'); | |
// Disable multiplexing | |
set('ssh_multiplexing', false); | |
// Tasks | |
// Upload build assets | |
task('upload', function () { | |
upload(__DIR__ . "/public/assets/", '{{release_path}}/public/assets/'); | |
//upload(__DIR__ . "/public/service-worker.js", '{{release_path}}/public/service-worker.js'); | |
}); | |
desc('Execute migrations'); | |
task('craft:migrate', function () { | |
run('{{release_path}}/craft migrate/up'); | |
})->once(); | |
// Hosts | |
// Production Server(s) | |
host('110.164.16.59', '110.164.16.34', '110.164.16.50') | |
->set('deploy_path', '/websites/{{application}}') | |
->set('branch', 'master') | |
->stage('production') | |
->user('someuser'); | |
// Staging Server | |
host('192.168.16.59') | |
->set('deploy_path', '/websites/{{application}}') | |
->set('branch', 'develop') | |
->stage('staging') | |
->user('someuser'); | |
// Group tasks | |
desc('Deploy your project'); | |
task('deploy', [ | |
'deploy:info', | |
'deploy:prepare', | |
'deploy:lock', | |
'deploy:release', | |
'deploy:update_code', | |
'upload', // Custom task to upload build assets | |
'deploy:shared', | |
'deploy:writable', | |
'deploy:vendors', | |
'deploy:clear_paths', | |
'deploy:symlink', | |
'deploy:unlock', | |
'cleanup', | |
'success' | |
]); | |
// [Optional] Run migrations | |
after('deploy:vendors', 'craft:migrate'); | |
// [Optional] If deploy fails automatically unlock | |
after('deploy:failed', 'deploy:unlock'); | |
// Run with '--parallel' | |
// dep deploy --parallel |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for providing this! 👏 👏
Just fiy:
deploy:success
anddeploy:cleanup
(See: https://deployer.org/docs/7.x/UPGRADE), but they are already included indeploy:publish
deploy:prepare
anddeploy:publish
already bundle many tasks (https://github.com/deployphp/deployer/blob/master/recipe/common.php#L137)Shortened it down to the following, but I'm not yet a task expert for deployer. Not sure if 100% correct ;-)
Currently trying this https://dev.to/mandrasch/statamic-meets-hetzner-cloud-ploi-and-deployer-2ko5 approach with DDEV + Craft + Deployer on ploi + Hetzner Cloud. I'm currently stuck with the following for the first time deployment? Changed
php craft migrate/up
tophp craft up
, but no success. 🤔(Repo: https://github.com/mandrasch/train-to-lake-craftcms, deploy.php here: https://github.com/mandrasch/train-to-lake-craftcms/blob/main/deploy.php)
Update: Needed to run
php craft install/craft
inrelease/xx/
folder after first (failed) deployment (via SSH on target server). Deployment works fine after installation. 🥳