Git Product home page Git Product logo

capistrano-laravel's Introduction

Capistrano-Laravel [Depreciated]

Move to new repository inside Deploy Laravel


Zero downtime deployment Laravel with Capistrano

Requirements

  • Ruby Environment (RBENV) or Ruby Version Manager (RVM)

  • Clone this repo

    git clone [email protected]:zeroc0d3/capistrano-laravel.git
    
  • Running docker-compose

    cd capistrano-laravel
    ./run-docker.sh
    
  • Edit Laravel source target in docker/compose/rootfs/root/deploy/config/deploy.rb

    set :repo_url, "[YOUR_LARAVEL_REPO]"
    
  • Edit target server environment in docker/compose/rootfs/root/deploy/config/deploy/[environment].rb

    server '[YOUR_TARGET_SERVER]'
    
  • Upload your shared files & folders in your server / VPS

    /var/www/[laravel-project]/[environment]/shared/src
    ---
    .env
    composer.json
    composer.lock
    node_modules
    package.json
    storage/debugbar
    storage/framework
    storage/logs
    vendor
    yarn.lock
    
  • Setup number of release folder in docker/compose/rootfs/root/deploy/config/deploy.rb

    set :keep_releases, 5    ## keep 5 release folder
    

Symlink Files (Default)

append :linked_files, "#{fetch(:source)}/.env", "#{fetch(:source)}/composer.json", "#{fetch(:source)}/composer.lock", "#{fetch(:source)}/package.json", "#{fetch(:source)}/yarn.lock",
---
.env
composer.json
composer.lock
package.json
yarn.lock

Symlink Folders (Default)

append :linked_dirs, "#{fetch(:source)}/vendor", "#{fetch(:source)}/node_modules", "#{fetch(:source)}/storage"
---
vendor
node_modules
storage

Folder Structure

[laravel-project]
├── staging
│   ├── current -> /var/www/[laravel-project]/staging/releases/20191123134641/
│   ├── releases
│   │   ├── 20191123081119
│   │   └── 20191123134641   ### the latest symlink
│   │       ├── .env -> /var/www/[laravel-project]/staging/shared/src/.env
│   │       ├── composer.json -> /var/www/[laravel-project]/staging/shared/src/composer.json
│   │       ├── composer.lock -> /var/www/[laravel-project]/staging/shared/src/composer.lock
│   │       ├── vendor -> /var/www/[laravel-project]/staging/shared/src/vendor/
│   │       ├── node_modules -> /var/www/[laravel-project]/staging/shared/src/node_modules/
│   │       ├── storage -> /var/www/[laravel-project]/staging/shared/src/storage/
│   │       └── yarn.lock -> /var/www/[laravel-project]/staging/shared/src/yarn.lock
│   ├── shared
│   │   ├── log
│   │   └── src
│   │       ├── .env
│   │       ├── composer.json
│   │       ├── vendor
│   │       ├── node_modules
│   │       └── storage
│   │           ├── debugbar
│   │           ├── framework
│   │           │   ├── cache
│   │           │   ├── sessions
│   │           │   └── views
│   │           ├── logs
│   │           └── users
│   └── tmp
└── [environments]

Access Deployment Container

  • Goto container
    docker exec -it [CONTAINER_NAME]
    ---
    eg:
    docker exec -it zeroc0d3lab_deployment bash
    
  • Install Dependencies Gem
    rvm use [RUBY_VERSION]   # eg: RUBY_VERSION=2.7.1
    ---
    rvm use 2.7.1
    bundle install
    

Deployment (Inside Container)

  • Set Environment RVM
    rvm use [RUBY_VERSION]   # eg: RUBY_VERSION=2.7.1
    ---
    rvm use 2.7.1
    
  • Staging
    cap staging deploy
    
  • Preproduction
    cap preprod deploy
    
  • Production
    cap production deploy
    

Manual Trigger (Inside Container)

  • Set Environment RVM
    rvm use [RUBY_VERSION]   # eg: RUBY_VERSION=2.7.1
    ---
    rvm use 2.7.1
    
  • Reload / Restart NGINX
    cap [environment] nginx:[manual_reload|manual_restart]
    ---
    cap staging nginx:manual_reload
    cap staging nginx:manual_restart
    
  • Reload / Restart PHP-FPM (php7.4-fpm)
    cap [environment] phpfpm:[manual_reload|manual_restart]
    ---
    cap staging phpfpm:manual_reload
    cap staging phpfpm:manual_restart
    
  • Install / Dump Autoload Composer
    cap [environment] composer:[install|dumpautoload|initialize]
    ---
    cap staging composer:install
    cap staging composer:dumpautoload
    cap staging composer:initialize   ## (will run install & dumpautoload)
    
  • Clear View / Clear Cache Framework
    cap [environment] artisan:[clear_view|clear_cache|clear_all]
    ---
    cap staging artisan:clear_view
    cap staging artisan:clear_cache
    cap staging artisan:clear_all   ## (will run clear_view & clear_cache)
    
  • NPM Package Dependencies
    cap [environment] npm:[install|update|cleanup|reinstall]
    ---
    cap staging npm:install
    cap staging npm:update
    cap staging npm:cleanup
    cap staging npm:reinstall ## (will run cleanup & install)
    
  • Yarn Package Dependencies
    cap [environment] yarn:[install|update|cleanup|reinstall]
    ---
    cap staging yarn:install
    cap staging yarn:update
    cap staging yarn:cleanup
    cap staging yarn:reinstall ## (will run cleanup & install)
    

Environment Tested

  • Docker version
    docker -v
    ---
    Docker version 19.03.11, build 42e35e61f3
    
  • Docker-compose version
    docker-compose -v
    ---
    docker-compose version 1.24.1, build 4667896b
    
  • Ruby version
    ruby -v
    ---
    ruby 2.7.1p83 (2020-03-31 revision a0c7c23c9c) [x86_64-linux]
    

Properties

  • Author : @zeroc0d3 (ZeroC0D3Lab)
  • License : Apache ver-2

capistrano-laravel's People

Contributors

zeroc0d3 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

siberfx

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.