new_artrails_capistrano 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7c5bb956afc61ebd6675c6419c7d978428cc19e5
4
- data.tar.gz: fc0057e1a2753f5e2db51e13c7ead3eb1b93d87f
3
+ metadata.gz: ded6859a7399bb2d6abd70b14b594c8b4b82832c
4
+ data.tar.gz: 1207eae9f16cbdf08ad40834abdd04bdcd440b14
5
5
  SHA512:
6
- metadata.gz: 341931b41e89b4e884ad8d30f6d53389d33e1b5e1ba0a609775ee63bc0107fdd0443622fdb7c2b0327e979620ec101d02ac295aa1130e75adb63acaaef90b4a6
7
- data.tar.gz: ddc2588682b90c1cfce442ce7a242b62421f02404c989a9dce8bf03dbe90bf845364604fd6cf167444054568eeb667e3a0c922f7e7dbf32fe0342f22b0b17b3f
6
+ metadata.gz: 51e5e6096b9d80372df93bc90a8c59626444b929785b36736b540e1151207e8ff09f67a45b5e55c0a7b001062eee7e3ec420eac2c210e02c1d4ac346c42570e4
7
+ data.tar.gz: 161d583d914c7a1f853a985dab1aa8bd34b270a0ba73f9ca59d33d5708d659fb2a7cc7ddcb4a4998c6f4db3ee12d2d84eee8ddce45ed8cb4156ddb00a7613eec
@@ -1,6 +1,5 @@
1
1
  .codeclimate.yml
2
2
  .gitignore
3
- .rspec_status
4
3
  .rubocop.yml
5
4
  .rubocop_todo.yml
6
5
  .travis.yml
@@ -17,6 +16,8 @@ bin/setup
17
16
  config.reek
18
17
  lib/.keep
19
18
  lib/capistrano/new_artrails_capistrano.rb
19
+ lib/capistrano/new_artrails_capistrano/front_helpers.rb
20
+ lib/capistrano/new_artrails_capistrano/helpers.rb
20
21
  lib/capistrano/new_artrails_capistrano/version.rb
21
22
  lib/capistrano/tasks/new_artrails_capistrano.rake
22
23
  lib/new_artrails_capistrano.rb
