fezzik 0.4.2 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (6) hide show
  1. data/README.md +7 -1
  2. data/TODO.md +0 -1
  3. data/bin/fezify +46 -34
  4. data/fezzik.gemspec +5 -1
  5. data/lib/fezzik.rb +25 -6
  6. metadata +40 -75
data/README.md CHANGED
@@ -7,7 +7,7 @@ and gets out of your way.
7
7
 
8
8
  ## Install
9
9
 
10
- sudo gem install fezzik
10
+ gem install fezzik
11
11
 
12
12
  ## Setup
13
13
 
@@ -96,6 +96,12 @@ The command.rb recipe gives you a prompt that lets you execute shell code on eac
96
96
  run command (or "quit"): tail www/myapp/log.txt -n 1
97
97
  [2011-07-01 00:01:23] GET / 200
98
98
 
99
+ You can also run a single command:
100
+
101
+ $ fez prod command_execute\['ls'\]
102
+
103
+ (You'll probably need to escape the `[]` in your shell as well.)
104
+
99
105
  ### Rollback
100
106
 
101
107
  fez get rollback
data/TODO.md CHANGED
@@ -5,7 +5,6 @@
5
5
  * clear old releases
6
6
  * better way to update recipes/core with gem updates
7
7
  * figure out how to include/share common recipes
8
- * per-server or per-group configurations
9
8
 
10
9
  ## Bugs
11
10
  * symlink task links to a nonexistant directory when run in isolation
data/bin/fezify CHANGED
@@ -1,20 +1,20 @@
1
1
  #!/usr/bin/env ruby
2
2
  require "colorize"
3
+ require "fileutils"
3
4
 
4
5
  files = {
5
- "config/deploy.rb" => <<-EOF,
6
+ "config/deploy.rb" => <<-'EOF',
6
7
  # This is the configuration file for fezzik.
7
8
  # Define variables here as you would for Vlad the Deployer.
8
9
  # A full list of variables can be found here:
9
10
  # http://hitsquad.rubyforge.org/vlad/doco/variables_txt.html
10
11
 
11
12
  set :app, "app"
12
- set :deploy_to, "/opt/#\{app\}"
13
- set :release_path, "#\{deploy_to\}/releases/#\{Time.now.strftime("%Y%m%d%H%M")\}"
13
+ set :deploy_to, "/opt/#{app}"
14
+ set :release_path, "#{deploy_to}/releases/#{Time.now.strftime("%Y%m%d%H%M")}"
14
15
  set :local_path, Dir.pwd
15
16
  set :user, "root"
16
17
 
17
-
18
18
  # Each destination is a set of machines and configurations to deploy to.
19
19
  # You can deploy to a destination from the command line with:
20
20
  # fez to_dev deploy
@@ -24,20 +24,27 @@ set :user, "root"
24
24
  # You can set environment variables that will be loaded at runtime on the server
25
25
  # like this:
26
26
  # env :rack_env, "production"
27
+ # or
28
+ # env :error_monitoring, "true", ["prod12.com"]
29
+ # The second form specifies an environment variable particular to a server or list of servers (as a subset of
30
+ # the :domain list).
31
+ #
27
32
  # This will also generate a file on the server named config/environment.rb, which you can include
28
33
  # in your code to load these variables as Ruby constants. You can create your own config/environment.rb
29
34
  # file to use for development, and it will be overwritten at runtime.
30
35
 
31
36
  destination :dev do
32
- set :domain, "#\{user\}@dev.example.com"
37
+ set :domain, "#{user}@dev.example.com"
33
38
  end
34
39
 
35
40
  destination :prod do
36
- set :domain, "#\{user\}@prod.example.com"
41
+ set :domain, "#{user}@prod.example.com"
37
42
  end
38
43
  EOF
39
44
 
40
- "config/recipes/core.rb" => <<-EOF,
45
+ "config/recipes/core.rb" => <<-'EOF',
46
+ require "fileutils"
47
+
41
48
  # This file contains core tasks that are used to deploy your application to the
42
49
  # destination servers. This is a decent initial setup, but is completely configurable.
43
50
 
@@ -49,58 +56,65 @@ namespace :fezzik do
49
56
  # and it will be overwritten by this task when the code deploys.
50
57
  desc "saves variables set by 'env' in deploy.rb into config/environment.sh and config/environment.rb"
51
58
  task :save_environment do
52
- system("mkdir -p /tmp/#\{app\}/config")
53
- File.open("/tmp/#\{app\}/config/environment.rb", "w") do |file|
54
- @environment.each do |key, value|
55
- file.puts "#\{key.to_s.upcase\}=\\"#\{value\}\\""
59
+ @per_server_environments.each do |server, environment|
60
+ root_config_dir = "/tmp/#{app}/#{server}_config"
61
+ FileUtils.mkdir_p root_config_dir
62
+ File.open(File.join(root_config_dir, "environment.rb"), "w") do |file|
63
+ environment.each do |key, value|
64
+ quote = value.is_a?(Numeric) ? '' : '"'
65
+ file.puts "#{key.to_s.upcase} = #{quote}#{value}#{quote}"
66
+ end
56
67
  end
57
- end
58
- File.open("/tmp/#\{app\}/config/environment.sh", "w") do |file|
59
- @environment.each do |key, value|
60
- file.puts "export #\{key.to_s.upcase\}=\\"#\{value\}\\""
68
+ File.open(File.join(root_config_dir, "environment.sh"), "w") do |file|
69
+ environment.each { |key, value| file.puts %[export #{key.to_s.upcase}="#{value}"] }
61
70
  end
62
71
  end
63
72
  end
64
73
 
65
74
  desc "stages the project for deployment in /tmp"
66
75
  task :stage do
67
- puts "staging project in /tmp/#\{app\}"
68
- system("rm -fr /tmp/#\{app\}")
69
- system("cp -r #\{local_path\} /tmp/#\{app\}")
76
+ puts "staging project in /tmp/#{app}"
77
+ FileUtils.rm_rf "/tmp/#{app}"
78
+ FileUtils.mkdir_p "/tmp/#{app}/staged"
79
+ FileUtils.cp_r "#{local_path}/.", "/tmp/#{app}/staged"
70
80
  Rake::Task["fezzik:save_environment"].invoke
71
81
  end
72
82
 
73
83
  desc "performs any necessary setup on the destination servers prior to deployment"
74
84
  remote_task :setup do
75
85
  puts "setting up servers"
76
- run "mkdir -p #\{deploy_to\}/releases"
86
+ run "mkdir -p #{deploy_to}/releases"
77
87
  end
78
88
 
79
89
  desc "rsyncs the project from its stages location to each destination server"
80
90
  remote_task :push => [:stage, :setup] do
81
- puts "pushing to #\{target_host\}:#\{release_path\}"
91
+ puts "pushing to #{target_host}:#{release_path}"
82
92
  # Copy on top of previous release to optimize rsync
83
- rsync "-q", "--copy-dest=#\{current_path\}", "/tmp/#\{app\}/", "#\{target_host\}:#\{release_path\}"
93
+ rsync "-q", "--copy-dest=#{current_path}", "/tmp/#{app}/staged/", "#{target_host}:#{release_path}"
94
+ # Copy over the appropriate configs for the target
95
+ ["environment.rb", "environment.sh"].each do |config_file|
96
+ rsync "-q", "/tmp/#{app}/#{target_host}_config/#{config_file}",
97
+ "#{target_host}:#{release_path}/config/#{config_file}"
98
+ end
84
99
  end
85
100
 
86
101
  desc "symlinks the latest deployment to /deploy_path/project/current"
87
102
  remote_task :symlink do
88
- puts "symlinking current to #\{release_path\}"
89
- run "cd #\{deploy_to\} && ln -fns #\{release_path\} current"
103
+ puts "symlinking current to #{release_path}"
104
+ run "cd #{deploy_to} && ln -fns #{release_path} current"
90
105
  end
91
106
 
92
107
  desc "runs the executable in project/bin"
93
108
  remote_task :start do
94
- puts "starting from #\{capture_output \{ run \"readlink #\{current_path\}\" \}\}"
95
- run "cd #\{current_path\} && source config/environment.sh" +
96
- " && ./bin/run_app.sh"
109
+ puts "starting from #{capture_output { run "readlink #{current_path}" }}"
110
+ run "cd #{current_path} && source config/environment.sh && ./bin/run_app.sh"
97
111
  end
98
112
 
99
113
  desc "kills the application by searching for the specified process name"
100
114
  remote_task :stop do
101
115
  puts "stopping app"
102
116
  # Replace YOUR_APP_NAME with whatever is run from your bin/run_app.sh file.
103
- # run "(kill -9 `ps aux | grep 'YOUR_APP_NAME' | grep -v grep | awk '\{print $2\}'` || true)"
117
+ # run "(kill -9 `ps aux | grep 'YOUR_APP_NAME' | grep -v grep | awk '{print $2}'` || true)"
104
118
  end
105
119
 
106
120
  desc "restarts the application"
@@ -114,19 +128,19 @@ namespace :fezzik do
114
128
  Rake::Task["fezzik:push"].invoke
115
129
  Rake::Task["fezzik:symlink"].invoke
116
130
  Rake::Task["fezzik:restart"].invoke
117
- puts "#\{app\} deployed!"
131
+ puts "#{app} deployed!"
118
132
  end
119
133
  end
120
134
  EOF
121
135
 
122
- "bin/run_app.sh" => <<-EOF
136
+ "bin/run_app.sh" => <<-'EOF'
123
137
  #!/bin/sh
124
138
  # This file will be called to start your application.
125
139
  EOF
126
140
  }
127
141
 
128
- system("mkdir -p config/recipes")
129
- system("mkdir -p bin")
142
+ FileUtils.mkdir_p "config/recipes"
143
+ FileUtils.mkdir_p "bin"
130
144
 
131
145
  files.each do |filename, content|
132
146
  if File.exists?(filename) && ARGV[0] != "-f"
@@ -134,9 +148,7 @@ files.each do |filename, content|
134
148
  else
135
149
  puts " [new] #{filename} created".green
136
150
  File.open(filename, "w") { |file| file.write(content) }
137
- if filename == "bin/run_app.sh"
138
- system("chmod a+x bin/run_app.sh")
139
- end
151
+ system("chmod a+x bin/run_app.sh") if filename == "bin/run_app.sh"
140
152
  end
141
153
  end
142
154
 
data/fezzik.gemspec CHANGED
@@ -1,6 +1,10 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "fezzik/version"
4
+
1
5
  Gem::Specification.new do |s|
2
6
  s.name = "fezzik"
3
- s.version = "0.4.2"
7
+ s.version = Fezzik::VERSION
4
8
 
5
9
  s.required_rubygems_version = Gem::Requirement.new(">=0") if s.respond_to? :required_rubygems_version=
6
10
  s.specification_version = 2 if s.respond_to? :specification_version=
data/lib/fezzik.rb CHANGED
@@ -3,7 +3,7 @@ require "stringio"
3
3
  namespace :fezzik do
4
4
  task :run do
5
5
  destination = ARGV[0]
6
- destination = $1 if destination.match(/to_(.+)/)
6
+ destination = $1 if destination.match(/^to_(.+)/)
7
7
  destination, @domain_override = destination.split(":", 2)
8
8
  @domain_override = @domain_override.split(",") if @domain_override
9
9
  tasks = ARGV[1..-1]
@@ -29,9 +29,9 @@ namespace :fezzik do
29
29
  @destination = args[:destination].to_sym
30
30
  @environment = {}
31
31
  require "./config/deploy.rb"
32
- servers = domain
33
- servers = domain.join(", ") if domain.is_a?(Array)
34
- puts "configuring for #{servers}"
32
+ @servers = domain.is_a?(Array) ? domain : domain.split(",").map(&:strip)
33
+ compute_environment_per_server
34
+ puts "configuring for #{@servers.join(", ")}"
35
35
  end
36
36
 
37
37
  def destination(target, &block)
@@ -44,8 +44,27 @@ namespace :fezzik do
44
44
  end
45
45
  end
46
46
 
47
- def env(key, value)
48
- @environment[key] = value
47
+ # If servers is given, then this environment variable will only apply to that server (or array of servers)
48
+ # (these should match names given in :domain). If servers is not given, then this environment variable
49
+ # applies to all servers.
50
+ def env(key, value, servers = nil)
51
+ servers = Array(servers) if servers
52
+ @environment[[key, servers]] = value
53
+ end
54
+
55
+ def compute_environment_per_server
56
+ @per_server_environments = Hash.new { |h, k| h[k] = {} }
57
+ @environment.each do |k, value|
58
+ key, servers = k
59
+ if servers
60
+ # Allow the user to provide "user@host.com" or "host.com" when identifying servers for per-server
61
+ # environment variables.
62
+ applicable_servers = @servers.select { |s1| servers.any? { |s2| s1 == s2 || s1.end_with?(s2) } }
63
+ else
64
+ applicable_servers = @servers
65
+ end
66
+ applicable_servers.each { |s| @per_server_environments[s][key] = value }
67
+ end
49
68
  end
50
69
 
51
70
  def capture_output(&block)
metadata CHANGED
@@ -1,120 +1,85 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: fezzik
3
- version: !ruby/object:Gem::Version
4
- hash: 11
5
- prerelease: false
6
- segments:
7
- - 0
8
- - 4
9
- - 2
10
- version: 0.4.2
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.5.0
5
+ prerelease:
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Daniel MacDougall
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2011-08-18 00:00:00 -07:00
19
- default_executable:
20
- dependencies:
21
- - !ruby/object:Gem::Dependency
12
+ date: 2011-11-14 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
22
15
  name: rake
23
- prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: &2152418940 !ruby/object:Gem::Requirement
25
17
  none: false
26
- requirements:
18
+ requirements:
27
19
  - - ~>
28
- - !ruby/object:Gem::Version
29
- hash: 49
30
- segments:
31
- - 0
32
- - 8
33
- - 7
20
+ - !ruby/object:Gem::Version
34
21
  version: 0.8.7
35
22
  type: :runtime
36
- version_requirements: *id001
37
- - !ruby/object:Gem::Dependency
38
- name: rake-remote_task
39
23
  prerelease: false
40
- requirement: &id002 !ruby/object:Gem::Requirement
24
+ version_requirements: *2152418940
25
+ - !ruby/object:Gem::Dependency
26
+ name: rake-remote_task
27
+ requirement: &2152414560 !ruby/object:Gem::Requirement
41
28
  none: false
42
- requirements:
29
+ requirements:
43
30
  - - ~>
44
- - !ruby/object:Gem::Version
45
- hash: 11
46
- segments:
47
- - 2
48
- - 0
49
- - 2
31
+ - !ruby/object:Gem::Version
50
32
  version: 2.0.2
51
33
  type: :runtime
52
- version_requirements: *id002
53
- - !ruby/object:Gem::Dependency
54
- name: colorize
55
34
  prerelease: false
56
- requirement: &id003 !ruby/object:Gem::Requirement
35
+ version_requirements: *2152414560
36
+ - !ruby/object:Gem::Dependency
37
+ name: colorize
38
+ requirement: &2152413800 !ruby/object:Gem::Requirement
57
39
  none: false
58
- requirements:
59
- - - ">="
60
- - !ruby/object:Gem::Version
61
- hash: 27
62
- segments:
63
- - 0
64
- - 5
65
- - 8
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
66
43
  version: 0.5.8
67
44
  type: :runtime
68
- version_requirements: *id003
45
+ prerelease: false
46
+ version_requirements: *2152413800
69
47
  description: A light deployment system that gets out of your way
70
48
  email: dmacdougall@gmail.com
71
- executables:
49
+ executables:
72
50
  - fez
73
51
  - fezify
74
52
  extensions: []
75
-
76
53
  extra_rdoc_files: []
77
-
78
- files:
54
+ files:
79
55
  - README.md
80
56
  - TODO.md
81
57
  - fezzik.gemspec
82
58
  - lib/fezzik.rb
83
59
  - bin/fez
84
60
  - bin/fezify
85
- has_rdoc: true
86
61
  homepage: http://github.com/dmacdougall/fezzik
87
62
  licenses: []
88
-
89
63
  post_install_message:
90
64
  rdoc_options: []
91
-
92
- require_paths:
65
+ require_paths:
93
66
  - lib
94
- required_ruby_version: !ruby/object:Gem::Requirement
67
+ required_ruby_version: !ruby/object:Gem::Requirement
95
68
  none: false
96
- requirements:
97
- - - ">="
98
- - !ruby/object:Gem::Version
99
- hash: 3
100
- segments:
101
- - 0
102
- version: "0"
103
- required_rubygems_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - ! '>='
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
73
+ required_rubygems_version: !ruby/object:Gem::Requirement
104
74
  none: false
105
- requirements:
106
- - - ">="
107
- - !ruby/object:Gem::Version
108
- hash: 3
109
- segments:
110
- - 0
111
- version: "0"
75
+ requirements:
76
+ - - ! '>='
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
112
79
  requirements: []
113
-
114
80
  rubyforge_project: fezzik
115
- rubygems_version: 1.3.7
81
+ rubygems_version: 1.8.7
116
82
  signing_key:
117
83
  specification_version: 2
118
84
  summary: A light deployment system that gets out of your way
119
85
  test_files: []
120
-