capistrano-demonz 0.0.5 → 0.0.6

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.
data/README.md CHANGED
@@ -1,24 +1,116 @@
1
1
  # Capistrano::Demonz
2
2
 
3
- TODO: Write a gem description
3
+ Capistrano recipes developed for use by [Demonz Media](http://demonzmedia.com).
4
+
5
+ **Current version:** 0.0.5
6
+
7
+ Only includes a Drupal recipe for now.
4
8
 
5
9
  ## Installation
6
10
 
7
- Add this line to your application's Gemfile:
11
+ Make sure you have ruby and RubyGems installed, then run (you may need to prefix this with `sudo`):
12
+
13
+ $ gem install capistrano-demonz
14
+
15
+ ## Usage
8
16
 
9
- gem 'capistrano-demonz'
17
+ In your Drupal application's directory, run:
10
18
 
11
- And then execute:
19
+ $ capify .
12
20
 
13
- $ bundle
21
+ This will create two files, a `Capfile` in the root and `config/deploy.rb`.
14
22
 
15
- Or install it yourself as:
23
+ Open up the `Capfile` and replace it with:
16
24
 
17
- $ gem install capistrano-demonz
25
+ ```ruby
26
+ require 'rubygems'
27
+ require 'railsless-deploy'
28
+ load 'deploy' if respond_to?(:namespace)
29
+ load 'config/deploy'
30
+ require 'capistrano/ext/multistage'
31
+ require 'demonz/drupal'
32
+ ```
18
33
 
19
- ## Usage
34
+ Open up `deploy.rb` and replace with:
35
+
36
+ ```ruby
37
+ set :stages, %w(production staging)
38
+ set :default_stage, "staging"
39
+ set :application, "mysite.com"
40
+
41
+ set :repository, "git@github.com:demonz/mydrupalproject.git"
42
+ set :scm, :git
43
+ set :branch, ""
44
+ set :deploy_via, :remote_cache
45
+ set :deploy_to, "/var/www/#{application}"
46
+ # @see Demonz Base Stack/Configure user permissions
47
+ set :group, 'www-pub'
48
+ set :group_writable, true
49
+
50
+ # Set to true if boost (the Drupal module) is installed
51
+ set :uses_boost, false
52
+
53
+ # For automated SASS compilation
54
+ set :uses_sass, false
55
+ set :themes, []
56
+
57
+ set :keep_releases, 5
58
+ set :keep_backups, 7 # only keep 3 backups (default is 10)
59
+
60
+ # Set Excluded directories/files (relative to the application's root path)
61
+ set(:backup_exclude) { [ "var/", "tmp/" ] }
62
+ ```
63
+
64
+ Edit this according to your specific project. Importnant values are `:application`, `:repository`, `:branch` amongst others. It should be fairly self-explanatory.
65
+
66
+ Then, create a folder at `config/deploy` in your project's root:
67
+
68
+ $ mkdir config/deploy
69
+
70
+ And according to the number of application stages you defined previously in `:stages`, create applicable config files. For example, in the case above:
71
+
72
+ $ touch config/deploy/staging.rb
73
+ $ touch config/deploy/production.rb
74
+
75
+ Then, in each of the above files, enter a variation of the following:
76
+
77
+ ```ruby
78
+ server 'myserver.com', :app, :web, :primary => true
79
+ # role :web, "mywebserver.com"
80
+ # role :app, "mywebserver.com"
81
+ # role :db, "mydatabaseserver.com", :primary => true
82
+ set :user, 'root'
83
+ set :use_sudo, false
84
+
85
+ set :ssh_options, {
86
+ :forward_agent => true,
87
+ # :keys => ["#{ENV['HOME']}/.ssh/your-ec2-key.pem"],
88
+ :keys => [File.join(ENV["HOME"], ".ssh", "id_rsa")],
89
+ :port => 2992
90
+ }
91
+ ```
92
+
93
+ Make sure to set your SSH server and user (`:user`)—if this user isn't root, set `:use_sudo` to `true`.
94
+
95
+ If you have seperate web and database servers, comment out the `server` line and uncomment each of the `role` lines. Set these to their respective servers. In Drupal's case the `role :web` and `role :app` lines should be identical.
96
+
97
+ Once all of that's done, run the following command (**note: this will create a folder on the remote server at /var/www/mysite.com**, make sure this doesn't conflict with anything):
98
+
99
+ $ cap deploy:setup
100
+
101
+ When that finishes, log on to (each of?) the remote server(s). Copy your site's files directory to `/var/www/mysite.com/shared/default/files` and put a copy of your site's settings file at `/var/www/mysite.com/shared/settings.{stage}.php`. Replace `{stage}` with the stage that this server represents (staging, production, etc.).
102
+
103
+ You can then run a deployment with:
104
+
105
+ $ cap deploy -S tag="mygittag"
106
+
107
+ If you do not specify a Git tag, it will use the HEAD revision of your current repository and prompt you to create a tag.
108
+
109
+ Additionally, if this is a fresh deployment, the script will prompt you for a gzipped SQL dump, try and have this ready. An easy way to do this is:
110
+
111
+ $ drush sql-dump --result-file --gzip
20
112
 