@@ -0,0 +1,115 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Capistrano
4
+ module NewArtrailsCapistrano
5
+ module FrontHelpers
6
+
7
+ def front_branch
8
+ fetch(:front_branch) || 'master'
9
+ end
10
+
11
+ def front_rsync_remote_cache
12
+ fetch(:front_remote_cache) || "shared/front-cached-copy-#{fetch(:local_user) || 'deploy'}"
13
+ end
14
+
15
+ def front_local_cache
16
+ front_application = fetch(:front_application)
17
+ # "-#{fetch(:stage)}"
18
+ fetch(:front_local_cache) || "/tmp/.#{front_application}_rsync_cache"
19
+ end
20
+
21
+ def front_rsync_credentials
22
+ fetch(:local_user)
23
+ end
24
+
25
+ def front_dist_dir_name
26
+ fetch(:front_dist_dir_name) || 'dist'
27
+ end
28
+
29
+ def front_rsync_options
30
+ fetch(:front_rsync_options) || fetch(:rsync_options)
31
+ end
32
+
33
+ def front_rsync_include
34
+ fetch(:front_rsync_include) || fetch(:rsync_include)
35
+ end
36
+
37
+ def front_rsync_exclude
38
+ fetch(:front_rsync_exclude) || fetch(:rsync_exclude)
39
+ end
40
+
41
+ # do not delete Rails' Apache served folders
42
+ def front_copy_command
43
+ assets_prefix = fetch(:assets_prefix) || 'assets'
44
+ keeps = fetch(:backend_dirs_or_files_to_keep_in_public) || ([assets_prefix] + %w[ images system upload download])
45
+ if keeps.empty?
46
+ keep_string = ''
47
+ else
48
+ keep_string = ' ' + keeps.map { |keep| "--exclude=\'#{keep}\'" }.join(' ').to_s
49
+ end
50
+ "rsync -a --no-p --no-g --delete#{keep_string}"
51
+ end
52
+
53
+ def front_revision
54
+ @front_revision ||= `git ls-remote #{fetch(:front_repo_url)} #{front_branch}`.split("\t").first
55
+ end
56
+
57
+ def front_release_path
58
+ File.join(release_path, 'public')
59
+ end
60
+
61
+ def front_install_command
62
+ fetch(:front_install_command) ||
63
+ <<-CMD
64
+ npm install &&
65
+ bower install &&
66
+ gulp clean &&
67
+ gulp build
68
+ CMD
69
+ end
70
+ def front_sync_command
71
+ fetch(:front_sync_command) ||
72
+ <<-CMD
73
+ cd #{front_local_cache} &&
74
+ git fetch #{fetch(:front_repo_url)} #{front_branch} &&
75
+ git fetch --tags #{fetch(:front_repo_url)} #{front_branch} &&
76
+ git reset --hard #{front_revision} &&
77
+ #{front_install_command}
78
+ CMD
79
+ end
80
+
81
+ def front_checkout_command
82
+ fetch(:front_checkout_command) ||
83
+ <<-CMD
84
+ git clone #{fetch(:front_repo_url)} #{front_local_cache} &&
85
+ cd #{front_local_cache} &&
86
+ git checkout -b deploy/#{front_branch} #{front_revision} &&
87
+ #{front_install_command}
88
+ CMD
89
+ end
90
+
91
+ def front_command
92
+ if (File.exists?(front_local_cache) && File.directory?(front_local_cache))
93
+ puts "[FRONT] updating front local cache to revision #{front_revision}"
94
+ cmd = front_sync_command
95
+ end
96
+ unless (File.exists?(front_local_cache) || File.directory?(front_local_cache))
97
+ puts "[FRONT] creating front local cache with revision #{front_revision}"
98
+ File.delete(front_local_cache) if File.exists?(front_local_cache)
99
+ Dir.mkdir(File.dirname(front_local_cache)) unless File.directory?(File.dirname(front_local_cache))
100
+
101
+ cmd = front_checkout_command
102
+ end
103
+ cmd.gsub("\n", '')
104
+ end
105
+
106
+ def front_remote_cache
107
+ lambda do
108
+ cache = front_rsync_remote_cache
109
+ cache = deploy_to + '/' + cache if cache && cache !~ /^\//
110
+ cache
111
+ end
112
+ end
113
+ end
114
+ end
115
+ end
@@ -0,0 +1,103 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Capistrano
4
+ module NewArtrailsCapistrano
5
+ module Helpers
6
+ def backend_branch
7
+ fetch(:branch) || 'master'
8
+ end
9
+
10
+ def backend_revision
11
+ @backend_revision ||= `git ls-remote #{fetch(:repo_url)} #{backend_branch}`.split("\t").first
12
+ end
13
+
14
+ def backend_local_cache
15
+ application = fetch(:application)
16
+ # "-#{fetch(:stage)}"
17
+ fetch(:local_cache) || "/tmp/.#{application}_rsync_cache"
18
+ end
19
+
20
+ def new_artrails_capistrano_sudo_as
21
+ "#{fetch(:new_artrails_capistrano_sudo_as)}" || 'deploy'
22
+ end
23
+
24
+ def file_exists?(path)
25
+ test "[ -e #{path} ]"
26
+ end
27
+
28
+ def dir_exists?(path)
29
+ test "[ -d #{path} ]"
30
+ end
31
+
32
+ def copy_command
33
+ "rsync -a --no-p --no-g --delete"
34
+ end
35
+
36
+ def rsync_remote_cache
37
+ fetch(:remote_cache) || "shared/cached-copy-#{fetch(:local_user) || 'deploy'}"
38
+ end
39
+
40
+ def new_artrails_capistrano_detect_manifest_path
41
+ %w(
42
+ .sprockets-manifest*
43
+ manifest*.*
44
+ ).each do |pattern|
45
+ candidate = release_path.join('public', fetch(:assets_prefix), pattern)
46
+ return capture(:ls, candidate).strip.gsub(/(\r|\n)/,' ') if test(:ls, candidate)
47
+ end
48
+ msg = 'Rails assets manifest file not found.'
49
+ warn msg
50
+ # Rails 5 only
51
+ # fail Capistrano::FileNotFound, msg
52
+ end
53
+
54
+ def new_artrails_capistrano_run_with_rvm_in_release_path(cmd, options={}, &block)
55
+ joined_cmd =<<-CMD
56
+ sudo -iu #{fetch(:new_artrails_capistrano_sudo_as)} sh -c "
57
+ source\\\\ '/usr/local/rvm/scripts/rvm' &&
58
+ cd #{fetch(:release_path)} &&
59
+ RAILS_ENV=#{fetch(:rails_env)} #{cmd}
60
+ "
61
+ CMD
62
+ new_artrails_capistrano_run(joined_cmd.gsub(/\r?\n/, '').gsub(/\s+/, ' '), options) do
63
+ block.call
64
+ end
65
+ end
66
+
67
+ def new_artrails_capistrano_run(cmd, options={}, &block)
68
+ if cmd.include?('db:migrate')
69
+ c = cmd.split(';')
70
+
71
+ c.each_index do |index|
72
+ if c[index].strip[0..4].include?('rake ') && c[index].include?('db:migrate')
73
+ c[index] = " sudo -i -u #{new_artrails_capistrano_sudo_as} " + c[index]
74
+ end
75
+ end
76
+
77
+ cmd = c.join(';')
78
+ end
79
+ if cmd.include?('find')
80
+ cmd = "sudo -u #{new_artrails_capistrano_sudo_as} " + cmd
81
+ end
82
+
83
+ if cmd.strip[0..3] != 'pwd ' &&
84
+ !cmd.include?( 'sudo' ) &&
85
+ !cmd.include?( 'chmod +r+w+x' ) &&
86
+ !cmd.include?( 'chmod g+w' ) &&
87
+ !cmd.include?( 'chgrp -R mongrel' ) &&
88
+ !cmd.include?( 'find' )
89
+ if !cmd.include?( ' && (' ) && !cmd.include?( 'sh -c' )
90
+ cmd = cmd.gsub( /\s&&\s/, " && sudo -i -u #{new_artrails_capistrano_sudo_as} " )
91
+ end
92
+ if !cmd.include?(' | (') && !cmd.include?('sh -c')
93
+ cmd = cmd.gsub(/\s\|\s/, " | sudo -i -u #{new_artrails_capistrano_sudo_as} ")
94
+ end
95
+
96
+ cmd = "sudo -i -u #{new_artrails_capistrano_sudo_as} " + cmd
97
+ end
98
+
99
+ execute(cmd, options, &block)
100
+ end
101
+ end
102
+ end
103
+ end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Capistrano
4
4
  module NewArtrailsCapistrano
5
- VERSION = '0.0.1'
5
+ VERSION = '0.0.2'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: new_artrails_capistrano
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marcin Kalita
@@ -402,7 +402,6 @@ extra_rdoc_files: []
402
402
  files:
403
403
  - ".codeclimate.yml"
404
404
  - ".gitignore"
405
- - ".rspec_status"
406
405
  - ".rubocop.yml"
407
406
  - ".rubocop_todo.yml"
408
407
  - ".travis.yml"
@@ -419,6 +418,8 @@ files:
419
418
  - config.reek
420
419
  - lib/.keep
421
420
  - lib/capistrano/new_artrails_capistrano.rb
421
+ - lib/capistrano/new_artrails_capistrano/front_helpers.rb
422
+ - lib/capistrano/new_artrails_capistrano/helpers.rb
422
423
  - lib/capistrano/new_artrails_capistrano/version.rb
423
424
  - lib/capistrano/tasks/new_artrails_capistrano.rake
424
425
  - lib/new_artrails_capistrano.rb