kompanee-recipes 0.0.9 → 0.0.10

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of kompanee-recipes might be problematic. Click here for more details.

@@ -2,5 +2,5 @@ $:.unshift(File.dirname(__FILE__)) unless
2
2
  $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
3
3
 
4
4
  module KompaneeRecipes
5
- VERSION = '0.0.9'
5
+ VERSION = '0.0.10'
6
6
  end
@@ -54,6 +54,14 @@ Capistrano::Configuration.instance(:must_exist).load do
54
54
 
55
55
  RewriteEngine On
56
56
 
57
+ ErrorDocument 503 /system/maintenance.html
58
+ RewriteCond %{DOCUMENT_ROOT}/system/maintenance.html -f
59
+ RewriteCond %{SCRIPT_FILENAME} !maintenance.html
60
+ RewriteCond %{REQUEST_URI} !^/images/
61
+ RewriteCond %{REQUEST_URI} !^/robots.txt
62
+ RewriteCond %{REQUEST_URI} !^/sitemap
63
+ RewriteRule ^.*$ - [redirect=503,last]
64
+
57
65
  ErrorLog /var/log/apache2/#{application}-errors.log
58
66
 
59
67
  LogLevel warn
@@ -1,40 +1,10 @@
1
- require 'kompanee-recipes/ubuntu_server_setup'
2
- require 'kompanee-recipes/app_setup'
3
- require 'kompanee-recipes/bash_environment'
4
- require 'bundler/capistrano'
5
-
6
1
  Capistrano::Configuration.instance(:must_exist).load do
7
- set :use_sudo, false
8
- set :default_shell, false
9
- set :rake, "bundle install; bundle exec rake"
2
+ set :use_sudo, false
3
+ set :default_shell, false
4
+ set :rake, "bundle install; bundle exec rake"
10
5
 
11
6
  set(:application_safe) {application.gsub(/-/, "_")}
12
7
 
13
- ######################################################################
14
- # SERVER SPECIFIC #
15
- ######################################################################
16
- set :domain, "thekompanee.com"
17
-
18
- set(:user) {"deploy"}
19
- set(:user_home) {"/home/#{user}"}
20
- set(:deploy_dir) {"/var/www"}
21
- set(:deploy_name) {"#{application_short}.#{domain}"}
22
- set(:deploy_to) {"#{deploy_dir}/#{deploy_name}"}
23
-
24
- set :server_ip, "174.143.210.58"
25
- set :app_server_ip, server_ip
26
- set :web_server_ip, server_ip
27
- set :db_server_ip, server_ip
28
-
29
- set(:server_name) {"zeus.#{domain}"}
30
- set :web_server_name, server_name
31
- set :app_server_name, server_name
32
- set :db_server_name, server_name
33
-
34
- set :app_ruby_version, "ruby-1.9.2-head"
35
- set :default_ruby_version, "ruby-1.9.2-head"
36
- set :passenger_version, "3.0.0"
37
-
38
8
  ######################################################################
39
9
  # DATABASE SPECIFIC #
40
10
  ######################################################################
@@ -47,24 +17,81 @@ Capistrano::Configuration.instance(:must_exist).load do
47
17
  set :scm, :git
48
18
  set :github_account, "thekompanee"
49
19
  set(:repository) {"git@github.com:#{github_account}/#{application}.git"}
50
- set :branch, "master"
20
+ set(:current_branch) { `git branch`.match(/\* (\S+)\s/m)[1] || raise("Couldn't determine current branch") }
21
+ set :branch, defer { current_branch }
51
22
  set :deploy_via, :remote_cache
52
23
  ssh_options[:forward_agent] = true
53
24
 
54
25
  ######################################################################
55
- # SERVER ROLE SETUP #
26
+ # SYSTEM GEM VERSIONS #
56
27
  ######################################################################
57
- role :web, web_server_name
58
- role :app, app_server_name
59
- role :db, db_server_name, :primary => true
28
+ set :default_ruby_version, "ruby-1.9.2-head"
29
+ set :app_ruby_version, "ruby-1.9.2-head"
30
+ set :passenger_version, "3.0.0"
31
+ set :bundler_version, "1.0.7"
60
32
 
61
- role :ubuntu, web_server_name
62
- role :apache, web_server_name
63
- role :mysql, db_server_name
64
-
65
33
  ######################################################################
