Coder Social home page Coder Social logo

laravel-deployer-recipes's Introduction

Laravel Deployer recipes

Source Code License: MIT

Extra Deployer recipes for Laravel projects.

Notice : some of this submodule recipes are using the https://github.com/Okipa/laravel-utils-dotfiles third dependency.


Installation

  • Install the extra laravel recipes in your project with the following command : git submodule add https://github.com/Okipa/laravel-deployer-recipes.git .deploy.
  • Make sure you add the following lines in the scripts part of your composer.json file to make sure that you always have an updated version of this git submodule :
"post-install-cmd": [
    ...
    "git submodule sync --recursive && git submodule update --init --recursive --remote --force",
    ...
],
"post-update-cmd": [
    ...
    "git submodule sync --recursive && git submodule update --init --recursive --remote --force",
    ...
]
  • Add the deployer.phar to the root path of your project : https://deployer.org/docs/getting-started
  • Create a deploy.php file at the root path of your project with the following content (adjusted according your project needs) :
namespace Deployer;

require 'recipe/laravel.php';
require './.deploy/asset_tasks.php';
require './.deploy/build_tasks.php';
require './.deploy/deploy_tasks.php';
require './.deploy/project_tasks.php';
require './.deploy/vendor_tasks.php';

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// define servers
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
$servers = [
    'preprod'    => [
        'host'             => '[domain_or_ip]',
        'branch'           => 'develop',
        'deploy_path'      => '[path_to_preprod_releases]',
        'user'             => '[preprod_user]',
        'http_user'        => '[preprod_http_user]',
        'http_group'       => '[http_group]',
        'private_identity' => '~/.ssh/id_rsa',
    ],
    'production' => [
        'host'             => '[domain_or_ip]',
        'branch'           => 'master',
        'deploy_path'      => '[path_to_production_releases]',
        'user'             => '[production_user]',
        'http_user'        => '[production_http_user]',
        'http_group'       => '[http_group]',
        'private_identity' => '~/.ssh/id_rsa',
    ],
];

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// servers configuration
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// we set the required configurations
set('repository', '[project_git_repository]');
set('composer_flags', '--no-dev --verbose --prefer-dist --optimize-autoloader --no-progress --no-interaction');
// we override the default deployer configurations
set('keep_releases', 3);
set('default_stage', 'preprod');
set('allow_anonymous_stats', false);
set('writable_mode', 'chmod');
set('writable_use_sudo', false);
set('bin/composer', function(){
    return run('which composer');
});
set('default_timeout', 900);
// we add custom configurations to laravel recipe (if needed)
// add('shared_dirs', ['public/files']);
// we configure servers
foreach ($servers as $stage => $server) {
    host($stage)
        ->stage($stage)
        ->hostname($server['host'])
        ->user($server['user'])
        ->identityFile($server['private_identity'])
        ->set('branch', $server['branch'])
        ->set('deploy_path', $server['deploy_path'])
        ->set('http_user', $server['http_user'])
        ->set('http_group', $server['http_group']);
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// build and deployment tasks
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
task('build', function() use ($servers) {
    set('deploy_path', getcwd() . '/.deploy/.build');
    set('branch', $servers[input()->getArgument('stage')]['branch']);
    try {
        invoke('build:check_latest');
    } catch (\RuntimeException $e) {    
        invoke('deploy:info');
        invoke('deploy:prepare');
        invoke('deploy:lock');
        invoke('deploy:release');
        invoke('deploy:update_code');
        invoke('deploy:writable');
        invoke('vendor:composer_setup');
        invoke('git:submodules:install');
        invoke('deploy:vendors');
        invoke('vendor:yarn_install_rsync'); // to use with laravel mix (to avoid webpack symlink issue)
        // invoke('vendor:yarn_install'); // faster => to only with non-webpack resources manager
        // invoke('vendor:bower_install'); // uncomment with bower usage
        invoke('resources:compile');
        invoke('deploy:symlink');
        invoke('build:create_package');
        invoke('deploy:unlock');
        invoke('cleanup');
    }
})->local()->desc('Locally building and compiling project archive');

task('release', [
    'deploy:info',
    'deploy:prepare',
    'deploy:lock',
    'deploy:release',
    'deploy:upload',
    // 'git:submodules:install', // uncomment if https://github.com/Okipa/laravel-utils-dotfiles submodule is used and with git submodules usage
    // 'project:dependencies_check', // uncomment if https://github.com/Okipa/laravel-utils-dotfiles submodule is used
    'deploy:shared',
    'deploy:writable',
    'artisan:storage:link',
    'artisan:view:clear',
    'artisan:cache:clear',
    'artisan:config:cache',
    // 'artisan:route:cache', // only uncomment if the app is NOT multilingual
    'artisan:optimize',
    'artisan:migrate',
    // 'artisan:queue:restart', // uncomment if https://github.com/Okipa/laravel-utils-dotfiles submodule is used
    'supervisor:restart',
    'deploy:symlink',
    'deploy:unlock',
    'cleanup',
    'server:resources:reload',
    'cron:install',
])->desc('Releasing compiled project archive on server');

task('deploy', [
    'build',
    'release',
])->desc('Starting project deployment process');

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// custom tasks chaining
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
after('deploy:failed', 'deploy:unlock');

Available recipes

asset_tasks.php

  • resources:compile : Compiling project resources.

build_tasks.php

  • build:create_package : Creating compiled project archive.

deploy_tasks.php

  • deploy:upload : Uploading compiled project archive on server.

project_tasks.php

  • git:submodules:install : Installing project submodules.
  • cron:install : Adding the laravel cron to the user crontab.
  • server:resources:reload : Reloading the server resources.
  • project:dependencies_check : Check if project dependencies are missing from the server.
  • supervisor:restart : Restarting the project supervisor daemon.

vendor_tasks.php

  • vendor:composer_setup : Setting up composer with a vendor directory caching.
  • vendor:yarn_install : Installing project node dependencies with a node_modules directory caching (usefull with gulp / elixir).
  • vendor:yarn_install_rsync : Installing project node dependencies with a node_modules directory caching and rsyncing the node_modules directory (usefull to avoid symbolic link webpack issue).
  • vendor:bower_install : Installing project bower dependencies with a bower_components directory caching.

laravel-deployer-recipes's People

Contributors

okipa avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.