21
- TODO: Write usage instructions here
113
+ And that's it!
22
114
 
23
115
  ## Contributing
24
116
 
data/lib/demonz/base.rb CHANGED
@@ -14,10 +14,6 @@ configuration = Capistrano::Configuration.respond_to?(:instance) ?
14
14
 
15
15
  configuration.load do
16
16
 
17
- # Set default stages
18
- set :stages, %w(staging production)
19
- set :default_stage, "staging"
20
-
21
17
  # Set shared path to be inside app directory
22
18
  set :shared_path, File.join(deploy_to, 'shared')
23
19
 
@@ -40,7 +36,6 @@ configuration.load do
40
36
  # --------------------------------------------
41
37
  # SSH
42
38
  set :user, proc{text_prompt("SSH username: ")}
43
- set :group, :user
44
39
  set :password, proc{Capistrano::CLI.password_prompt("SSH password for '#{user}':")}
45
40
 
46
41
  # Database
@@ -61,7 +56,7 @@ configuration.load do
61
56
  set :copy_strategy, :checkout
62
57
  set :copy_compression, :bz2
63
58
  set :copy_exclude, [".svn", ".DS_Store", "*.sample", "LICENSE*", "Capfile",
64
- "RELEASE*", "*.rb", "*.sql", "nbproject", "_template", "*.sublime*"]
59
+ "RELEASE*", "*.sql", "nbproject", "_template", "*.sublime*"]
65
60
 
66
61
  # Backups Path
67
62
  _cset(:backups_path) { File.join(deploy_to, "backups") }
@@ -79,10 +74,8 @@ configuration.load do
79
74
  # Release tracking
80
75
  set :release_file, File.join(shared_path, "RELEASES")
81
76
 
82
- # SASS compilation support (via compass)
83
- set :uses_sass, false
84
-
85
77
  # Add a dependency on compass and :themes if required
78
+ uses_sass = fetch(:uses_sass, false)
86
79
  if uses_sass
87
80
  depend :remote, :gem, "compass", ">=0.12"
88
81
  _cset(:themes) { abort "Please specify themes on this site, set :themes, ['theme1', 'theme2']" }
@@ -120,7 +113,7 @@ configuration.load do
120
113
 
121
114
  desc "Setup backup directory for database and web files"
122
115
  task :setup_backup, :except => { :no_release => true } do
123
- run "#{try_sudo} mkdir -p #{backups_path} #{tmp_backups_path} && #{try_sudo} chmod 775 #{backups_path} && #{try_sudo} chmod 775 #{tmp_backups_path}"
116
+ run "#{try_sudo} mkdir -p #{backups_path} #{tmp_backups_path} && #{try_sudo} chmod 775 #{backups_path} && #{try_sudo} chmod 775 #{tmp_backups_path} && #{try_sudo} chown -R #{user}:#{group} #{backups_path}"
124
117
  end