66
34
  # DEPLOYMENT TASKS #
67
35
  ######################################################################
36
+ on :start, "ensure_stage", :except => ["staging", "production"]
37
+
38
+ before 'deploy', 'deploy:web:disable'
39
+ before 'deploy:migrate', 'deploy:backup'
40
+ after 'deploy:update_code', 'deploy:migrate'
41
+ after 'deploy:finalize_update', 'deploy:config:symlink'
42
+ after 'deploy:restart', 'deploy:tag'
43
+ after 'deploy', 'deploy:cleanup', 'deploy:web:enable'
44
+
45
+ desc "[internal] Ensure that a rails_env to deploy to has been selected."
46
+ task :ensure_stage do
47
+ unless exists?(:rails_env)
48
+ abort "You need to specify staging or production when you deploy. ie 'cap deploy:staging' or 'cap staging db:backup'"
49
+ end
50
+ end
51
+
52
+ task :staging do
53
+ require 'kompanee-recipes/ubuntu_server_setup'
54
+ require 'kompanee-recipes/app_setup'
55
+ require 'kompanee-recipes/bash_environment'
56
+
57
+ set :rails_env, "staging"
58
+ set :domain, "thekompanee.com"
59
+
60
+ set(:user) {"deploy"}
61
+ set(:manager_user) {ENV['CAP_MANAGER_USER'] || user}
62
+ set(:user_home) {"/home/#{user}"}
63
+ set(:manager_user_home) {"/home/#{manager_user}"}
64
+ set(:deploy_dir) {"/var/www"}
65
+ set(:deploy_name) {"#{application_short}.#{domain}"}
66
+ set(:deploy_to) {"#{deploy_dir}/#{deploy_name}"}
67
+
68
+ set :server_ip, "174.143.210.58"
69
+ set :app_server_ip, server_ip
70
+ set :web_server_ip, server_ip
71
+ set :db_server_ip, server_ip
72
+
73
+ set(:server_name) {"zeus.#{domain}"}
74
+ set :web_server_name, server_name
75
+ set :app_server_name, server_name
76
+ set :db_server_name, server_name
77
+
78
+ role :web, web_server_name, :primary => true
79
+ role :app, app_server_name, :primary => true
80
+ role :db, db_server_name, :primary => true
81
+
82
+ role :ubuntu, web_server_name, app_server_name, db_server_name
83
+ role :apache, web_server_name
84
+ role :mysql, db_server_name
85
+ end
86
+
87
+ task :production do
88
+ set :rails_env, "production"
89
+
90
+ set :user, "heroku@thekompanee.com"
91
+ set(:password) {Capistrano::CLI.password_prompt("Heroku Password: ")}
92
+
93
+ require 'kompanee-recipes/heroku_deploy'
94
+ end
68
95
 
69
96
  namespace :deploy do
70
97
  task :start do ; end
@@ -73,53 +100,124 @@ Capistrano::Configuration.instance(:must_exist).load do
73
100
  run "touch #{File.join(current_path,'tmp','restart.txt')}"
74
101
  end
75
102
 
103
+ task :tag do
104
+ timestamp_string_without_seconds = Time.now.strftime("%Y%m%d%H%M")
105
+ tag_name = "deployed_to_#{rails_env}_#{timestamp_string_without_seconds}"
106
+
107
+ `git tag -a -m "Tagging deploy to #{rails_env} at #{timestamp_string_without_seconds}" #{tag_name} #{branch}`
108
+ `git push --tags > /dev/null 2>&1 &`
109
+
110
+ puts "Tagged release with #{tag_name}"
111
+ end
112
+
113
+ namespace :gems do
114
+ desc "Install Bundled Gems"
115
+ task :install, :roles => :app do
116
+ Net::SSH.start(app_server_ip, user) do |ssh|
117
+ ssh.exec!("cd #{current_path} && bundle install --gemfile #{release_path}/Gemfile --path #{shared_path}/bundle --deployment --quiet --without development test")
118
+ end
119
+ end
120
+
121
+ desc "Update Bundled Gems"
122
+ task :update, :roles => :app do
123
+ raise "I'm sorry Dave, but I can't let you do that. I have full control over production." if rails_env == 'production'
124
+
125
+ Net::SSH.start(app_server_ip, user) do |ssh|
126
+ ssh.exec!("cd #{current_path} && bundle update")
127
+ end
128
+ end
129
+ end
130
+
131
+ namespace :config do
132
+ task :create do
133
+ run "if [ ! -d #{shared_path}/config ]; then mkdir #{shared_path}/config; fi"
134
+ run "if [ ! -f #{shared_path}/config/database.yml ]; then cp #{latest_release}/config/database.#{rails_env}.yml #{shared_path}/config/database.yml; fi"
135
+ end
136
+
137
+ task :symlink do
138
+ config.create
139
+ run "ln -nfs #{shared_path}/config/database.yml #{latest_release}/config/database.yml"
140
+ end
141
+ end
142
+
76
143
  namespace :web do
