Permalink
Browse files

Major refactoring of tasks to clean up code.

- Renamed Artisan tasks to match the same name as their command in artisan.
- Refactored some tasks into multiple tasks to clean up logic (needs additional refactoring to remove duplicate code).
- Renamed some properties to make it clearer what they’re for.
- Added new tasks to match current Laravel’s deploy methods.
- Removed unused Helper file.
- Added test files, but still need to write tests.
  • Loading branch information...
1 parent 003041f commit bd066bfe8005e3c03fcc0cc3845de425da3282e0 @ikari7789 ikari7789 committed Oct 12, 2016
Showing with 355 additions and 186 deletions.
  1. +18 −0 .editorconfig
  2. +9 −1 .gitignore
  3. +2 −0 .rspec
  4. +5 −0 .travis.yml
  5. +1 −1 Gemfile
  6. +15 −14 LICENSE
  7. +107 −55 README.md
  8. +6 −1 Rakefile
  9. +14 −0 bin/console
  10. +8 −0 bin/setup
  11. +19 −14 capistrano-laravel.gemspec
  12. +1 −0 lib/capistrano/laravel.rb
  13. +0 −6 lib/capistrano/laravel/helpers.rb
  14. +141 −94 lib/capistrano/tasks/laravel.rake
  15. +7 −0 spec/capistrano/laravel_spec.rb
  16. +2 −0 spec/spec_helper.rb
