kompanee-recipes 0.0.10 → 0.1.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.

Potentially problematic release.


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

@@ -0,0 +1,24 @@
1
+ Capistrano::Configuration.instance(:must_exist).load do
2
+ set :rake, "bundle exec rake"
3
+
4
+ namespace :gems do
5
+ desc "Install Bundled Gems"
6
+ task :install do
7
+ run "cd #{current_path} && bundle install --gemfile #{current_path}/Gemfile --path #{shared_path}/bundle --deployment --quiet --without development test"
8
+ end
9
+
10
+ desc "Update Bundled Gems"
11
+ task :update do
12
+ raise "I'm sorry Dave, but I can't let you do that. I have full control over production." if rails_env == 'production'
13
+
14
+ run "cd #{current_path} && bundle update"
15
+ end
16
+ end
17
+
18
+ namespace :bundler do
19
+ desc "Install Bundler"
20
+ task :install do
21
+ run "rvm use #{default_ruby_version}@global && gem install bundler --version #{bundler_version} --no-ri --no-rdoc"
22
+ end
23
+ end
24
+ end
@@ -1,264 +1,73 @@
1
- Capistrano::Configuration.instance(:must_exist).load do
2
- set :use_sudo, false
3
- set :default_shell, false
4
- set :rake, "bundle install; bundle exec rake"
5
-
6
- set(:application_safe) {application.gsub(/-/, "_")}
7
-
8
- ######################################################################
9
- # DATABASE SPECIFIC #
10
- ######################################################################
11
- set(:db_root_password) {Capistrano::CLI.password_prompt("Root Password For DB: ")}
12
- set(:db_app_password) {Capistrano::CLI.password_prompt("App Password For DB: ")}
13
-
14
- ######################################################################
15
- # VERSION CONTROL #
16
- ######################################################################
17
- set :scm, :git
18
- set :github_account, "thekompanee"
19
- set(:repository) {"git@github.com:#{github_account}/#{application}.git"}
20
- set(:current_branch) { `git branch`.match(/\* (\S+)\s/m)[1] || raise("Couldn't determine current branch") }
21
- set :branch, defer { current_branch }
22
- set :deploy_via, :remote_cache
23
- ssh_options[:forward_agent] = true
24
-
25
- ######################################################################
26
- # SYSTEM GEM VERSIONS #
27
- ######################################################################
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"
32
-
33
- ######################################################################
34
- # DEPLOYMENT TASKS #
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'
1
+ require 'kompanee-recipes/environment'
56
2
 
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
3
+ Capistrano::Configuration.instance(:must_exist).load do
4
+ require 'kompanee-recipes/ariadne'
86
5
 
87
- task :production do
88
- set :rails_env, "production"
6
+ before "deploy", "deploy:web:disable"
7
+ after "deploy", "deploy:web:enable"
89
8
 
90
- set :user, "heroku@thekompanee.com"
91
- set(:password) {Capistrano::CLI.password_prompt("Heroku Password: ")}
92
-
93
- require 'kompanee-recipes/heroku_deploy'
94
- end
9
+ before "deploy:migrate", "db:backup"
95
10
 
96
11
  namespace :deploy do
97
- task :start do ; end
98
- task :stop do ; end
99
- task :restart, :roles => :app, :except => { :no_release => true } do
100
- run "touch #{File.join(current_path,'tmp','restart.txt')}"
101
- end
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
12
+ desc <<-DESC
13
+ [internal] The list of tasks used by `deploy`, `deploy:cold` and `deploy:initial`
14
+ DESC
15
+ task :base do
16
+ transaction do
17
+ deploy.update
18
+ deploy.config.symlink
19
+ gems.install
20
+ deploy.migrate
21
+ deploy.tag
22
+ deploy.cleanup
128
23
  end
129
24
  end
130
25
 
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"
26
+ desc <<-DESC
27
+ Used when you would like to be more forceful with your deployment.
28
+
29
+ It will forceably disable the site (from the web server layer), run a standard
30
+ deployment, re-enable the site, and restart the web server.
31
+ DESC
32
+ task :cold do
33
+ transaction do
34
+ website.disable
35
+ deploy.base
36
+ website.enable
37
+ web_server.restart
140
38
  end