144
+ desc <<-DESC
145
+ Makes the application web-accessible again. Removes the \
146
+ "maintenance.html" page generated by deploy:web:disable, which (if your \
147
+ web servers are configured correctly) will make your application \
148
+ web-accessible again.
149
+ DESC
150
+ task :enable, :roles => :web, :except => { :no_release => true } do
151
+ run "rm #{shared_path}/system/maintenance.html"
152
+ end
153
+
154
+ desc <<-DESC
155
+ Present a maintenance page to visitors. Disables your application's web \
156
+ interface by writing a "maintenance.html" file to each web server. The \
157
+ servers must be configured to detect the presence of this file, and if \
158
+ it is present, always display it instead of performing the request.
159
+
160
+ By default, the maintenance page will just say the site is down for \
161
+ "maintenance", and will be back "shortly", but you can customize the \
162
+ page by specifying the REASON and UNTIL environment variables:
163
+
164
+ $ cap deploy:web:disable \\
165
+ REASON="hardware upgrade" \\
166
+ UNTIL="12pm Central Time"
167
+
168
+ Further customization will require that you write your own task.
169
+ DESC
170
+ task :disable, :roles => :web, :except => { :no_release => true } do
171
+ on_rollback { rm "#{shared_path}/system/maintenance.html" }
172
+
173
+ require 'erb'
174
+ deadline, reason = ENV['UNTIL'], ENV['REASON']
175
+
176
+ template = File.read("./app/views/pages/maintenance.html.erb")
177
+ maintenance_page = ERB.new(template).result(binding)
178
+
179
+ put maintenance_page, "#{shared_path}/system/maintenance.html", :mode => 0644
180
+ end
181
+
77
182
  desc "Uses the Web Server to enable the site."
78
- task :site_up do
183
+ task :site_up, :roles => [:web, :apache, :ubuntu] do
79
184
  ubuntu.apache.enable
80
185
  end
81
186
 
82
187
  desc "Uses the Web Server to disable the site."
83
- task :site_down do
188
+ task :site_down, :roles => [:web, :apache, :ubuntu] do
84
189
  ubuntu.apache.disable
85
190
  end
86
191
 
87
192
  desc "Takes the entire web server up."
88
- task :server_up do
193
+ task :server_up, :roles => [:web, :apache, :ubuntu] do
89
194
  ubuntu.apache.start
90
195
  end
91
196
 
92
197
  desc "Takes the entire web server down."
93
- task :server_down do
198
+ task :server_down, :roles => [:web, :apache, :ubuntu] do
94
199
  ubuntu.apache.stop
95
200
  end
96
201
 
97
202
  desc "Restarts then entire web server."
98
- task :server_restart do
203
+ task :server_restart, :roles => [:web, :apache, :ubuntu] do
99
204
  ubuntu.apache.restart
100
205
  end
101
206
 
102
207
  desc "Installs the site configuration for the files."
103
- task :install do
208
+ task :install, :roles => [:web, :apache, :ubuntu] do
104
209
  app_setup.apache.install_virtual_host
105
210
  end
106
211
 
107
212
  desc "Completely removes the site configuration from the server (but leaves the files.)"
108
- task :remove do
213
+ task :remove, :roles => [:web, :apache] do
109
214
  app_setup.apache.remove_virtual_host
110
215
  end
111
216
  end
112
217
 
