capistrano-faster-rails 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 267f8d4165d2dfd5a34f51ee33ab376057ee609b8ea3d18db05b4138a657b078
4
+ data.tar.gz: 0267eb20da80f65880cce0189cae1e7fb0df4a1192f307558091e944cc78e6a4
5
+ SHA512:
6
+ metadata.gz: be5dca1f91d6a8df868d167b37f9dc899920e2c90b8682a92ef3d67177d912528780827fdfb5ab2a408e597f172173a98adf90d42d68b5b44a40d98332faa383
7
+ data.tar.gz: 780b849843a81098dad49205f4986fd9921eafd17699da96aa2a07bbc28c2cc095af4277e2bebc6f229a585514ea044b1fc5a623a5d0cfd24d1994b686dfcb54
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ Gemfile.lock
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in capistrano-faster-rails.gemspec
6
+ gemspec
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2005-2019 David Heinemeier Hansson
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,54 @@
1
+ # Welcome to use `capistrano-faster-rails`!
2
+
3
+ ## What does this gem do?
4
+
5
+ 1. Execute copy `linked_files` and `linked_dirs` with one command on deployed servers.
6
+
7
+ Capistrano runs each command separately on their own SSH session and it takes too long to deploy an application, copy `linked_files` and `linked_dirs` on deployed servers with one command will speedup deploying process.
8
+
9
+ 2. Skip `bundle install` if Gemfile isn't changed.
10
+
11
+ `bundle install` takes few or dozens of seconds, most of the time your project's Gemfile will not be changed, and you don't have to execute `bundle install` if your Gemfile isn't changed.
12
+
13
+ 3. Skip `rake assets:precompile` if asset files not chagned.
14
+
15
+ `rake assets:precompile` is really slow if your Rails project has plenty of assets to precompile, even if they are not changed. You don't have to execute `rake assets:precompile` if your asset files not chagned.
16
+
17
+
18
+ ## Installation
19
+
20
+ Add this line to your Rails application's Gemfile and below to `gem 'capistrano-rails'`:
21
+
22
+ ```ruby
23
+ # Gemfile
24
+ gem 'capistrano-faster-rails'
25
+ ```
26
+
27
+ And then execute:
28
+
29
+ $ bundle
30
+
31
+ ## Usage
32
+
33
+ Add this line to your Rails application's Capfile and below to `require 'capistrano/rails'`:
34
+
35
+ ```ruby
36
+ # Capfile
37
+ require 'capistrano/faster-rails'
38
+ ```
39
+
40
+ use `set :asset_files` in config/deploy.rb to set your project assets files, `asset_files` default to `"vendor/assets app/assets config/initializers/assets.rb"`
41
+
42
+ use `set :bundle_files` in config/deploy.rb to set your project ruby Gemfile files, `bundle_files` default to `"Gemfile Gemfile.lock .ruby-version"`
43
+
44
+ Causion:
45
+
46
+ `asset_files` and `bundle_files` are both space separated string, not array!
47
+
48
+ this gem only works with `git` scm!
49
+
50
+
51
+
52
+ ## Contributing
53
+
54
+ Bug reports and pull requests are welcome on GitHub at https://github.com/ifool/capistrano-faster-rails.
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "capistrano/faster/rails"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
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
@@ -0,0 +1,44 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "capistrano-faster-rails"
7
+ spec.version = "1.0.0"
8
+ spec.authors = ["lifuzhong"]
9
+ spec.email = ["lifuzho@126.com"]
10
+
11
+ spec.summary = %q{Speedup deploy Ruby On Rails project when using capistrano}
12
+ spec.description = %q{
13
+ 1. Capistrano runs each command separately on their own SSH session and that's why it takes so long to deploy an application, copy `linked_files` and `linked_dirs` with one command will speedup deploying process.
14
+ 2. `bundle install` takes few or dozens of seconds. generally, you don't have to execute `bundle install` if your Gemfile and Gemfile.lock not changed
15
+ 3. `rake assets:precompile` is really slow if your Rails project has plenty of assets to precompile, even if they are not changed. You don't have to precompile them if not chagned.
16
+ }
17
+ spec.homepage = "https://github.com/ifool/capistrano-faster-rails"
18
+ spec.license = 'MIT'
19
+
20
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
21
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
22
+ if spec.respond_to?(:metadata)
23
+ # spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
24
+
25
+ spec.metadata["homepage_uri"] = spec.homepage
26
+ spec.metadata["source_code_uri"] = "https://github.com/ifool/capistrano-faster-rails"
27
+ spec.metadata["changelog_uri"] = "https://github.com/ifool/capistrano-faster-rails"
28
+ else
29
+ raise "RubyGems 2.0 or newer is required to protect against " \
30
+ "public gem pushes."
31
+ end
32
+
33
+ # Specify which files should be added to the gem when it is released.
34
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
35
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
36
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
37
+ end
38
+ spec.bindir = "exe"
39
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
40
+ spec.require_paths = ["lib"]
41
+
42
+ spec.add_development_dependency "bundler", "~> 1.17"
43
+ spec.add_development_dependency "rake", "~> 10.0"
44
+ end
File without changes
@@ -0,0 +1 @@
1
+ load File.expand_path("../tasks/faster-rails.rake", __FILE__)
@@ -0,0 +1,91 @@
1
+ namespace :deploy do
2
+ namespace :symlink do
3
+ Rake::Task["deploy:symlink:linked_files"].clear_actions
4
+ task :linked_files do
5
+ next unless any? :linked_files
6
+ on release_roles :all do
7
+ link_cmd = "mkdir -p #{linked_file_dirs(release_path).join(' ')}\n"
8
+ link_cmd << fetch(:linked_files).map { |file|
9
+ source_file = shared_path.join(file).to_s.ljust(40, ' ')
10
+ "ln -sf #{source_file} #{release_path.join(file)}"
11
+ }.join("\n")
12
+ execute(link_cmd.tap { |s| puts s })
13
+ end
14
+ end
15
+
16
+ Rake::Task["deploy:symlink:linked_dirs"].clear_actions
17
+ task :linked_dirs do
18
+ next unless any? :linked_dirs
19
+ on release_roles :all do
20
+ link_cmd = "mkdir -p #{linked_dir_parents(release_path).join(' ')}\n"
21
+ link_cmd << "cd #{release_path} && rm -rf #{fetch(:linked_dirs).join(' ')}\n"
22
+ link_cmd << fetch(:linked_dirs).map { |dir_name|
23
+ source_dir = shared_path.join(dir_name).to_s.ljust(40, ' ')
24
+ "ln -sf #{source_dir} #{release_path.join(dir_name)}"
25
+ }.join("\n")
26
+ execute(link_cmd.tap { |s| puts s })
27
+ end
28
+ end
29
+ end
30
+
31
+ namespace :assets do
32
+ Rake::Task["deploy:assets:precompile"].clear_actions
33
+ task :precompile do
34
+ on(release_roles(fetch(:assets_roles))) {
35
+ log "[deploy:assets:precompile] Checking assets changes"
36
+ asset_files = fetch(:asset_files, "vendor/assets app/assets config/initializers/assets.rb")
37
+ asset_changed = within(repo_path) {
38
+ previous_revision, current_revision = fetch(:previous_revision), fetch(:current_revision)
39
+ previous_revision.to_s.empty? ||
40
+ !capture("cd #{repo_path} && git diff --name-only #{previous_revision} #{current_revision} -- #{asset_files}").empty?
41
+ }
42
+
43
+ if asset_changed
44
+ within(release_path) do
45
+ with rails_env: fetch(:rails_env), rails_groups: fetch(:rails_assets_groups) do
46
+ execute :rake, "assets:precompile"
47
+ end
48
+ end
49
+ else
50
+ log "[deploy:assets:precompile] Skip `deploy:assets:precompile` (assets not changed)"
51
+ end
52
+ }
53
+ end
54
+ end
55
+ end
56
+
57
+ namespace :bundler do
58
+ desc 'Install the current Bundler environment.'
59
+ Rake::Task["bundler:install"].clear_actions
60
+ task :install do
61
+ on fetch(:bundle_servers) do
62
+ log "[bundler:install] Checking Gemfile and Gemfile.lock changes"
63
+ bundle_files = fetch(:bundle_files, "Gemfile Gemfile.lock .ruby-version")
64
+ gemfile_changed = within(repo_path) {
65
+ previous_revision, current_revision = fetch(:previous_revision), fetch(:current_revision)
66
+ previous_revision.to_s.empty? ||
67
+ !capture("cd #{repo_path} && git diff --name-only #{previous_revision} #{current_revision} -- #{bundle_files}").empty?
68
+ }
69
+
70
+ within release_path do
71
+ with fetch(:bundle_env_variables) do
72
+ options = []
73
+ options << "--gemfile #{fetch(:bundle_gemfile)}" if fetch(:bundle_gemfile)
74
+ options << "--path #{fetch(:bundle_path)}" if fetch(:bundle_path)
75
+ unless test(:bundle, :check, *options)
76
+ options << "--binstubs #{fetch(:bundle_binstubs)}" if fetch(:bundle_binstubs)
77
+ options << "--jobs #{fetch(:bundle_jobs)}" if fetch(:bundle_jobs)
78
+ options << "--without #{fetch(:bundle_without)}" if fetch(:bundle_without)
79
+ options << "#{fetch(:bundle_flags)}" if fetch(:bundle_flags)
80
+ if gemfile_changed
81
+ execute :bundle, :install, *options
82
+ else
83
+ log "[bundler:install] Skip `bundle install` (Gemfile and Gemfile.lock not changed)"
84
+ execute :echo, %Q['BUNDLE_FROZEN: "true"\nBUNDLE_WITHOUT: "development:test"'], '>>', '.bundle/config'
85
+ end
86
+ end
87
+ end
88
+ end
89
+ end
90
+ end
91
+ end
metadata ADDED
@@ -0,0 +1,91 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: capistrano-faster-rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - lifuzhong
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-11-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.17'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.17'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ description: "\n 1. Capistrano runs each command separately on their own SSH session
42
+ and that's why it takes so long to deploy an application, copy `linked_files` and
43
+ `linked_dirs` with one command will speedup deploying process.\n 2. `bundle install`
44
+ takes few or dozens of seconds. generally, you don't have to execute `bundle install`
45
+ if your Gemfile and Gemfile.lock not changed\n 3. `rake assets:precompile` is
46
+ really slow if your Rails project has plenty of assets to precompile, even if they
47
+ are not changed. You don't have to precompile them if not chagned.\n "
48
+ email:
49
+ - lifuzho@126.com
50
+ executables: []
51
+ extensions: []
52
+ extra_rdoc_files: []
53
+ files:
54
+ - ".gitignore"
55
+ - Gemfile
56
+ - LICENSE.txt
57
+ - README.md
58
+ - Rakefile
59
+ - bin/console
60
+ - bin/setup
61
+ - capistrano-faster-rails.gemspec
62
+ - lib/capistrano-faster-rails.rb
63
+ - lib/capistrano/faster-rails.rb
64
+ - lib/capistrano/tasks/faster-rails.rake
65
+ homepage: https://github.com/ifool/capistrano-faster-rails
66
+ licenses:
67
+ - MIT
68
+ metadata:
69
+ homepage_uri: https://github.com/ifool/capistrano-faster-rails
70
+ source_code_uri: https://github.com/ifool/capistrano-faster-rails
71
+ changelog_uri: https://github.com/ifool/capistrano-faster-rails
72
+ post_install_message:
73
+ rdoc_options: []
74
+ require_paths:
75
+ - lib
76
+ required_ruby_version: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ required_rubygems_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ requirements: []
87
+ rubygems_version: 3.0.3
88
+ signing_key:
89
+ specification_version: 4
90
+ summary: Speedup deploy Ruby On Rails project when using capistrano
91
+ test_files: []