141
39
  end
142
-
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
40
 
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
-
182
- desc "Uses the Web Server to enable the site."
183
- task :site_up, :roles => [:web, :apache, :ubuntu] do
184
- ubuntu.apache.enable
185
- end
186
-
187
- desc "Uses the Web Server to disable the site."
188
- task :site_down, :roles => [:web, :apache, :ubuntu] do
189
- ubuntu.apache.disable
190
- end
191
-
192
- desc "Takes the entire web server up."
193
- task :server_up, :roles => [:web, :apache, :ubuntu] do
194
- ubuntu.apache.start
195
- end
196
-
197
- desc "Takes the entire web server down."
198
- task :server_down, :roles => [:web, :apache, :ubuntu] do
199
- ubuntu.apache.stop
200
- end
201
-
202
- desc "Restarts then entire web server."
203
- task :server_restart, :roles => [:web, :apache, :ubuntu] do
204
- ubuntu.apache.restart
205
- end
206
-
207
- desc "Installs the site configuration for the files."
208
- task :install, :roles => [:web, :apache, :ubuntu] do
209
- app_setup.apache.install_virtual_host
210
- end
211
-
212
- desc "Completely removes the site configuration from the server (but leaves the files.)"
213
- task :remove, :roles => [:web, :apache] do
214
- app_setup.apache.remove_virtual_host
41
+ desc <<-DESC
42
+ This task should be used only on the first deployment.
43
+
44
+ It will set up the deployment structure that Capistrano uses, create the DB, install
45
+ the website configuration files into the web server, and then run a standard "cold"
46
+ deployment.
47
+ DESC
48
+ task :initial do
49
+ transaction do
50
+ deploy.setup
51
+ db.create
52
+ website.install
53
+ deploy.cold
54
+ deploy.check
215
55
  end
216
56
  end
217
57
 
218
- desc "Make sure server has all necessary software for deployment."
219
- task :server_setup, :roles => [:ubuntu] do
220
- ubuntu.setup
221
- end
222
-
223
- desc "Prepare the server for deployment."
224
- task :prepare do
225
- deploy.db.create
226
- deploy.web.install
227
- deploy.setup
228
- deploy.web.site_up
229
- deploy.web.server_restart
230
- deploy.check
231
- end
232
- end
233
-
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"
58
+ desc <<-DESC
59
+ The standard deployment task.
60
+
61
+ It will check out a new release of the code to the `releases` directory, update the
62
+ symlinks to the desired shared configuration files, install all necessary gems,
63
+ run all pending migrations, tag the git commit, perform a cleanup and restart
64
+ the application layer so that the changes will take effect.
65
+ DESC
66
+ task :default do
67
+ transaction do
68
+ deploy.base
69
+ deploy.restart
70
+ end
262
71
  end
263
72
  end
264
73
  end