125
118
 
126
119
  desc <<-DESC
@@ -252,8 +245,8 @@ configuration.load do
252
245
  clean_tag = tag.gsub("/", "-")
253
246
 
254
247
  # Try to add tag to git
255
- if ! system "git tag #{release_name}"
256
- raise Capistrano::Error, "Failed to Git tag: #{release_name}"
248
+ if ! system "git tag #{clean_tag}"
249
+ raise Capistrano::Error, "Failed to Git tag: #{clean_tag}"
257
250
  end
258
251
  end
259
252
 
data/lib/demonz/common.rb CHANGED
@@ -44,7 +44,7 @@ end
44
44
 
45
45
  # Get release history from server as string
46
46
  def get_release_history(release_file)
47
- release_history = capture("cat #{release_file}").strip
47
+ release_history = remote_file_exists?(release_file) ? capture("cat #{release_file}").strip : ''
48
48
  release_history
49
49
  end
50
50
 
data/lib/demonz/drupal.rb CHANGED
@@ -194,6 +194,17 @@ configuration.load do
194
194
  end
195
195
  end
196
196
 
197
+ desc "Compile SASS (using Compass) for this release"
198
+ task :compile_sass, :roles => :web, :except => { :no_release => true } do
199
+ themes = fetch(:themes, [])
200
+ themes.each do |theme|
201
+ theme_path = File.join(latest_release, 'sites', 'all', 'themes', theme)
202
+ compass_config = File.join(theme_path, 'config.rb')
203
+ run "/bin/bash -c 'source ~/.bash_profile; cd #{theme_path}; compass clean;'"
204
+ run "/bin/bash -c 'source ~/.bash_profile; cd #{theme_path}; compass compile -c #{compass_config} --force --output-style compressed;'"
205
+ end
206
+ end
207
+
197
208
  desc "Symlink shared directories"
198
209
  task :symlink, :roles => :web, :except => { :no_release => true } do
199
210
  uses_boost = fetch(:uses_boost, false)
@@ -230,9 +241,13 @@ configuration.load do
230
241
 
231
242
  desc "Migrate old database to new release"
232
243
  task :migrate, :roles => :web, :except => { :no_release => true } do
244
+ uses_sass = fetch(:uses_sass, false)
245
+
233
246
  create_db
234
247
  copy_old_to_new_db
235
248
  run_update_scripts
249
+ compile_sass if uses_sass
250
+
236
251
  # Run drush updb just incase
237
252
  run "#{drush_bin} -r #{latest_release} updb"
238
253
  end
@@ -242,7 +257,7 @@ configuration.load do
242
257
  set :archive_name, "files_before_#{release_name}.tar.gz"
243
258
  set :files_dir_location, File.join(shared_path, 'default')
244
259
  logger.debug "Creating a Tarball of the files directory in #{backups_path}/#{archive_name}"
245
- run "cd #{files_dir_location} && tar -cvpf - files | gzip -c --best > #{backups_path}/#{archive_name}"
260
+ run "cd #{files_dir_location} && tar -cvpf - files | #{try_sudo} gzip -c --best > #{backups_path}/#{archive_name}"
246
261
  end
247
262
 
248
263
  desc "Clear all Drupal cache"
@@ -1,5 +1,5 @@
1
1
  module Capistrano
2
2
  module Demonz
3
- VERSION = "0.0.5"
3
+ VERSION = "0.0.6"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capistrano-demonz
3
3
  version: !ruby/object:Gem::Version
4
- hash: 21
4
+ hash: 19
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 5
10
- version: 0.0.5
9
+ - 6
10
+ version: 0.0.6
11
11
  platform: ruby
12
12
  authors:
13
13
  - Chinthaka Godawita
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-12-21 00:00:00 Z
18
+ date: 2013-01-08 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: railsless-deploy