edploy 2.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.
Files changed (55) hide show
  1. data/.gitignore +4 -0
  2. data/Gemfile +4 -0
  3. data/MIT-LICENSE +92 -0
  4. data/README.rdoc.fast_remote_cache +48 -0
  5. data/Rakefile +1 -0
  6. data/TODO.TXT +17 -0
  7. data/bin/dploy +15 -0
  8. data/bin/dploygen +39 -0
  9. data/bin/dployify +29 -0
  10. data/edploy.gemspec +21 -0
  11. data/lib/capistrano/ext/mailer.rb +90 -0
  12. data/lib/capistrano/ext/multistage.rb +59 -0
  13. data/lib/capistrano/ext/output_catcher.rb +97 -0
  14. data/lib/capistrano/ext/output_hooks.rb +54 -0
  15. data/lib/capistrano/recipes/deploy/strategy/fast_remote_cache.rb +44 -0
  16. data/lib/capistrano/recipes/deploy/strategy/utilities/copy.rb +53 -0
  17. data/lib/edploy/environment_capistrano.rb +19 -0
  18. data/lib/edploy/recipes/apache.rb +8 -0
  19. data/lib/edploy/recipes/bundle_install.rb +15 -0
  20. data/lib/edploy/recipes/fast_remote_cache.rb +43 -0
  21. data/lib/edploy/recipes/fast_remote_cache_extensions.rb +11 -0
  22. data/lib/edploy/recipes/hooks.rb +24 -0
  23. data/lib/edploy/recipes/production.rb +56 -0
  24. data/lib/edploy/recipes/rails.rb +5 -0
  25. data/lib/edploy/recipes/setup_project.rb +26 -0
  26. data/lib/edploy/recipes/smart_deploy.rb +47 -0
  27. data/lib/edploy/recipes/templates.rb +60 -0
  28. data/lib/edploy/recipes/web_disable_enable.rb +32 -0
  29. data/lib/edploy.rb +17 -0
  30. data/lib/edployify/configuration.rb +140 -0
  31. data/lib/edployify/preferences.rb +176 -0
  32. data/lib/edployify/project.rb +69 -0
  33. data/lib/edployify/template.rb +84 -0
  34. data/lib/edployify.rb +6 -0
  35. data/lib/edployscripts/archive.rb +27 -0
  36. data/lib/edployscripts/environment_scripts.rb +47 -0
  37. data/lib/edployscripts/file_handling.rb +28 -0
  38. data/lib/edployscripts/git.rb +27 -0
  39. data/lib/edployscripts.rb +6 -0
  40. data/templates/config/edploy/copy/extract/.gitkeep +0 -0
  41. data/templates/config/edploy/copy/init_scripts/.gitkeep +0 -0
  42. data/templates/config/edploy/copy/project_files/.gitkeep +0 -0
  43. data/templates/config/edploy/scripts/after_deploy_setup/.gitkeep +0 -0
  44. data/templates/config/edploy/scripts/after_deploy_symlink/passenger/clear_file_cache.erb +7 -0
  45. data/templates/config/edploy/scripts/after_deploy_update_code/make_symlinks.erb +74 -0
  46. data/templates/config/edploy/scripts/edploygen/01_bundle_install.erb +5 -0
  47. data/templates/config/edploy/scripts/edploygen/01_prepare_servers.post.erb +12 -0
  48. data/templates/config/edploy/scripts/edploygen/02_whenever_configs.erb +36 -0
  49. data/templates/config/edploy/templates/passenger/activate.rb.erb +2 -0
  50. data/templates/config/edploy/templates/passenger/after_config.rb.erb +2 -0
  51. data/templates/config/edploy/templates/passenger/apache_vhost.erb.erb +107 -0
  52. data/templates/config/edploy/templates/passenger/config.rb.erb +3 -0
  53. data/templates/config/edploy/templates/passenger/deactivate.rb.erb +1 -0
  54. data/templates/config/edploy/whenever/generic.rb.erb +12 -0
  55. metadata +113 -0