@@ -0,0 +1,213 @@
1
+ Capistrano::Configuration.instance(:must_exist).load do
2
+ ######################################################################
3
+ # ENVIRONMENT SETUP #
4
+ ######################################################################
5
+ on :start, "environment_check", :except => ["staging", "production"]
6
+
7
+ after 'production', 'defaults:production', 'defaults'
8
+ after 'staging', 'defaults:staging', 'defaults'
9
+
10
+ after 'defaults:rackspace', 'defaults:managed_server'
11
+ after 'defaults:managed_server', 'load_capabilities'
12
+ after 'defaults:heroku', 'load_capabilities'
13
+
14
+ before 'environment_check', 'environment_check:common'
15
+ after 'environment_check:rackspace', 'environment_check:managed_server'
16
+
17
+ namespace :defaults do
18
+ desc "[internal] Used to set up the intelligent staging defaults we like for our projects"
19
+ task :staging do
20
+ set :rails_env, "staging"
21
+ end
22
+
23
+ desc "[internal] Used to set up the intelligent production defaults we like for our projects"
24
+ task :production do
25
+ set :rails_env, "production"
26
+ end
27
+
28
+
29
+ desc "[internal] Sets intelligent defaults for managed server deployments."
30
+ task :managed_server do
31
+ set :default_ruby_version, "ruby-1.9.2-head" unless exists?(:default_ruby_version)
32
+ set :app_ruby_version, default_ruby_version unless exists?(:app_ruby_version)
33
+ set :passenger_version, "3.0.0" unless exists?(:passenger_version)
34
+ set :bundler_version, "1.0.7" unless exists?(:bundler_version)
35
+
36
+ set :deployment_username, "deploy" unless exists?(:deployment_user)
37
+ set :manager_username, "manager" unless exists?(:manager_username)
38
+ set :user, deployment_username unless exists?(:user)
39
+
40
+ set :user_home, "/home/#{user}" unless exists?(:user_home)
41
+ set :manager_user_home, "/home/#{manager_username}" unless exists?(:manager_user_home)
42
+ set :deployment_user_home, "/home/#{deployment_username}" unless exists?(:deployment_user_home)
43
+ set :deploy_dir, "/var/www" unless exists?(:deploy_dir)
44
+ set :deploy_name, "#{application_short}.#{domain}" unless exists?(:deploy_name)
45
+ set :deploy_to, "#{deploy_dir}/#{deploy_name}"
46
+
47
+ set :keep_releases, 15
48
+
49
+ set :global_shared_files, ["config/database.yml"] unless exists?(:global_shared_files)
50
+
51
+ set :app_server_ip, server_ip unless exists?(:app_server_ip)
52
+ set :web_server_ip, server_ip unless exists?(:web_server_ip)
53
+ set :db_server_ip, server_ip unless exists?(:db_server_ip)
54
+
55
+ set :app_server_name, server_name unless exists?(:app_server_name)
56
+ set :web_server_name, server_name unless exists?(:web_server_name)
57
+ set :db_server_name, server_name unless exists?(:db_server_name)
58
+
59
+ # Evidently roles can't be assigned in a namespace :-/
60
+ set_managed_server_roles
61
+ end
62
+
63
+ desc "[internal] Sets intelligent defaults for Kompanee Rackspace deployments."
64
+ task :rackspace do
65
+ set :domain, "thekompanee.com" unless exists?(:domain)
66
+
67
+ set :server_ip, "174.143.212.245" unless exists?(:server_ip)
68
+ set :server_name, "zeus.#{domain}" unless exists?(:server_name)
69
+
70
+ set :capabilities, [:ubuntu, :mysql, :phpmyadmin, :php, :apache, :rvm, :vim, :bash, :bundler, :git, :passenger] unless exists?(:capabilities)
71
+ end
72
+
73
+ desc "[internal] Sets intelligent defaults for Heroku deployments"
74
+ task :heroku do
75
+ set :heroku_credentials_path, "#{ENV["HOME"]}/.heroku" unless exists?(:heroku_credentials_path)
76
+ set :heroku_credentials_file, "#{heroku_credentials_path}/credentials" unless exists?(:heroku_credentials_file)
77
+
78
+ set(:password) {Capistrano::CLI.password_prompt("Encrypted Heroku Password: ")} unless exists?(:password)
79
+
80
+ set :capabilities, [:heroku]
81
+ end
82
+
83
+ desc "[internal] Sets intelligent version control defaults for deployments"
84
+ task :vc do
85
+ set :scm, :git
86
+ set :github_account, "thekompanee" unless exists?(:github_account)
87
+ set(:repository) {"git@github.com:#{github_account}/#{application}.git"}
88
+ set(:branch) { `git branch`.match(/\* (\S+)\s/m)[1] || raise("Couldn't determine current branch") }
89
+ set(:remote) { `git remote`.match(/(\S+)\s/m)[1] || raise("Couldn't determine default remote repository") }
90
+ set :deploy_via, :remote_cache
91
+ ssh_options[:forward_agent] = true
92
+ end
93
+
94
+ desc "[internal] Sets intelligent common defaults for deployments"
95
+ task :common do
96
+ set :use_sudo, false
97
+ set :default_shell, false
98
+
99
+ set(:application_underscored) {application.gsub(/-/, "_")} unless exists?(:application_underscored)
100
+ end
101
+
102
+ desc <<-DESC
103
+ [internal] Installs the entire environment for the given deployment type.
104
+
105
+ Most of these values can be overridden in each application's deploy.rb file.
106
+ Unfortunately some of them can't be such as :scm but they're our recipies so...
107
+ LIVE WITH IT! :)
108
+ DESC
109
+ task :default do
110
+ defaults.common
111
+ defaults.vc
112
+ defaults.send(deployment_type.to_s)
113
+ end
114
+ end
115
+
116
+ namespace :environment_check do
117
+ desc <<-DESC
118
+ [internal] Checks to see if all necessary Kompanee Rackspace environment variables have been set up.
119
+ DESC
120
+ task :rackspace do
121
+ required_variables = [
122
+ :domain,
123
+ :server_ip,
124
+ :server_name,
125
+ :app_ruby_version
126
+ ]
127
+
128
+ required_variables.each do |expected_variable|
129
+ abort( "You have not defined '#{expected_variable}' which is necessary for a Kompanee Rackspace deployment." ) unless exists?(expected_variable)
130
+ end
131
+ end
132
+
133
+ desc <<-DESC
134
+ [internal] Checks to see if all necessary managed server environment variables have been set up.
135
+ DESC
136
+ task :managed_server do
137
+ required_variables = [
138
+ :os_type,
139
+ :default_ruby_version,
140
+ :app_ruby_version,
141
+ :passenger_version,
142
+ :bundler_version,
143
+ :user,
144
+ :deployment_username,
145
+ :manager_username,
146
+ :user_home,
147
+ :manager_user_home,
148
+ :deploy_dir,
149
+ :deploy_name,
150
+ :deploy_to,
151
+ :app_server_ip,
152
+ :web_server_ip,
153
+ :db_server_ip,
154
+ :web_server_name,
155
+ :app_server_name,
156
+ :db_server_name
157
+ ]
158
+
159
+ required_variables.each do |expected_variable|
160
+ abort( "You have not defined '#{expected_variable}' which is necessary for a managed server deployment." ) unless exists?(expected_variable)
161
+ end
162
+ end
163
+
164
+ desc <<-DESC
165
+ [internal] Checks to see if all necessary Heroku environment variables have been set up.
166
+ DESC
167
+ task :heroku do
168
+ required_variables = [
169
+ :deploy_name,
170
+ :user
171
+ ]
172
+
173
+ required_variables.each do |expected_variable|
174
+ abort( "You have not defined '#{expected_variable}' which is necessary for a Heroku deployment." ) unless exists?(expected_variable)
175
+ end
176
+ end
177
+
178
+ desc "[internal] Checks for environment variables shared among all deployment types."
179
+ task :common do
180
+ abort "You need to specify staging or production when you deploy. ie 'cap staging db:backup'" unless exists?(:rails_env)
181
+ abort "You need to specify a deployment type in your application's 'deploy.rb' file. ie 'set :deployment_type, :heroku'" unless exists?(:deployment_type)
182
+
183
+ required_variables = [
184
+ :application,
185
+ :application_short
186
+ ]
187
+
188
+ required_variables.each do |expected_variable|
189
+ abort( "You have not defined '#{expected_variable}' which is necessary for a deployment." ) unless exists?(expected_variable)
190
+ end
191
+ end
192
+
193
+ desc "[internal] Checks to see if all the necessary environment variables have been set up for a proper deployment."
194
+ task :default do
195
+ environment_check.send(deployment_type.to_s)
196
+ end
197
+ end
198
+
199
+ desc "[internal] This task is only here because `role` cannot be used within a `namespace`"
200
+ task :set_managed_server_roles do
201
+ role :web, web_server_name, :primary => true
202
+ role :app, app_server_name, :primary => true
203
+ role :db, db_server_name, :primary => true
204
+ end
205
+
206
+ desc "[internal] This task is only here because `require` cannot be used within a `namespace`"
207
+ task :load_capabilities do
208
+ require "kompanee-recipes/#{deployment_type}"
209
+ capabilities.each do |capability|
210
+ require "kompanee-recipes/#{capability}"
211
+ end
212
+ end
213
+ end