View
@@ -0,0 +1,18 @@
+root = true
+
+[*]
+indent_style = space
+indent_size = 4
+end_of_line = lf
+charset = utf-8
+trim_trailing_whitespace = true
+insert_final_newline = true
+
+[*.md]
+trim_trailing_whitespace = false
+
+[*.rake]
+indent_size = 2
+
+[*.rb]
+indent_size = 2
View
@@ -1 +1,9 @@
-*.gem
+/.bundle/
+/.yardoc
+/Gemfile.lock
+/_yardoc/
+/coverage/
+/doc/
+/pkg/
+/spec/reports/
+/tmp/
View
@@ -0,0 +1,2 @@
+--format documentation
+--color
View
@@ -0,0 +1,5 @@
+sudo: false
+language: ruby
+rvm:
+ - 2.3.1
+before_install: gem install bundler -v 1.13.2
View
@@ -1,4 +1,4 @@
source 'https://rubygems.org'
-# Specify your gem's dependencies in capistrano-bundler.gemspec
+# Specify your gem's dependencies in capistrano-laravel.gemspec
gemspec
View
@@ -1,20 +1,21 @@
The MIT License (MIT)
-Copyright (c) 2013 Peter Mitchell (peterjmit@gmail.com)
+Copyright (c) 2016 Peter Mitchell (peterjmit@gmail.com)
-Permission is hereby granted, free of charge, to any person obtaining a copy of
-this software and associated documentation files (the "Software"), to deal in
-the Software without restriction, including without limitation the rights to
-use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
-the Software, and to permit persons to whom the Software is furnished to do so,
-subject to the following conditions:
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
-The above copyright notice and this permission notice shall be included in all
-copies or substantial portions of the Software.
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
-FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
-COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
-IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
-CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
View
@@ -1,11 +1,10 @@
-# Capistrano::laravel
+# Capistrano::Laravel
Deploy Laravel applications with Capistrano v3.*
## Installation
-If managing your Capistrano deploy as a ruby project,
-add the following to your gemfile:
+If managing your Capistrano deploy as a ruby project, add this line to your application's Gemfile:
```ruby
gem 'capistrano', '~> 3.0.0'
@@ -18,18 +17,15 @@ And then execute:
bundle
```
-If just managing ruby gems on their own on a deploy server,
-execute the following to ensure all gems are installed
+Or install it yourself as:
```shell
-gem install capistrano
gem install capistrano-laravel
```
## Setting up Capistrano
-After installing Capistrano, you can use it to initialize a skeleton configuration.
-To setup Capistrano, please follow the documentation provided on their website:
+After installing Capistrano, you can use it to initialize a skeleton configuration. To setup Capistrano, please follow the documentation provided on their website:
http://capistranorb.com/documentation/getting-started/preparing-your-application/
@@ -61,84 +57,140 @@ require 'capistrano/laravel'
The gem makes the following configuration variables available (shown with defaults).
```ruby
-# Which roles to execute commands on.
+# Which roles to consider as laravel roles
set :laravel_roles, :all
-# Which roles to use for execute migrations
-set :laravel_migrate_roels, :all
+# The artisan flags to include on artisan commands by default
+set :laravel_artisan_flags, "--env=#{fetch(:stage)}"
-# Determines which operations to perform based on which version
-# of the Laravel framework your project is using.
-set :laravel_version, 5.1
+# Which roles to use for running migrations
+set :laravel_migration_roles, :all
-# If using Laravel 5+, a dotenv file is used for environment configuration.
-# This variable uploads the given file from the the host to the guest.
+# The artisan flags to include on artisan commands by default when running migrations
+set :laravel_migration_artisan_flags, "--force --env=#{fetch(:stage)}"
+
+# The version of laravel being deployed
+set :laravel_version, 5.3
+
+# Which dotenv file to transfer to the server
set :laravel_dotenv_file, './.env'
-# Flags to add to artisan calls.
-set :laravel_artisan_flags, "--env=production"
+# The user that the server is running under (used for ACLs)
+set :laravel_server_user, 'www-data'
-# Will set linked folders based on your Laravel version
+# Ensure the dirs in :linked_dirs exist?
+set :laravel_ensure_linked_dirs_exist, true
+
+# Link the directores in laravel_linked_dirs?
set :laravel_set_linked_dirs, true
-# Will set ACL paths based on your Laravel version
-set :laravel_set_acl_paths, true
+# Linked directories for a standard Laravel 4 application
+set :laravel_4_linked_dirs, [
+ 'app/storage'
+]
-# Make any missing shared folders if they don't exist
-set :laravel_create_linked_acl_paths, true
+# Linked directories for a standard Laravel 5 application
+set :laravel_5_linked_dirs, [
+ 'storage'
+]
-# Which user to set ACL permissions for.
-set :laravel_server_user, "www-data"
+# Ensure the paths in :file_permissions_paths exist?
+set :laravel_ensure_acl_paths_exist, true
+
+# Set ACLs for the paths in laravel_acl_paths?
+set :laravel_set_acl_paths, true
+
+# Paths that should have ACLs set for a standard Laravel 4 application
+set :laravel_4_acl_paths, [
+ 'app/storage',
+ 'app/storage/public',
+ 'app/storage/cache',
+ 'app/storage/logs',
+ 'app/storage/meta',
+ 'app/storage/sessions',
+ 'app/storage/views'
+]
+
+# Paths that should have ACLs set for a standard Laravel 5 application
+set :laravel_5_acl_paths, [
+ 'bootstrap/cache',
+ 'storage',
+ 'storage/app',
+ 'storage/app/public',
+ 'storage/framework',
+ 'storage/framework/cache',
+ 'storage/framework/sessions',
+ 'storage/framework/views',
+ 'storage/logs'
+]
```
### Tasks
-The following tasks are added to your deploy automagically when
-adding capistrano/laravel to your deploy.
+The following tasks are added to your deploy automagically when adding capistrano/laravel to your deploy.
```ruby
-before 'deploy:starting', 'laravel:configure_folders'
-after 'deploy:symlink:shared', 'laravel:create_linked_acl_paths'
-after 'deploy:symlink:shared', 'deploy:set_permissions:acl'
-after 'deploy:symlink:shared', 'laravel:upload_dotenv_file'
-before 'deploy:updated', 'laravel:optimize_release'
+before 'deploy:starting', 'laravel:resolve_linked_dirs'
+before 'deploy:starting', 'laravel:resolve_acl_paths'
+after 'deploy:starting', 'laravel:ensure_linked_dirs_exist'
+after 'deploy:starting', 'laravel:ensure_acl_paths_exist'
+after 'deploy:updating', 'deploy:set_permissions:acl'
+before 'composer:run', 'laravel:upload_dotenv_file'
+after 'composer:run', 'laravel:storage_link'
+after 'composer:run', 'laravel:optimize'
```
#### Task Descriptions
```ruby
-# Configure linked dirs/acl dirs
-invoke "laravel:configure_folders"
+# Determine which folders, if any, to use for linked directories.
+invoke 'laravel:resolve_linked_dirs'
+
+# Determine which paths, if any, to have ACL permissions set.
+invoke 'laravel:resolve_acl_paths'
-# Create any missing folders for ACL
-invoke "laravel:create_linked_acl_paths"
+# Ensure that linked dirs exist.
+invoke 'laravel:ensure_linked_dirs_exist'
-# Upload the dotenv file from local to remote
-invoke "laravel:upload_dotenv_file"
+# Ensure that ACL paths exist.
+invoke 'laravel:ensure_acl_paths_exist'
-# Execute an artisan command
-invoke "laravel:artisan", "command"
+# Upload dotenv file for release.
+invoke 'laravel:upload_dotenv_file'
-# Run `artisan config:cache` to optimize the configuration
-invoke "laravel:optimize_config"
+# Execute a provided artisan command.
+# Replace :command_name with the command to execute
+invoke 'laravel:artisan[:command_name]'
-# Run `artisan route:cache` to optimize the routes files
-invoke "laravel:optimize_route"
+# Create a cache file for faster configuration loading
+invoke 'laravel:config_cache'
-# Run `artisan optimize` to optimize the framework
-invoke "laravel:optimize_release"
+# Create a route cache file for faster route registration
+invoke 'laravel:route_cache'
-# Run migrations for the database
-invoke "laravel:migrate_db"
+# Optimize the framework for better performance.
+invoke 'laravel:optimize'
-# Rollback the database migration
-invoke "laravel:rollback_db"
+# Create a symbolic link from "public/storage" to "storage/app/public"
+invoke 'laravel:storage_link'
+
+# Run the database migrations.
+invoke 'laravel:migrate'
+
+# Rollback the last database migration.
+invoke 'laravel:migrate_rollback'
```
+## Development
+
+After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
+
+To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
+
## Contributing
-1. Fork it
-2. Create your feature branch (`git checkout -b my-new-feature`)
-3. Commit your changes (`git commit -am 'Add some feature'`)
-4. Push to the branch (`git push origin my-new-feature`)
-5. Create new Pull Request
+Bug reports and pull requests are welcome on GitHub at https://github.com/capistrano/laravel.
+
+## License
+
+The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
View
@@ -1 +1,6 @@
-require 'bundler/gem_tasks'
+require "bundler/gem_tasks"
+require "rspec/core/rake_task"
+
+RSpec::Core::RakeTask.new(:spec)
+
+task :default => :spec
View
@@ -0,0 +1,14 @@
+#!/usr/bin/env ruby
+
+require "bundler/setup"
+require "capistrano/laravel"
+
+# You can add fixtures and/or initialization code here to make experimenting
+# with your gem easier. You can also use a different console, if you like.
+
+# (If you use this, don't forget to add pry to your Gemfile!)
+# require "pry"
+# Pry.start
+
+require "irb"
+IRB.start
View
@@ -0,0 +1,8 @@
+#!/usr/bin/env bash
+set -euo pipefail
+IFS=$'\n\t'
+set -vx
+
+bundle install
+
+# Do any other automated setup that you need to do here
@@ -1,26 +1,31 @@
# coding: utf-8
lib = File.expand_path('../lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
+require 'capistrano/laravel/version'
Gem::Specification.new do |spec|
- spec.name = 'capistrano-laravel'
- spec.version = '0.0.4'
- spec.authors = ['Peter Mitchell', 'Andrew Miller']
- spec.email = ['peterjmit@gmail.com', 'ikari7789@yahoo.com']
- spec.description = %q{Laravel specific deployment options for Capistrano 3.x}
- spec.summary = %q{Laravel deployment for Capistrano 3.x}
- spec.homepage = 'https://github.com/capistrano/laravel'
- spec.license = 'MIT'
+ spec.name = "capistrano-laravel"
+ spec.version = Capistrano::Laravel::VERSION
+ spec.authors = ["Peter Mitchell", "Andrew Miller"]
+ spec.email = ["peterjmit@gmail.com", "ikari7789@yahoo.com"]
- spec.files = `git ls-files`.split($/)
- spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
- spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
- spec.require_paths = ['lib']
+ spec.summary = %q{Laravel specific deployment options for Capistrano 3.x}
+ spec.description = %q{Laravel deployment for Capistrano 3.x}
+ spec.homepage = "https://github.com/capistrano/laravel"
+ spec.license = "MIT"
+
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
+ f.match(%r{^(test|spec|features)/})
+ end
+ spec.bindir = "exe"
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
+ spec.require_paths = ["lib"]
spec.add_dependency 'capistrano', '~> 3.0'
spec.add_dependency 'capistrano-composer', '~> 0.0.6'
spec.add_dependency 'capistrano-file-permissions', '~> 1.0'
- spec.add_development_dependency 'bundler', '~> 1.3'
- spec.add_development_dependency 'rake', '~> 10.4'
+ spec.add_development_dependency "bundler", "~> 1.13"
+ spec.add_development_dependency "rake", "~> 10.0"
+ spec.add_development_dependency "rspec", "~> 3.0"
end
@@ -1,4 +1,5 @@
require "capistrano/composer"
require "capistrano/file-permissions"
+require "capistrano/laravel/version"
load File.expand_path("../tasks/laravel.rake", __FILE__)
@@ -1,6 +0,0 @@
-module Capistrano
- module Laravel
- module Helpers
- end
- end
-end
Oops, something went wrong.

0 comments on commit bd066bf

Please sign in to comment.