@@ -0,0 +1,176 @@
1
+ require 'highline'
2
+ require 'yaml'
3
+ require 'fileutils'
4
+ # work around problem where HighLine detects an eof on $stdin and raises an err
5
+ HighLine.track_eof = false
6
+
7
+ module Edployify
8
+
9
+ class Preferences
10
+
11
+ PREFERENCES_FILE = File.join(Dir.home, '.edployify.cfg')
12
+
13
+ class << self
14
+
15
+ def get
16
+ instance.get
17
+ end
18
+
19
+ private
20
+
21
+ def instance
22
+ @@instance ||= self.new
23
+ end
24
+
25
+ end
26
+
27
+ def get
28
+ initial_configure if preferences.empty?
29
+ preferences
30
+ end
31
+
32
+ def configure
33
+ menu
34
+ end
35
+
36
+ def request_preset(action)
37
+ list_presets
38
+ ask_preset(action)
39
+ end
40
+
41
+ private
42
+
43
+ def initial_configure
44
+ puts "You don't have any git repository presets configured, let's do this first."
45
+ puts ""
46
+ add_preset
47
+ menu
48
+ end
49
+
50
+ def add_preset
51
+ puts ""
52
+ puts "Define a username, hostname and optionally a basepath for the preset."
53
+ puts "Note: A project name will be defined during the actual edployify run later on.\n"
54
+ puts "Structure: <USERNAME>@<HOSTNAME>:<BASEPATH>/{PROJECT}.git"
55
+ puts "Example: git@github.com:ewoutvonk/edploy.git"
56
+ puts "Example: gituser@my.server.com:myproject.git (if basepath is empty, there is no slash)"
57
+ preset_add(modify_preset)
58
+ end
59
+
60
+ def modify_preset(preset = nil)
61
+ satisfied = false
62
+ username = nil
63
+ hostname = nil
64
+ basepath = nil
65
+ if preset
66
+ username, hostname, basepath = preset.split(/[@:]|\/?\{PROJECT\}\.git/)
67
+ basepath = nil if basepath.nil? || basepath.empty?
68
+ end
69
+ until satisfied do
70
+ puts ""
71
+ username = highline.ask("Git repository username: ") { |q| q.default = username || 'git' }
72
+ hostname = highline.ask("Git repository hostname: ") { |q| q.default = hostname || 'github.com' }
73
+ basepath = highline.ask("Git repository basepath (optional): ") { |q| q.default = basepath if basepath }
74
+ preset = "#{username}@#{hostname}:#{basepath}#{basepath.empty? ? '' : '/'}{PROJECT}.git"
75
+ puts ""
76
+ highline.choose do |menu|
77
+ menu.prompt = "Current value: `#{preset}'. What do you want to do? "
78
+ menu.choice(:save) { satisfied = true }
79
+ menu.choice(:change) { }
80
+ menu.choice(:abort) { return } unless preferences.empty?
81
+ end
82
+ end
83
+ preset
84
+ end
85
+
86
+ def edit_preset
87
+ list_presets
88
+ old_preset = ask_preset(:edit)
89
+ new_preset = modify_preset(old_preset)
90
+ preset_update(old_preset, new_preset)
91
+ end
92
+
93
+ def delete_preset
94
+ list_presets
95
+ preset_delete(ask_preset(:delete))
96
+ end
97
+
98
+ def list_presets
99
+ puts "\nPresets:\n\n"
100
+ puts (presets_list.each_with_index.map { |entry, i| " #{i+1}. #{entry}" }.join("\n") + "\n")
101
+ end
102
+
103
+ def ask_preset(action)
104
+ preset = nil
105
+ begin
106
+ i = highline.ask("Preset to #{action}: ", Integer)
107
+ end until !(preset = preset_get(i-1)).nil?
108
+ preset
109
+ end
110
+
111
+ def menu
112
+ while true do
113
+ puts ""
114
+ highline.choose do |menu|
115
+ menu.prompt = "Main menu. Please make a choice. "
116
+ menu.choice(:list_presets) { list_presets }
117
+ menu.choice(:add_preset) { add_preset }
118
+ menu.choice(:edit_preset) { edit_preset }
119
+ menu.choice(:delete_preset) { delete_preset }
120
+ menu.choice(:quit) { return }
121
+ end
122
+ end
123
+ end
124
+
125
+ ##
126
+
127
+ def presets_list
128
+ preferences[:presets]
129
+ end
130
+
131
+ def preset_add(preset)
132
+ preferences[:presets] << preset
133
+ write_file
134
+ end
135
+
136
+ def preset_update(old_preset, new_preset)
137
+ delete_preset(old_preset)
138
+ add_preset(new_preset)
139
+ end
140
+
141
+ def preset_delete(preset)
142
+ preferences[:presets].delete(preset)
143
+ write_file
144
+ end
145
+
146
+ def preset_get(i)
147
+ preferences[:presets][i]
148
+ end
149
+
150
+ def preferences
151
+ unless @preferences
152
+ FileUtils.touch PREFERENCES_FILE
153
+ $edployify_cfg = File.open(PREFERENCES_FILE, "r+")
154
+ at_exit do
155
+ $edployify_cfg.close unless $edployify_cfg.closed?
156
+ end
157
+ preferences_contents = $edployify_cfg.read
158
+ @preferences = preferences_contents.length == 0 ? {} : YAML::load(preferences_contents)
159
+ $edployify_cfg.rewind
160
+ end
161
+ @preferences
162
+ end
163
+
164
+ def write_file
165
+ $edployify_cfg.write YAML::dump(preferences)
166
+ $edployify_cfg.truncate $edployify_cfg.pos
167
+ $edployify_cfg.rewind
168
+ end
169
+
170
+ def highline
171
+ @highline ||= HighLine.new
172
+ end
173
+
174
+ end
175
+
176
+ end
@@ -0,0 +1,69 @@
1
+ require 'highline'
2
+ require 'fileutils'
3
+ # work around problem where HighLine detects an eof on $stdin and raises an err
4
+ HighLine.track_eof = false
5
+
6
+ module Edployify
7
+
8
+ class Project
9
+
10
+ class << self
11
+
12
+ def before_capify_clean
13
+ FileUtils.rm_f('Capfile')
14
+ end
15
+
16
+ def after_capify_clean
17
+ capfile = File.readlines('Capfile').map { |line| line =~ /load 'config\/deploy'/ ? [ "require 'edploy'\n", line ] : line }.flatten.join('')
18
+ File.open('Capfile', 'w') { |f| f.write capfile }
19
+ check_existing_dir(File.join('config', 'deploy'))
20
+ check_existing_file(File.join('config', 'deploy.rb'))
21
+ end
22
+
23
+ private
24
+
25
+ def check_existing_file(file)
26
+ if File.exists?(file)
27
+ highline.choose do |menu|
28
+ menu.prompt = "File `#{file}' exists, what do you want to do? "
29
+ menu.choice(:ignore) do
30
+ end
31
+ menu.choice(:truncate) do
32
+ File.truncate(file, 0)
33
+ end
34
+ menu.choice(:comment) do
35
+ File.open(file, 'r+') { |f| c = f.readlines.map { |l| "# #{l}" } ; f.rewind ; f.write c.join() ; f.truncate f.pos }
36
+ end
37
+ end
38
+ end
39
+ end
40
+
41
+ def check_existing_dir(dir)
42
+ if File.directory?(dir)
43
+ highline.choose do |menu|
44
+ menu.prompt = "Directory `#{dir}' exists, what do you want to do? "
45
+ menu.choice(:ignore) do
46
+ end
47
+ menu.choice(:remove) do
48
+ FileUtils.rm_rf(dir)
49
+ end
50
+ menu.choice(:move_stages_to_edploy_and_remove) do
51
+ FileUtils.mv Dir.glob("config/deploy/*.rb"), "config/edploy/stages/"
52
+ FileUtils.rm_rf(dir)
53
+ end
54
+ menu.choice(:rename_with_bak_extension) do
55
+ FileUtils.mv(dir, dir + ".bak")
56
+ end
57
+ end
58
+ end
59
+ end
60
+
61
+ def highline
62
+ @@highline ||= HighLine.new
63
+ end
64
+
65
+ end
66
+
67
+ end
68
+
69
+ end
@@ -0,0 +1,84 @@
1
+ require 'fileutils'
2
+ require 'erb'
3
+
4
+ module Edployify
5
+
6
+ class Dir
7
+ def initialize(path, base_path)
8
+ @path = File.join(base_path, path)
9
+ end
10
+
11
+ def mkdir
12
+ FileUtils.mkdir_p(@path)
13
+ end
14
+ end
15
+
16
+ class Template
17
+
18
+ TEMPLATES_DIR = File.expand_path('../../../templates', __FILE__)
19
+
20
+ def initialize(path, templates_base, project_base)
21
+ @template = File.join(templates_base, path)
22
+ @target = File.join(project_base, path.sub(/\.erb$/, ''))
23
+ end
24
+
25
+ def generate(local_binding)
26
+ content = ::ERB.new(IO.read(@template)).result(local_binding)
27
+ if File.exists?(@target)
28
+ warn "[skip] '#{@target}' already exists"
29
+ elsif File.exists?(@target.downcase)
30
+ warn "[skip] '#{@target.downcase}' exists, which could conflict with `#{@target}'"
31
+ else
32
+ unless File.exists?(File.dirname(@target))
33
+ puts "[add] making directory '#{File.dirname(@target)}'"
34
+ FileUtils.mkdir(File.dirname(@target))
35
+ end
36
+ puts "[add] writing '#{@target}'"
37
+ File.open(@target, "w") { |f| f.write(content) }
38
+ end
39
+ end
40
+
41
+ class << self
42
+
43
+ def templates
44
+ @@templates ||= init(:templates)
45
+ end
46
+
47
+ def dirs
48
+ @@dirs ||= init(:dirs)
49
+ end
50
+
51
+ def make_dirs
52
+ dirs.each do |dir|
53
+ dir.mkdir
54
+ end
55
+ end
56
+
57
+ def generate_templates(local_binding)
58
+ templates.each do |template|
59
+ template.generate(local_binding)
60
+ end
61
+ end
62
+
63
+ private
64
+
65
+ def init(type)
66
+ @@entries ||= { :templates => [], :dirs => [] }
67
+ if @@entries[:templates].empty? && @@entries[:dirs].empty?
68
+ ::Dir["#{TEMPLATES_DIR}/config/edploy/**/*"].each do |fqpn|
69
+ entry = fqpn.sub(/^#{TEMPLATES_DIR}\//, '')
70
+ if File.directory?(fqpn)
71
+ @@entries[:dirs] << Edployify::Dir.new(entry, ::RAILS_ROOT)
72
+ elsif entry.end_with?('.erb')
73
+ @@entries[:templates] << Edployify::Template.new(entry, TEMPLATES_DIR, ::RAILS_ROOT)
74
+ end
75
+ end
76
+ end
77
+ @@entries[type]
78
+ end
79
+
80
+ end
81
+
82
+ end
83
+
84
+ end
data/lib/edployify.rb ADDED
@@ -0,0 +1,6 @@
1
+ # Copyright (c) 2009-2012 by Ewout Vonk. All rights reserved.
2
+
3
+ require File.expand_path('../edployify/configuration.rb', __FILE__)
4
+ require File.expand_path('../edployify/preferences.rb', __FILE__)
5
+ require File.expand_path('../edployify/project.rb', __FILE__)
6
+ require File.expand_path('../edployify/template.rb', __FILE__)
@@ -0,0 +1,27 @@
1
+ module Edploy
2
+ class Archive
3
+
4
+ class << self
5
+
6
+ def extract(archive, target_dir, options = {})
7
+ cmds = []
8
+ case archive_type(archive)
9
+ when :tgz then cmds << "tar -C #{target_dir} -z -x -f #{archive}"
10
+ when :tbz2 then cmds << "tar -C #{target_dir} -j -x -f #{archive}"
11
+ when :tar then cmds << "tar -C #{target_dir} -x -f #{archive}"
12
+ when :zip then cmds << "cd #{target_dir} ; unzip #{archive}"
13
+ end
14
+ cmds << "rm -f #{archive}" if options[:remove]
15
+ system cmds.join(' ; ')
16
+ end
17
+
18
+ private
19
+
20
+ def archive_type(archive)
21
+ archive.sub(/\.tar\.gz$/, '.tgz').sub(/\.tar\.bz2$/, '.tbz2').gsub(/\./, '').downcase.to_sym
22
+ end
23
+
24
+ end
25
+
26
+ end
27
+ end
@@ -0,0 +1,47 @@
1
+ if defined?(REQUIRE_BUNDLE_EXEC) && REQUIRE_BUNDLE_EXEC && (ENV['BUNDLE_GEMFILE'].nil? || ENV['BUNDLE_BIN_PATH'].nil?)
2
+ abort "You should run this with bundle exec!"
3
+ elsif !File.exists?(File.join(Dir.getwd, 'Capfile'))
4
+ abort "You should run this from the rails root!"
5
+ end
6
+
7
+ RAILS_ROOT = Dir.getwd
8
+
9
+ require 'syck'
10
+
11
+ Syck.load_file(File.join(RAILS_ROOT, 'config', 'edploy', 'edploy.yml')).each do |key, value|
12
+ self.class.const_set(key.to_sym.upcase, value)
13
+ end
14
+
15
+ GEM_DIR = File.expand_path('../../../', __FILE__)
16
+ MY_HOSTNAME = `hostname`.strip
17
+ MY_HOSTNAME_WITHOUT_INDEX = `hostname | sed 's/[0-9]$//'`.strip
18
+
19
+ unless defined?(Capistrano::Configuration) # only execute when this file gets included from a normal script
20
+ PROJECT_PATH = ENV['PROJECT_PATH'] || File.expand_path('../../../../', __FILE__)
21
+ DEPLOY_USER = (ENV['DEPLOY_USER'].nil? || ENV['DEPLOY_USER'].empty?) ? `id -un`.strip : ENV['DEPLOY_USER']
22
+ DEPLOY_GROUP = (ENV['DEPLOY_GROUP'].nil? || ENV['DEPLOY_GROUP'].empty?) ? `id -gn`.strip : ENV['DEPLOY_GROUP']
23
+
24
+ if %w(staging test qa tryout).include?(MY_HOSTNAME)
25
+ RAILS_ENV = 'staging'
26
+ if MY_HOSTNAME == 'test'
27
+ STAGE = 'testmachine'
28
+ else
29
+ STAGE = MY_HOSTNAME
30
+ end
31
+ SHARED_PATH = "#{DEPLOY_TO}/shared"
32
+ CURRENT_PATH = "#{DEPLOY_TO}/current"
33
+ GLUSTERFS_PATH = "/mnt/glusterfs"
34
+ elsif %w(app db).include?(MY_HOSTNAME_WITHOUT_INDEX)
35
+ RAILS_ENV = 'production'
36
+ STAGE = 'production'
37
+ SHARED_PATH = "#{DEPLOY_TO}/shared"
38
+ CURRENT_PATH = "#{DEPLOY_TO}/current"
39
+ GLUSTERFS_PATH = "/mnt/glusterfs"
40
+ else
41
+ RAILS_ENV = 'development'
42
+ STAGE = nil
43
+ SHARED_PATH = File.expand_path('../../../../shared', __FILE__)
44
+ CURRENT_PATH = PROJECT_PATH
45
+ GLUSTERFS_PATH = File.expand_path('../../../../glusterfs', __FILE__)
46
+ end
47
+ end
@@ -0,0 +1,28 @@
1
+ module Edploy
2
+ class FileHandling
3
+
4
+ class << self
5
+
6
+ def upload_file(file, tmp_path, &block)
7
+ if File.exists?(file)
8
+ random_string = "#{Time.now.to_i}"
9
+ tmp_file = "#{tmp_path}/#{random_string}-#{File.basename(file)}"
10
+ commands << "mkdir -p #{File.dirname(tmp_file)}"
11
+ put File.read(file), tmp_file, :mode => 0644
12
+ yield(tmp_file)
13
+ end
14
+ end
15
+
16
+ def iterate_dir_items(base_dir, &block)
17
+ Dir["#{base_dir}/**"].each do |fqpn|
18
+ entry = fqpn.sub(/^#{base_dir}\//, '')
19
+ dirname = File.dirname(entry)
20
+ filename = File.basename(entry)
21
+ yield(dirname, filename, relative_entry, fqpn)
22
+ end
23
+ end
24
+
25
+ end
26
+
27
+ end
28
+ end
@@ -0,0 +1,27 @@
1
+ module Edploy
2
+ class Git
3
+
4
+ class << self
5
+
6
+ def git(*opts)
7
+ options = opts.last.is_a?(Hash) ? opts.pop : {}
8
+ opts << "--hard" if options[:hard]
9
+ if message = options.delete(:message)
10
+ opts << "-m '#{message}'"
11
+ end
12
+ opts << '2>/dev/null' if options[:silent]
13
+ cmd = "git #{opts.map(&:to_s).join(' ')}"
14
+ unless system(cmd)
15
+ return if options[:silent]
16
+ abort "error while running `#{cmd}'"
17
+ end
18
+ end
19
+
20
+ def method_missing(method, *args, &block)
21
+ git(*([method] + args))
22
+ end
23
+
24
+ end
25
+
26
+ end
27
+ end
@@ -0,0 +1,6 @@
1
+ # Copyright (c) 2009-2012 by Ewout Vonk. All rights reserved.
2
+
3
+ require File.expand_path('../edployscripts/environment_scripts.rb', __FILE__)
4
+ require File.expand_path('../edployscripts/file_handling.rb', __FILE__)
5
+ require File.expand_path('../edployscripts/archive.rb', __FILE__)
6
+ require File.expand_path('../edployscripts/git.rb', __FILE__)
File without changes
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'edployscripts'
4
+ require 'fileutils'
5
+
6
+ puts "Clearing local file cache..."
7
+ FileUtils.rm_rf(Dir['tmp/cache/[^.]*'])
@@ -0,0 +1,74 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'edployscripts'
4
+ require 'fileutils'
5
+
6
+ FileUtils.mkdir_p(SHARED_PATH)
7
+ FileUtils.mkdir_p(GLUSTERFS_PATH)
8
+
9
+ sudo_mkdir_p = []
10
+ mkdir_p = []
11
+ sudo_chown = []
12
+ rm_rf = []
13
+ cp_a = {}
14
+ sudo_ln_nfs = {}
15
+ ln_nfs = {}
16
+ commands = []
17
+
18
+ SYMLINK_DURING_DEPLOY.each do |source_template, target_template|
19
+ is_dir_symlink = source_template.end_with?('/')
20
+ source = source_template.gsub(/:[^\/]+/) { |s| Kernel.const_get(s[1..-1].upcase.to_sym) }.gsub(/\/$/, '')
21
+ target = target_template.gsub(/:[^\/]+/) { |s| Kernel.const_get(s[1..-1].upcase.to_sym) }
22
+
23
+ target_is_inside_project = target.start_with?(DEPLOY_TO)
24
+ source_is_inside_project = source.start_with?(DEPLOY_TO)
25
+ if is_dir_symlink
26
+ unless File.exists?(source)
27
+ if source_is_inside_project
28
+ mkdir_p << source
29
+ else
30
+ sudo_mkdir_p << source
31
+ end
32
+ sudo_chown << source
33
+ end
34
+ rm_rf << target if File.exists?(target) && !File.symlink?(target) && is_inside_project
35
+ end
36
+ if target_is_inside_project
37
+ ln_nfs[source] = target
38
+ else
39
+ sudo_ln_nfs[source] = target
40
+ end
41
+ end
42
+
43
+ stage_host_files_dir = File.join(PROJECT_PATH, 'config', 'edploy', 'copy', 'project_files', STAGE, MY_HOSTNAME)
44
+ stage_role_files_dir = File.join(PROJECT_PATH, 'config', 'edploy', 'copy', 'project_files', STAGE, MY_HOSTNAME_WITHOUT_INDEX)
45
+ stage_files_dir = File.join(PROJECT_PATH, 'config', 'edploy', 'copy', 'project_files', STAGE)
46
+ stage_host_files_to_copy = Dir[File.join(stage_host_files_dir, '*')].map { |entry| entry.sub(/^#{stage_host_files_dir}\//, '') }
47
+ stage_role_files_to_copy = Dir[File.join(stage_role_files_dir, '*')].map { |entry| entry.sub(/^#{stage_role_files_dir}\//, '') }
48
+ stage_files_to_copy = Dir[File.join(stage_files_dir, '*')].reject { |entry| [ MY_HOSTNAME, MY_HOSTNAME_WITHOUT_INDEX ].include?(File.basename(entry)) }.map { |entry| entry.sub(/^#{stage_files_dir}\//, '') }
49
+
50
+ {
51
+ stage_host_files_dir => stage_host_files_to_copy,
52
+ stage_role_files_dir => stage_role_files_to_copy,
53
+ stage_files_dir => stage_files_to_copy
54
+ }.each do |base_source_dir, file_list|
55
+ file_list.each do |file|
56
+ mkdir_p << File.join(PROJECT_PATH, File.dirname(file))
57
+ cp_a[File.join(base_source_dir, file)] = File.join(PROJECT_PATH, File.dirname(file), '/')
58
+ end
59
+ end
60
+
61
+ commands = []
62
+ commands << "sudo mkdir -p #{sudo_mkdir_p.uniq.join(' ')}" unless sudo_mkdir_p.empty?
63
+ commands << "mkdir -p #{mkdir_p.uniq.join(' ')}" unless mkdir_p.empty?
64
+ commands << "sudo chown #{DEPLOY_USER}:#{DEPLOY_GROUP} #{sudo_chown.uniq.join(' ')}" unless sudo_chown.empty?
65
+ commands << "rm -rf #{rm_rf.uniq.join(' ')}" unless rm_rf.empty?
66
+ commands += cp_a.map { |source, target| "cp -a #{source} #{target}" }
67
+ commands += sudo_ln_nfs.map { |source, target| "sudo ln -nfs #{source} #{target}" }
68
+ commands += ln_nfs.map { |source, target| "ln -nfs #{source} #{target}" }
69
+
70
+ commands.each do |cmd|
71
+ puts cmd
72
+ end
73
+
74
+ system commands.join(' ; ') or abort "#{$0} failed"
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'edployscripts'
4
+
5
+ system("bundle install --path vendor/bundle")
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ REQUIRE_BUNDLE_EXEC = true
4
+ require 'edployscripts'
5
+
6
+ location = File.join(::RAILS_ROOT, 'config', 'edploy', 'stages')
7
+ stages = Dir["#{location}/*.rb"].map { |f| File.basename(f, ".rb") }
8
+
9
+ stages.each do |stage|
10
+ system("cap #{stage} fast_remote_cache:setup")
11
+ system("cap #{stage} fast_remote_cache:prepare")
12
+ end
@@ -0,0 +1,36 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ REQUIRE_BUNDLE_EXEC = true
4
+ require 'edployscripts'
5
+ require 'open3'
6
+ require 'fileutils'
7
+
8
+ def run_process(cmd, target_file)
9
+ puts "writing #{target_file}.."
10
+ Open3.popen3(cmd) { |stdin, stdout, stderr|
11
+ err_output = stderr.read
12
+ std_output = stdout.readlines.map { |line| line =~ /^## \[message\] / ? nil : line.strip }.compact.join("\n").strip + "\n"
13
+ if err_output.empty?
14
+ File.open(target_file, "w") { |f| f.write std_output.gsub(RAILS_ROOT, File.join(DEPLOY_TO, 'current')) }
15
+ else
16
+ abort "error while running: #{cmd}\n#{err_output}"
17
+ end
18
+ }
19
+ File.chmod(0755, target_file)
20
+ end
21
+
22
+ Dir["#{RAILS_ROOT}/config/edploy/whenever/*.rb"].entries.each do |crontab_def_file|
23
+ config_base_name = File.basename(crontab_def_file, ".rb")
24
+ next if config_base_name.to_sym == :generic
25
+ stage = File.readlines(crontab_def_file).grep(/^set :stage/).first.split(", ").last.strip[1..-2]
26
+
27
+ base_target_dir = File.join(RAILS_ROOT, 'config', 'edploy', 'copy', 'project_files', stage)
28
+ target_dir = config_base_name == stage ? base_target_dir : File.join(base_target_dir, "#{config_base_name}")
29
+ target_file = File.join(target_dir, 'config', "<%= application %>_cron")
30
+
31
+ FileUtils.mkdir_p(target_dir)
32
+ cmd = "whenever -f #{crontab_def_file}"
33
+ run_process(cmd, target_file)
34
+ end
35
+
36
+ system("git add #{RAILS_ROOT}/config/edploy/copy/project_files/production/*/config/*_cron #{RAILS_ROOT}/config/edploy/copy/project_files/{staging,testmachine,qa,tryout}/config/*_cron")
@@ -0,0 +1,2 @@
1
+ sudo "ln -nsf #{deploy_to}/passenger/apache_vhost /etc/apache2/sites-available/#{application}"
2
+ sudo "a2ensite #{application}"
@@ -0,0 +1,2 @@
1
+ sudo "ln -nsf #{deploy_to}/passenger/apache_vhost /etc/apache2/sites-available/#{application}"
2
+ sudo "a2ensite #{application}"