113
- namespace :db do
114
- desc "Adds the DBizzle to the Sizzle. Also adds the appropriate user."
115
- task :create do
116
- app_setup.db.create
117
- end
118
-
119
- desc "Removes the DB from the Server. Also removes the user."
120
- task :drop do
121
- app_setup.db.drop
122
- end
218
+ desc "Make sure server has all necessary software for deployment."
219
+ task :server_setup, :roles => [:ubuntu] do
220
+ ubuntu.setup
123
221
  end
124
222
 
125
223
  desc "Prepare the server for deployment."
@@ -131,10 +229,36 @@ Capistrano::Configuration.instance(:must_exist).load do
131
229
  deploy.web.server_restart
132
230
  deploy.check
133
231
  end
232
+ end
134
233
 
135
- desc "Make sure server has all necessary software for deployment."
136
- task :server_setup do
137
- ubuntu.setup
234
+ namespace :db do
235
+ desc "Adds the DBizzle to the Sizzle. Also adds the appropriate user."
236
+ task :create, :roles => :db do
237
+ app_setup.db.create
238
+ end
239
+
240
+ desc "Removes the DB from the Server. Also removes the user."
241
+ task :drop, :roles => :db do
242
+ app_setup.db.drop
243
+ end
244
+
245
+ desc "Backup the database"
246
+ task :backup, :roles => :db do
247
+ run "cd #{current_path} && rake BACKUP_DIRECTORY=#{shared_path} RAILS_ENV=#{rails_env} db:backup"
248
+ end
249
+
250
+ desc "Reset database and seed fresh"
251
+ task :reset_and_seed do
252
+ raise "I'm sorry Dave, but I can't let you do that. I have full control over production." if rails_env == 'production'
253
+ db.backup
254
+ run "cd #{current_path} && rake RAILS_ENV=#{rails_env} db:reset_and_seed"
255
+ end
256
+
257
+ desc "Seed database"
258
+ task :seed do
259
+ raise "I'm sorry Dave, but I can't let you do that. I have full control over production." if rails_env == 'production'
260
+ db.backup
261
+ run "cd #{current_path} && rake RAILS_ENV=#{rails_env} db:seed"
138
262
  end
139
263
  end
140
264
  end
@@ -1,6 +1,4 @@
1
1
  Capistrano::Configuration.instance(:must_exist).load do
2
- set :passenger_version, "2.2.13"
3
-
4
2
  ######################################################################
5
3
  # UBUNTU SERVER TASKS #
6
4
  ######################################################################
@@ -74,14 +72,14 @@ Capistrano::Configuration.instance(:must_exist).load do
74
72
 
75
73
  namespace :gems do
76
74
  desc "Install Bundler"
77
- task :install_bundler do
75
+ task :install_bundler, :roles => :app do
78
76
  Net::SSH.start(web_server_ip, user) do |ssh|
79
- ssh.exec!("rvm use #{default_ruby_version}@global && gem install bundler --no-ri --no-rdoc")
77
+ ssh.exec!("rvm use #{default_ruby_version}@global && gem install bundler --version #{bundler_version} --no-ri --no-rdoc")
80
78
  end
81
79
  end
82
80
 
83
81
  desc "Install Passenger"
84
- task :install_passenger do
82
+ task :install_passenger, :roles => :web do
85
83
  Net::SSH.start(web_server_ip, user) do |ssh|
86
84
  ssh.exec!("rvm use #{default_ruby_version}@global && gem install passenger --version #{passenger_version} --no-ri --no-rdoc")
87
85
  end
@@ -91,12 +89,12 @@ Capistrano::Configuration.instance(:must_exist).load do
91
89
 
92
90
  namespace :vc do
93
91
  desc "Install Git"
94
- task :install_git, :roles => [:ubuntu] do
92
+ task :install_git, :roles => [:ubuntu, :app] do
95
93
  sudo "apt-get install git-core git-svn -y"
96
94
  end
97
95
 
98
96
  desc "Install Subversion"
99
- task :install_subversion, :roles => [:ubuntu] do
97
+ task :install_subversion, :roles => [:ubuntu, :app] do
100
98
  sudo "apt-get install subversion -y"
101
99
  end
102
100
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kompanee-recipes
3
3
  version: !ruby/object:Gem::Version
4
- hash: 13
4
+ hash: 11
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 9
10
- version: 0.0.9
9
+ - 10
10
+ version: 0.0.10
11
11
  platform: ruby
12
12
  authors:
13
13
  - The Kompanee