├── .editorconfig ├── .gitignore ├── .rspec ├── .travis.yml ├── CHANGELOG.md ├── Gemfile ├── LICENSE ├── README.md ├── Rakefile ├── bin ├── console └── setup ├── capistrano-laravel.gemspec ├── lib ├── capistrano │ ├── laravel.rb │ ├── laravel │ │ └── version.rb │ └── tasks │ │ └── laravel.rake └── capistrano_laravel.rb └── spec ├── capistrano └── laravel_spec.rb └── spec_helper.rb /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | indent_style = space 5 | indent_size = 4 6 | end_of_line = lf 7 | charset = utf-8 8 | trim_trailing_whitespace = true 9 | insert_final_newline = true 10 | 11 | [*.md] 12 | trim_trailing_whitespace = false 13 | 14 | [*.rake] 15 | indent_size = 2 16 | 17 | [*.rb] 18 | indent_size = 2 19 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /.bundle/ 2 | /.yardoc 3 | /Gemfile.lock 4 | /_yardoc/ 5 | /coverage/ 6 | /doc/ 7 | /pkg/ 8 | /spec/reports/ 9 | /tmp/ 10 | 11 | # rspec failure tracking 12 | .rspec_status 13 | -------------------------------------------------------------------------------- /.rspec: -------------------------------------------------------------------------------- 1 | --format documentation 2 | --color 3 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: ruby 2 | rvm: 3 | - 2.5 4 | - 2.6 5 | - 2.7 6 | 7 | script: bundle exec rake spec rubocop 8 | install: bundle install --jobs=1 9 | cache: bundler 10 | sudo: false 11 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | All notable changes to this project will be documented in this file. 3 | 4 | The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), 5 | and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). 6 | 7 | ## [Unreleased] 8 | ### Added 9 | 10 | ### Changed 11 | 12 | ### Deprecated 13 | 14 | ### Removed 15 | 16 | ### Fixed 17 | 18 | ### Security 19 | 20 | ## [1.2.3] - 2020-01-28 21 | ### Changed 22 | - Tested RVM versions to `2.5`, `2.6`, and `2.7`. 23 | - Source files to reflect changes requested by rubocop. 24 | - `laravel:upload_dotenv_file` to run before `deploy:updated` instead of 25 | `composer:run` to avoid issues with rollback. 26 | 27 | ### Removed 28 | - `.rubocop.yml` in favor of just using defaults. 29 | 30 | ## [1.2.2] - 2018-03-07 31 | ### Added 32 | - Rubocop to Travis-CI. 33 | 34 | ### Changed 35 | - Versions of ruby tested against in Travis-CI. 36 | - Single quotes to double quotes. 37 | - `artisan optimize` to not run if Laravel version is greater than or equal to 5.5. 38 | 39 | ## [1.2.1] - 2017-02-24 40 | ### Fixed 41 | - `:laravel_upload_dotenv_file_on_deploy` symbol in `laravel:upload_dotenv_file` task. 42 | 43 | ## [1.2.0] - 2017-02-22 44 | ### Added 45 | - `:laravel_upload_dotenv_file_on_deploy` boolean config value to enable/disable dotenv file upload on deploy. 46 | 47 | ## [1.1.1] - 2017-01-29 48 | ### Changed 49 | - Logic for checking whether or not ACL checks are perfomed to be in-line with the task instead of in the runlist. 50 | - `laravel:ensure_acl_paths_exist` to run before `deploy:updating` instead of after `deploy:starting`. 51 | - `deploy:set_permissions:acl` to run before `deploy:updated` instead of after `deploy:updating`. 52 | 53 | ## [1.1.0] - 2016-10-28 54 | ### Changed 55 | - Linked directories to be more specific instead of simply just `storage` folder. 56 | - Runlist to separate out tasks related to `:laravel_set_acl_paths`. 57 | 58 | ### Removed 59 | - Config check against `:laravel_set_acl_paths` when merging values into `:file_permissions_paths` and `:file_permissions_users`. 60 | 61 | ### Fixed 62 | - Creation of linked dirs to run under `shared_path` instead of under `release_path`. 63 | 64 | ## [1.0.1] - 2016-10-14 65 | ### Fixed 66 | - `artisan storage:link` to not run if Laravel version is less than or equal to 5.3. 67 | 68 | ## [1.0.0] - 2016-10-12 69 | ### Added 70 | - Editorconfig file. 71 | - Rspec configuration. 72 | - Travis-CI configuration. 73 | - Additional README contents to better explain how the plugin works and should be developed. 74 | - Inline comments to tasks file for every configuration value and task. 75 | - `laravel:storage_link` task for creating public storage link. 76 | 77 | ### Changed 78 | - Gitignore file to ignore more ruby-related files. 79 | - MIT license to be up-to-date for 2016. 80 | - Gemfile to use `Capistrano::Laravel::VERSION` instead of hardcoding it into the Gemfile. 81 | - `laravel:configure_folders` to `laravel:resolve_linked_dirs` and `laravel:ensure_linked_dirs_exist`. 82 | - `laravel:create_linked_acl_paths` to `laravel:resolve_acl_paths`. 83 | - `laravel:optimize_config` to `laravel:config_cache`. 84 | - `laravel:optimize_route` to `laravel:route_cache`. 85 | - `laravel:optimize_release` to `laravel:optimize`. 86 | - `laravel:migrate_db` to `laravel:migrate`. 87 | - `laravel:rollback_db` to `laravel:migrate_rollback`. 88 | - Runlist to reflect the refactored tasks. 89 | 90 | ### Removed 91 | - The empty class `capistrano/laravel/helpers`. 92 | 93 | ### Fixed 94 | - `laravel:artisan` task formatting so it can properly take inputs. 95 | 96 | ## [0.0.4] - 2016-10-02 97 | ### Changed 98 | - `laravel:artisan` tasks to be ran more than once. 99 | 100 | ## [0.0.3] - 2016-03-07 101 | ### Added 102 | - More documentation to the README. 103 | - `Capistrano::Laravel::VERSION`. 104 | 105 | ### Changed 106 | - Merged tasks files (artisan, laravel, migrations) into a single file. 107 | - Task loading logic to read just a single file. 108 | 109 | ## [0.0.2] - 2013-11-12 110 | ### Changed 111 | - Default `:file_permissions_user` to `:laravel_server_user` from `:webserver_user`. 112 | 113 | ## [0.0.1] - 2013-11-12 114 | ### Added 115 | - Basic Laravel tasks: `laravel:artisan`, `laravel:artisan optimize`, `laravel:artisan migrate`. 116 | 117 | [Unreleased]: https://github.com/capistrano/laravel/compare/v1.2.3...HEAD 118 | [1.2.3]: https://github.com/capistrano/laravel/compare/v1.2.2...v1.2.3 119 | [1.2.2]: https://github.com/capistrano/laravel/compare/v1.2.1...v1.2.2 120 | [1.2.1]: https://github.com/capistrano/laravel/compare/v1.2.0...v1.2.1 121 | [1.2.0]: https://github.com/capistrano/laravel/compare/v1.1.1...v1.2.0 122 | [1.1.1]: https://github.com/capistrano/laravel/compare/v1.1.0...v1.1.1 123 | [1.1.0]: https://github.com/capistrano/laravel/compare/v1.0.1...v1.1.0 124 | [1.0.1]: https://github.com/capistrano/laravel/compare/v1.0.0...v1.0.1 125 | [1.0.0]: https://github.com/capistrano/laravel/compare/v0.0.4...v1.0.0 126 | [0.0.4]: https://github.com/capistrano/laravel/compare/v0.0.3...v0.0.4 127 | [0.0.3]: https://github.com/capistrano/laravel/compare/v0.0.2...v0.0.3 128 | [0.0.2]: https://github.com/capistrano/laravel/compare/v0.0.1...v0.0.2 129 | [0.0.1]: https://github.com/capistrano/laravel/releases/tag/v0.0.1 130 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | source 'https://rubygems.org' 4 | 5 | # Specify your gem's dependencies in capistrano-laravel.gemspec 6 | gemspec 7 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Peter Mitchell (peterjmit@gmail.com) 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Capistrano::Laravel 2 | 3 | Deploy Laravel applications with Capistrano v3.* 4 | 5 | ## Installation 6 | 7 | If managing your Capistrano deploy as a ruby project, add this line to your 8 | application's Gemfile: 9 | 10 | ```ruby 11 | gem 'capistrano', '~> 3.0.0' 12 | gem 'capistrano-laravel' 13 | ``` 14 | 15 | And then execute: 16 | 17 | ```shell 18 | bundle 19 | ``` 20 | 21 | Or install it yourself as: 22 | 23 | ```shell 24 | gem install capistrano-laravel 25 | ``` 26 | 27 | ## Setting up Capistrano 28 | 29 | After installing Capistrano, you can use it to initialize a skeleton 30 | configuration. To setup Capistrano, please follow the documentation 31 | provided on their website: 32 | 33 | http://capistranorb.com/documentation/getting-started/preparing-your-application/ 34 | 35 | This will generate the following files: 36 | 37 | ``` 38 | . 39 | ├── Capfile # Used to manage Capistrano and its dependencies 40 | ├── config 41 | │   ├── deploy 42 | │   │   ├── production.rb # Configuration for production environment 43 | │   │   └── staging.rb # Configuration for staging environment 44 | │   └── deploy.rb # Common configuration for all environments 45 | └── lib 46 | └── capistrano 47 | └── tasks # Customized Capistrano tasks for your project 48 | ``` 49 | 50 | ## Usage 51 | 52 | Require the module in your `Capfile`: 53 | 54 | ```ruby 55 | require 'capistrano/laravel' 56 | ``` 57 | 58 | ### Configuration 59 | 60 | The gem makes the following configuration variables available (shown with defaults). 61 | 62 | ```ruby 63 | # Which roles to consider as laravel roles 64 | set :laravel_roles, :all 65 | 66 | # The artisan flags to include on artisan commands by default 67 | set :laravel_artisan_flags, "--env=#{fetch(:stage)}" 68 | 69 | # Which roles to use for running migrations 70 | set :laravel_migration_roles, :all 71 | 72 | # The artisan flags to include on artisan commands by default when running migrations 73 | set :laravel_migration_artisan_flags, "--force --env=#{fetch(:stage)}" 74 | 75 | # The version of laravel being deployed 76 | set :laravel_version, 5.3 77 | 78 | # Whether to upload the dotenv file on deploy 79 | set :laravel_upload_dotenv_file_on_deploy, true 80 | 81 | # Which dotenv file to transfer to the server 82 | set :laravel_dotenv_file, './.env' 83 | 84 | # The user that the server is running under (used for ACLs) 85 | set :laravel_server_user, 'www-data' 86 | 87 | # Ensure the dirs in :linked_dirs exist? 88 | set :laravel_ensure_linked_dirs_exist, true 89 | 90 | # Link the directores in laravel_linked_dirs? 91 | set :laravel_set_linked_dirs, true 92 | 93 | # Linked directories for a standard Laravel 4 application 94 | set :laravel_4_linked_dirs, [ 95 | 'app/storage' 96 | ] 97 | 98 | # Linked directories for a standard Laravel 5 application 99 | set :laravel_5_linked_dirs, [ 100 | 'storage' 101 | ] 102 | 103 | # Ensure the paths in :file_permissions_paths exist? 104 | set :laravel_ensure_acl_paths_exist, true 105 | 106 | # Set ACLs for the paths in laravel_acl_paths? 107 | set :laravel_set_acl_paths, true 108 | 109 | # Paths that should have ACLs set for a standard Laravel 4 application 110 | set :laravel_4_acl_paths, [ 111 | 'app/storage', 112 | 'app/storage/public', 113 | 'app/storage/cache', 114 | 'app/storage/logs', 115 | 'app/storage/meta', 116 | 'app/storage/sessions', 117 | 'app/storage/views' 118 | ] 119 | 120 | # Paths that should have ACLs set for a standard Laravel 5 application 121 | set :laravel_5_acl_paths, [ 122 | 'bootstrap/cache', 123 | 'storage', 124 | 'storage/app', 125 | 'storage/app/public', 126 | 'storage/framework', 127 | 'storage/framework/cache', 128 | 'storage/framework/sessions', 129 | 'storage/framework/views', 130 | 'storage/logs' 131 | ] 132 | ``` 133 | 134 | ### Tasks 135 | 136 | The following tasks are added to your deploy automagically when adding 137 | capistrano/laravel to your deploy. 138 | 139 | ```ruby 140 | before 'deploy:starting', 'laravel:resolve_linked_dirs' 141 | before 'deploy:starting', 'laravel:resolve_acl_paths' 142 | after 'deploy:starting', 'laravel:ensure_linked_dirs_exist' 143 | before 'deploy:updating', 'laravel:ensure_acl_paths_exist' 144 | before 'deploy:updated', 'deploy:set_permissions:acl' 145 | before 'deploy:updated', 'laravel:upload_dotenv_file' 146 | after 'composer:run', 'laravel:storage_link' 147 | after 'composer:run', 'laravel:optimize' 148 | ``` 149 | 150 | #### Task Descriptions 151 | 152 | ```ruby 153 | # Determine which folders, if any, to use for linked directories. 154 | invoke 'laravel:resolve_linked_dirs' 155 | 156 | # Determine which paths, if any, to have ACL permissions set. 157 | invoke 'laravel:resolve_acl_paths' 158 | 159 | # Ensure that linked dirs exist. 160 | invoke 'laravel:ensure_linked_dirs_exist' 161 | 162 | # Ensure that ACL paths exist. 163 | invoke 'laravel:ensure_acl_paths_exist' 164 | 165 | # Upload dotenv file for release. 166 | invoke 'laravel:upload_dotenv_file' 167 | 168 | # Execute a provided artisan command. 169 | # Replace :command_name with the command to execute 170 | invoke 'laravel:artisan[:command_name]' 171 | 172 | # Create a cache file for faster configuration loading 173 | invoke 'laravel:config_cache' 174 | 175 | # Create a route cache file for faster route registration 176 | invoke 'laravel:route_cache' 177 | 178 | # Optimize the framework for better performance. 179 | invoke 'laravel:optimize' 180 | 181 | # Create a symbolic link from "public/storage" to "storage/app/public" 182 | invoke 'laravel:storage_link' 183 | 184 | # Run the database migrations. 185 | invoke 'laravel:migrate' 186 | 187 | # Rollback the last database migration. 188 | invoke 'laravel:migrate_rollback' 189 | ``` 190 | 191 | ## Development 192 | 193 | After checking out the repo, run `bin/setup` to install dependencies. Then, run 194 | `rake spec` to run the tests. You can also run `bin/console` for an interactive 195 | prompt that will allow you to experiment. 196 | 197 | To install this gem onto your local machine, run `bundle exec rake install`. To 198 | release a new version, update the version number in `version.rb`, and then run 199 | `bundle exec rake release`, which will create a git tag for the version, push 200 | git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org). 201 | 202 | ## Contributing 203 | 204 | Bug reports and pull requests are welcome on GitHub at https://github.com/capistrano/laravel. 205 | 206 | ## License 207 | 208 | The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT). 209 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'bundler/gem_tasks' 4 | require 'rspec/core/rake_task' 5 | require 'rubocop/rake_task' 6 | 7 | task default: %i[spec rubocop] 8 | RSpec::Core::RakeTask.new(:spec) 9 | 10 | desc 'Run RuboCop checks' 11 | RuboCop::RakeTask.new 12 | -------------------------------------------------------------------------------- /bin/console: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | 3 | # frozen_string_literal: true 4 | 5 | require 'bundler/setup' 6 | require 'capistrano/laravel' 7 | 8 | # You can add fixtures and/or initialization code here to make experimenting 9 | # with your gem easier. You can also use a different console, if you like. 10 | 11 | # (If you use this, don't forget to add pry to your Gemfile!) 12 | # require 'pry' 13 | # Pry.start 14 | 15 | require 'irb' 16 | IRB.start 17 | -------------------------------------------------------------------------------- /bin/setup: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -euo pipefail 3 | IFS=$'\n\t' 4 | set -vx 5 | 6 | bundle install 7 | 8 | # Do any other automated setup that you need to do here 9 | -------------------------------------------------------------------------------- /capistrano-laravel.gemspec: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | lib = File.expand_path('lib', __dir__) 4 | $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) 5 | require 'capistrano/laravel/version' 6 | 7 | Gem::Specification.new do |spec| 8 | spec.name = 'capistrano-laravel' 9 | spec.version = Capistrano::Laravel::VERSION 10 | spec.authors = ['Peter Mitchell', 'Andrew Miller'] 11 | spec.email = ['peterjmit@gmail.com', 'ikari7789@yahoo.com'] 12 | 13 | spec.summary = 'Laravel specific deployment options for Capistrano 3.x' 14 | spec.description = 'Laravel deployment for Capistrano 3.x' 15 | spec.homepage = 'https://github.com/capistrano/laravel' 16 | spec.license = 'MIT' 17 | 18 | spec.files = `git ls-files -z`.split("\x0").reject do |f| 19 | f.match(%r{^(test|spec|features)/}) 20 | end 21 | spec.bindir = 'exe' 22 | spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) } 23 | spec.require_paths = ['lib'] 24 | 25 | spec.required_ruby_version = '>= 2.3.0' 26 | 27 | spec.add_dependency 'capistrano', '>= 3.0.0' 28 | spec.add_dependency 'capistrano-composer', '>= 0.0.6' 29 | spec.add_dependency 'capistrano-file-permissions', '>= 1.0.0' 30 | 31 | spec.add_development_dependency 'bundler' 32 | spec.add_development_dependency 'rake', '>= 10.0.0' 33 | spec.add_development_dependency 'rspec' 34 | spec.add_development_dependency 'rubocop' 35 | end 36 | -------------------------------------------------------------------------------- /lib/capistrano/laravel.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'capistrano/composer' 4 | require 'capistrano/file-permissions' 5 | require 'capistrano/laravel/version' 6 | 7 | load File.expand_path('tasks/laravel.rake', __dir__) 8 | -------------------------------------------------------------------------------- /lib/capistrano/laravel/version.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module Capistrano 4 | module Laravel 5 | VERSION = '1.2.3' 6 | end 7 | end 8 | -------------------------------------------------------------------------------- /lib/capistrano/tasks/laravel.rake: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | # rubocop:disable Style/MixinUsage 4 | include Comparable 5 | # rubocop:enable Style/MixinUsage 6 | 7 | # rubocop:disable Metrics/BlockLength 8 | namespace :load do 9 | task :defaults do 10 | # Which roles to consider as laravel roles 11 | set :laravel_roles, :all 12 | 13 | # The artisan flags to include on artisan commands by default 14 | set :laravel_artisan_flags, "--env=#{fetch(:stage)}" 15 | 16 | # Which roles to use for running migrations 17 | set :laravel_migration_roles, :all 18 | 19 | # The artisan flags to include on commands when running migrations 20 | set :laravel_migration_artisan_flags, "--force --env=#{fetch(:stage)}" 21 | 22 | # The version of laravel being deployed 23 | set :laravel_version, 5.3 24 | 25 | # Whether to upload the dotenv file on deploy 26 | set :laravel_upload_dotenv_file_on_deploy, true 27 | 28 | # Which dotenv file to transfer to the server 29 | set :laravel_dotenv_file, '.env' 30 | 31 | # The user that the server is running under (used for ACLs) 32 | set :laravel_server_user, 'www-data' 33 | 34 | # Ensure the dirs in :linked_dirs exist? 35 | set :laravel_ensure_linked_dirs_exist, true 36 | 37 | # Link the directores in laravel_linked_dirs? 38 | set :laravel_set_linked_dirs, true 39 | 40 | # Linked directories for a standard Laravel 4 application 41 | set :laravel_4_linked_dirs, [ 42 | 'app/storage/public', 43 | 'app/storage/cache', 44 | 'app/storage/logs', 45 | 'app/storage/meta', 46 | 'app/storage/sessions', 47 | 'app/storage/views' 48 | ] 49 | 50 | # Linked directories for a standard Laravel 5 application 51 | set :laravel_5_linked_dirs, [ 52 | 'storage/app', 53 | 'storage/framework/cache', 54 | 'storage/framework/sessions', 55 | 'storage/framework/views', 56 | 'storage/logs' 57 | ] 58 | 59 | # Ensure the paths in :file_permissions_paths exist? 60 | set :laravel_ensure_acl_paths_exist, true 61 | 62 | # Set ACLs for the paths in laravel_acl_paths? 63 | set :laravel_set_acl_paths, true 64 | 65 | # Paths that should have ACLs set for a standard Laravel 4 application 66 | set :laravel_4_acl_paths, [ 67 | 'app/storage', 68 | 'app/storage/public', 69 | 'app/storage/cache', 70 | 'app/storage/logs', 71 | 'app/storage/meta', 72 | 'app/storage/sessions', 73 | 'app/storage/views' 74 | ] 75 | 76 | # Paths that should have ACLs set for a standard Laravel 5 application 77 | set :laravel_5_acl_paths, [ 78 | 'bootstrap/cache', 79 | 'storage', 80 | 'storage/app', 81 | 'storage/app/public', 82 | 'storage/framework', 83 | 'storage/framework/cache', 84 | 'storage/framework/sessions', 85 | 'storage/framework/views', 86 | 'storage/logs' 87 | ] 88 | end 89 | end 90 | # rubocop:enable Metrics/BlockLength 91 | 92 | # rubocop:disable Metrics/BlockLength 93 | namespace :laravel do 94 | desc 'Determine which folders, if any, to use for linked directories.' 95 | task :resolve_linked_dirs do 96 | laravel_version = fetch(:laravel_version) 97 | 98 | # Use Laravel 5 linked dirs by default 99 | laravel_linked_dirs = fetch(:laravel_5_linked_dirs) 100 | 101 | # Laravel 4 102 | laravel_linked_dirs = fetch(:laravel_4_linked_dirs) if laravel_version < 5 103 | 104 | if fetch(:laravel_set_linked_dirs) 105 | set :linked_dirs, fetch(:linked_dirs, []).push(*laravel_linked_dirs) 106 | end 107 | end 108 | 109 | desc 'Determine which paths, if any, to have ACL permissions set.' 110 | task :resolve_acl_paths do 111 | next unless fetch(:laravel_set_acl_paths) 112 | 113 | laravel_version = fetch(:laravel_version) 114 | 115 | # Use Laravel 5 ACL paths by default 116 | laravel_acl_paths = fetch(:laravel_5_acl_paths) 117 | 118 | # Laravel 4 119 | laravel_acl_paths = fetch(:laravel_4_acl_paths) if laravel_version < 5 120 | 121 | set :file_permissions_paths, fetch(:file_permissions_paths, []) 122 | .push(*laravel_acl_paths) 123 | .uniq 124 | set :file_permissions_users, fetch(:file_permissions_users, []) 125 | .push(fetch(:laravel_server_user)) 126 | .uniq 127 | end 128 | 129 | desc 'Ensure that linked dirs exist.' 130 | task :ensure_linked_dirs_exist do 131 | next unless fetch(:laravel_ensure_linked_dirs_exist) 132 | 133 | on roles fetch(:laravel_roles) do 134 | fetch(:linked_dirs).each do |path| 135 | within shared_path do 136 | execute :mkdir, '-p', path 137 | end 138 | end 139 | end 140 | end 141 | 142 | desc 'Ensure that ACL paths exist.' 143 | task :ensure_acl_paths_exist do 144 | next unless fetch(:laravel_set_acl_paths) && 145 | fetch(:laravel_ensure_acl_paths_exist) 146 | 147 | on roles fetch(:laravel_roles) do 148 | fetch(:file_permissions_paths).each do |path| 149 | within release_path do 150 | execute :mkdir, '-p', path 151 | end 152 | end 153 | end 154 | end 155 | 156 | desc 'Upload dotenv file for release.' 157 | task :upload_dotenv_file do 158 | next unless fetch(:laravel_upload_dotenv_file_on_deploy) 159 | 160 | # Dotenv was introduced in Laravel 5 161 | next if fetch(:laravel_version) < 5 162 | 163 | dotenv_file = fetch(:laravel_dotenv_file) 164 | 165 | run_locally do 166 | if dotenv_file.empty? || test("[ ! -e #{dotenv_file} ]") 167 | raise Capistrano::ValidationError, 168 | "Must prepare dotenv file [#{dotenv_file}] locally before deploy!" 169 | end 170 | end 171 | 172 | on roles fetch(:laravel_roles) do 173 | upload! dotenv_file, "#{release_path}/.env" 174 | end 175 | end 176 | 177 | desc 'Execute a provided artisan command.' 178 | task :artisan, [:command_name] do |_t, args| 179 | ask(:cmd, 'list') # Ask only runs if argument is not provided 180 | command = args[:command_name] || fetch(:cmd) 181 | 182 | on roles fetch(:laravel_roles) do 183 | within release_path do 184 | execute :php, 185 | :artisan, 186 | command, 187 | *args.extras, 188 | fetch(:laravel_artisan_flags) 189 | end 190 | end 191 | 192 | # Enable task artisan to be ran more than once 193 | Rake::Task['laravel:artisan'].reenable 194 | end 195 | 196 | desc 'Create a cache file for faster configuration loading.' 197 | task :config_cache do 198 | next if fetch(:laravel_version) < 5 199 | 200 | Rake::Task['laravel:artisan'].invoke('config:cache') 201 | end 202 | 203 | desc 'Create a route cache file for faster route registration.' 204 | task :route_cache do 205 | next if fetch(:laravel_version) < 5 206 | 207 | Rake::Task['laravel:artisan'].invoke('route:cache') 208 | end 209 | 210 | desc 'Optimize the framework for better performance.' 211 | task :optimize do 212 | next if fetch(:laravel_version) >= 5.5 213 | 214 | Rake::Task['laravel:artisan'].invoke(:optimize, '--force') 215 | end 216 | 217 | desc 'Create a symbolic link from "public/storage" to "storage/app/public."' 218 | task :storage_link do 219 | next if fetch(:laravel_version) < 5.3 220 | 221 | Rake::Task['laravel:artisan'].invoke('storage:link') 222 | end 223 | 224 | desc 'Run the database migrations.' 225 | task :migrate do 226 | laravel_roles = fetch(:laravel_roles) 227 | laravel_artisan_flags = fetch(:laravel_artisan_flags) 228 | 229 | set(:laravel_roles, fetch(:laravel_migration_roles)) 230 | set(:laravel_artisan_flags, fetch(:laravel_migration_artisan_flags)) 231 | 232 | Rake::Task['laravel:artisan'].invoke(:migrate) 233 | 234 | set(:laravel_roles, laravel_roles) 235 | set(:laravel_artisan_flags, laravel_artisan_flags) 236 | end 237 | 238 | desc 'Rollback the last database migration.' 239 | task :migrate_rollback do 240 | laravel_roles = fetch(:laravel_roles) 241 | laravel_artisan_flags = fetch(:laravel_artisan_flags) 242 | 243 | set(:laravel_roles, fetch(:laravel_migration_roles)) 244 | set(:laravel_artisan_flags, fetch(:laravel_migration_artisan_flags)) 245 | 246 | Rake::Task['laravel:artisan'].invoke('migrate:rollback') 247 | 248 | set(:laravel_roles, laravel_roles) 249 | set(:laravel_artisan_flags, laravel_artisan_flags) 250 | end 251 | 252 | before 'deploy:starting', 'laravel:resolve_linked_dirs' 253 | before 'deploy:starting', 'laravel:resolve_acl_paths' 254 | after 'deploy:starting', 'laravel:ensure_linked_dirs_exist' 255 | after 'deploy:updating', 'laravel:ensure_acl_paths_exist' 256 | before 'deploy:updated', 'deploy:set_permissions:acl' 257 | before 'deploy:updated', 'laravel:upload_dotenv_file' 258 | after 'composer:run', 'laravel:storage_link' 259 | after 'composer:run', 'laravel:optimize' 260 | end 261 | # rubocop:enable Metrics/BlockLength 262 | -------------------------------------------------------------------------------- /lib/capistrano_laravel.rb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/capistrano/laravel/0e7f2aadb2cbc449b0623056d0f6840403017aec/lib/capistrano_laravel.rb -------------------------------------------------------------------------------- /spec/capistrano/laravel_spec.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'spec_helper' 4 | 5 | describe Capistrano::Laravel do 6 | it 'has a version number' do 7 | expect(Capistrano::Laravel::VERSION).not_to be nil 8 | end 9 | end 10 | -------------------------------------------------------------------------------- /spec/spec_helper.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'bundler/setup' 4 | require 'capistrano/all' 5 | require 'capistrano/framework' 6 | require 'capistrano/laravel' 7 | 8 | RSpec.configure do |config| 9 | # Enable flags like --only-failures and --next-failure 10 | config.example_status_persistence_file_path = '.rspec_status' 11 | 12 | config.expect_with :rspec do |c| 13 | c.syntax = :expect 14 | end 15 | end 16 | --------------------------------------------------------------------------------