silverstripe-deploy 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ gem 'capistrano'
5
+ gem 'railsless-deploy'
6
+
7
+ # Add dependencies to develop your gem here.
8
+ # Include everything needed to run rake, tests, features, etc.
9
+ group :development do
10
+ gem "bundler", "~> 1.0.0"
11
+ gem "jeweler", "~> 1.5.2"
12
+ end
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 timsnadden
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,19 @@
1
+ = silverstripe-deploy
2
+
3
+ Capistrano recipe for deploying Silverstripe sites.
4
+
5
+ == Contributing to silverstripe-deploy
6
+
7
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
8
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
9
+ * Fork the project
10
+ * Start a feature/bugfix branch
11
+ * Commit and push until you are happy with your contribution
12
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
13
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2011 timsnadden. See LICENSE.txt for
18
+ further details.
19
+
@@ -0,0 +1,27 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'rake'
11
+
12
+ require 'jeweler'
13
+ Jeweler::Tasks.new do |gem|
14
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
15
+ gem.name = "silverstripe-deploy"
16
+ gem.homepage = "http://github.com/timsnadden/silverstripe-deploy"
17
+ gem.license = "MIT"
18
+ gem.summary = "Silverstripe specific deployment recipes"
19
+ gem.description = "Silverstripe specific deployment recipes"
20
+ gem.email = "tim@snadden.com"
21
+ gem.authors = ["timsnadden"]
22
+ # Include your dependencies below. Runtime dependencies are required when using your gem,
23
+ # and development dependencies are only needed for development (ie running rake tasks, tests, etc)
24
+ gem.add_runtime_dependency 'capistrano', '>= 2.4'
25
+ gem.add_runtime_dependency 'railsless-deploy', '>= 1.0.2'
26
+ gem.add_development_dependency 'jeweler', '> 1.2.3'
27
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.5
@@ -0,0 +1,147 @@
1
+ Capistrano::Configuration.instance(:must_exist).load do
2
+
3
+ ############################################################################
4
+ # These variables MUST be set in the client capfiles. If they are not set,
5
+ # the deploy will fail with an error.
6
+ ############################################################################
7
+ _cset(:application) { abort "Please specify the name of your application, e.g. set :app_name, 'dna.co.nz'" }
8
+ _cset(:deploy_to) { abort "Please specify the deployment path, e.g. set :deploy_to, '/srv/www'" }
9
+ _cset(:repository) { abort "Please specify the repository URL. e.g. set :repository, 'http://svn.dna.co.nz/dna/internal/open/trunk'" }
10
+
11
+ ############################################################################
12
+ # These variables may be set in the client capfile if their default values
13
+ # are not sufficient.
14
+ ############################################################################
15
+ _cset(:apache_user) { "apache" }
16
+ _cset(:apache_group) { "apache" }
17
+ _cset(:keep_releases) { 3 }
18
+ _cset(:db_backup_dir) { "#{deploy_to}/db-backup" }
19
+ _cset(:local_db_user) { 'root' }
20
+ _cset(:local_db_password) { 'root' }
21
+ _cset(:tmp_dir) { '/tmp' }
22
+ _cset(:deploy_via) { :remote_cache }
23
+ default_run_options[:pty] = true
24
+
25
+
26
+ ############################################################################
27
+ # These variables are set via user input
28
+ ############################################################################
29
+ _cset(:user) { Capistrano::CLI.ui.ask("Enter server username: ") }
30
+ _cset(:db_password) { Capistrano::CLI.ui.ask("Enter mysql password: ") }
31
+
32
+ ############################################################################
33
+ # These variables are set by inspecting silverstripe config
34
+ ############################################################################
35
+ _cset(:db_name) {
36
+ configstring = capture "grep '^$database' #{current_path}/mysite/_config.php"
37
+ if configstring =~ /['"](.*)['"]/
38
+ $1
39
+ else
40
+ abort "Couldn't get :db_name from mysite/_config.php"
41
+ end
42
+ }
43
+
44
+ ############################################################################
45
+ # Utility Functions
46
+ ############################################################################
47
+
48
+ def remote_file_exists?(full_path)
49
+ 'true' == capture("if [ -e #{full_path} ]; then echo 'true'; fi").strip
50
+ end
51
+
52
+ ############################################################################
53
+ # Recipes
54
+ ############################################################################
55
+
56
+ namespace :deploy do
57
+ task :update do
58
+ transaction do
59
+ update_code
60
+ remove_dev_files
61
+ file_2_url
62
+ symlink_assets
63
+ symlink
64
+ end
65
+ end
66
+ task :symlink_assets do
67
+ run "ln -nsf #{shared_path}/assets #{latest_release}/assets"
68
+ end
69
+ task :remove_dev_files do
70
+ if remote_file_exists?("#{latest_release}/_ss_environment.php")
71
+ run "rm #{latest_release}/_ss_environment.php"
72
+ end
73
+ if remote_file_exists?("#{latest_release}/capfile")
74
+ run "rm #{latest_release}/capfile"
75
+ end
76
+ end
77
+ task :file_2_url do
78
+ run "echo \"\<\?php \\$_FILE_TO_URL_MAPPING\[\'#{latest_release}\'\] = \'http://#{application}/\'\;\" > #{deploy_to}/file2url.php"
79
+ end
80
+ task :fix_cache do
81
+ set :cache_name, latest_release.gsub( "/", "-" )
82
+ run "#{sudo} cp #{tmp_dir}/silverstripe-cache#{cache_name}/manifest-cli-script #{tmp_dir}/silverstripe-cache#{cache_name}/manifest-main"
83
+ run "#{sudo} chown -R #{apache_user}:#{apache_group} #{tmp_dir}/silverstripe-cache#{cache_name}"
84
+ end
85
+ task :rebuild_hometemplate do
86
+ run "cd #{latest_release}; sake / flush=all"
87
+ run "curl http://#{application}/"
88
+ end
89
+ task :cleanup_cache do
90
+ set :cache_name, deploy_to.gsub( "/", "-" )
91
+ existing_cache_dirs = capture("ls #{tmp_dir} | grep silverstripe-cache#{cache_name}-releases")
92
+ existing_cache_dirs.each { |dir|
93
+ run "echo #{dir}"
94
+ }
95
+ end
96
+ end
97
+
98
+ namespace :db do
99
+ task :backup do
100
+ run "mysqldump -u#{user} -p#{db_password} #{db_name} > #{db_backup_dir}/#{application}-#{release_name}.sql"
101
+ end
102
+ task :build do
103
+ run "cd #{latest_release}; sake dev/build flush=1"
104
+ end
105
+ task :cleanup do
106
+ count = fetch(:keep_releases, 5).to_i
107
+ existing_backups = capture("ls #{db_backup_dir} | wc -l").to_i
108
+
109
+ if count >= existing_backups
110
+ logger.info "no old db backups to clean up"
111
+ else
112
+ logger.info "removing db backups"
113
+ files = capture("ls -t1 #{db_backup_dir} | tail -n +#{keep_releases+1}")
114
+ files.each { |file|
115
+ run "rm #{db_backup_dir}/#{file}"
116
+ }
117
+ end
118
+ end
119
+ end
120
+
121
+ namespace :sync do
122
+ task :default do
123
+ assets
124
+ database
125
+ end
126
+
127
+ desc "Mirrors the remote shared assets directory with local copy"
128
+ task :assets do
129
+ run_locally("rsync -avzP #{user}@#{application}:#{shared_path}/assets/ assets/")
130
+ end
131
+
132
+ desc "Copy production database dump to local machine, import into local development database"
133
+ task :database do
134
+ dump_file = capture("ls -1 #{db_backup_dir} | tail -n 1").rstrip
135
+ run_locally "scp #{user}@#{application}:#{db_backup_dir}/#{dump_file} ."
136
+ run_locally "mysql -u#{local_db_user} -p#{local_db_password} #{db_name} < #{dump_file}"
137
+ end
138
+ end
139
+
140
+ before("deploy:update", "db:backup")
141
+ before("deploy:symlink", "db:build")
142
+ after("db:build", "deploy:rebuild_hometemplate")
143
+ after("db:build", "deploy:fix_cache")
144
+ after("deploy:cleanup", "db:cleanup")
145
+ before("sync:database", "db:backup")
146
+
147
+ end
@@ -0,0 +1,71 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{silverstripe-deploy}
8
+ s.version = "0.0.5"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = [%q{timsnadden}]
12
+ s.date = %q{2011-08-19}
13
+ s.description = %q{Silverstripe specific deployment recipes}
14
+ s.email = %q{tim@snadden.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ "Gemfile",
22
+ "LICENSE.txt",
23
+ "README.rdoc",
24
+ "Rakefile",
25
+ "VERSION",
26
+ "lib/silverstripe-deploy.rb",
27
+ "silverstripe-deploy.gemspec",
28
+ "test/helper.rb",
29
+ "test/test_silverstripe-deploy.rb"
30
+ ]
31
+ s.homepage = %q{http://github.com/timsnadden/silverstripe-deploy}
32
+ s.licenses = [%q{MIT}]
33
+ s.require_paths = [%q{lib}]
34
+ s.rubygems_version = %q{1.8.8}
35
+ s.summary = %q{Silverstripe specific deployment recipes}
36
+ s.test_files = [
37
+ "test/helper.rb",
38
+ "test/test_silverstripe-deploy.rb"
39
+ ]
40
+
41
+ if s.respond_to? :specification_version then
42
+ s.specification_version = 3
43
+
44
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
45
+ s.add_runtime_dependency(%q<capistrano>, [">= 0"])
46
+ s.add_runtime_dependency(%q<railsless-deploy>, [">= 0"])
47
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
48
+ s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
49
+ s.add_runtime_dependency(%q<capistrano>, [">= 2.4"])
50
+ s.add_runtime_dependency(%q<railsless-deploy>, [">= 1.0.2"])
51
+ s.add_development_dependency(%q<jeweler>, ["> 1.2.3"])
52
+ else
53
+ s.add_dependency(%q<capistrano>, [">= 0"])
54
+ s.add_dependency(%q<railsless-deploy>, [">= 0"])
55
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
56
+ s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
57
+ s.add_dependency(%q<capistrano>, [">= 2.4"])
58
+ s.add_dependency(%q<railsless-deploy>, [">= 1.0.2"])
59
+ s.add_dependency(%q<jeweler>, ["> 1.2.3"])
60
+ end
61
+ else
62
+ s.add_dependency(%q<capistrano>, [">= 0"])
63
+ s.add_dependency(%q<railsless-deploy>, [">= 0"])
64
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
65
+ s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
66
+ s.add_dependency(%q<capistrano>, [">= 2.4"])
67
+ s.add_dependency(%q<railsless-deploy>, [">= 1.0.2"])
68
+ s.add_dependency(%q<jeweler>, ["> 1.2.3"])
69
+ end
70
+ end
71
+
@@ -0,0 +1,18 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'test/unit'
11
+ require 'shoulda'
12
+
13
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
14
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
15
+ require 'silverstripe-deploy'
16
+
17
+ class Test::Unit::TestCase
18
+ end
@@ -0,0 +1,7 @@
1
+ require 'helper'
2
+
3
+ class TestSilverstripeDeploy < Test::Unit::TestCase
4
+ should "probably rename this file and start testing for real" do
5
+ flunk "hey buddy, you should probably rename this file and start testing for real"
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,182 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: silverstripe-deploy
3
+ version: !ruby/object:Gem::Version
4
+ hash: 21
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 5
10
+ version: 0.0.5
11
+ platform: ruby
12
+ authors:
13
+ - timsnadden
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-08-19 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ requirement: &id001 !ruby/object:Gem::Requirement
22
+ none: false
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ hash: 3
27
+ segments:
28
+ - 0
29
+ version: "0"
30
+ version_requirements: *id001
31
+ name: capistrano
32
+ prerelease: false
33
+ type: :runtime
34
+ - !ruby/object:Gem::Dependency
35
+ requirement: &id002 !ruby/object:Gem::Requirement
36
+ none: false
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ hash: 3
41
+ segments:
42
+ - 0
43
+ version: "0"
44
+ version_requirements: *id002
45
+ name: railsless-deploy
46
+ prerelease: false
47
+ type: :runtime
48
+ - !ruby/object:Gem::Dependency
49
+ requirement: &id003 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ hash: 23
55
+ segments:
56
+ - 1
57
+ - 0
58
+ - 0
59
+ version: 1.0.0
60
+ version_requirements: *id003
61
+ name: bundler
62
+ prerelease: false
63
+ type: :development
64
+ - !ruby/object:Gem::Dependency
65
+ requirement: &id004 !ruby/object:Gem::Requirement
66
+ none: false
67
+ requirements:
68
+ - - ~>
69
+ - !ruby/object:Gem::Version
70
+ hash: 7
71
+ segments:
72
+ - 1
73
+ - 5
74
+ - 2
75
+ version: 1.5.2
76
+ version_requirements: *id004
77
+ name: jeweler
78
+ prerelease: false
79
+ type: :development
80
+ - !ruby/object:Gem::Dependency
81
+ requirement: &id005 !ruby/object:Gem::Requirement
82
+ none: false
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ hash: 11
87
+ segments:
88
+ - 2
89
+ - 4
90
+ version: "2.4"
91
+ version_requirements: *id005
92
+ name: capistrano
93
+ prerelease: false
94
+ type: :runtime
95
+ - !ruby/object:Gem::Dependency
96
+ requirement: &id006 !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ hash: 19
102
+ segments:
103
+ - 1
104
+ - 0
105
+ - 2
106
+ version: 1.0.2
107
+ version_requirements: *id006
108
+ name: railsless-deploy
109
+ prerelease: false
110
+ type: :runtime
111
+ - !ruby/object:Gem::Dependency
112
+ requirement: &id007 !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ">"
116
+ - !ruby/object:Gem::Version
117
+ hash: 25
118
+ segments:
119
+ - 1
120
+ - 2
121
+ - 3
122
+ version: 1.2.3
123
+ version_requirements: *id007
124
+ name: jeweler
125
+ prerelease: false
126
+ type: :development
127
+ description: Silverstripe specific deployment recipes
128
+ email: tim@snadden.com
129
+ executables: []
130
+
131
+ extensions: []
132
+
133
+ extra_rdoc_files:
134
+ - LICENSE.txt
135
+ - README.rdoc
136
+ files:
137
+ - .document
138
+ - Gemfile
139
+ - LICENSE.txt
140
+ - README.rdoc
141
+ - Rakefile
142
+ - VERSION
143
+ - lib/silverstripe-deploy.rb
144
+ - silverstripe-deploy.gemspec
145
+ - test/helper.rb
146
+ - test/test_silverstripe-deploy.rb
147
+ homepage: http://github.com/timsnadden/silverstripe-deploy
148
+ licenses:
149
+ - MIT
150
+ post_install_message:
151
+ rdoc_options: []
152
+
153
+ require_paths:
154
+ - lib
155
+ required_ruby_version: !ruby/object:Gem::Requirement
156
+ none: false
157
+ requirements:
158
+ - - ">="
159
+ - !ruby/object:Gem::Version
160
+ hash: 3
161
+ segments:
162
+ - 0
163
+ version: "0"
164
+ required_rubygems_version: !ruby/object:Gem::Requirement
165
+ none: false
166
+ requirements:
167
+ - - ">="
168
+ - !ruby/object:Gem::Version
169
+ hash: 3
170
+ segments:
171
+ - 0
172
+ version: "0"
173
+ requirements: []
174
+
175
+ rubyforge_project:
176
+ rubygems_version: 1.8.8
177
+ signing_key:
178
+ specification_version: 3
179
+ summary: Silverstripe specific deployment recipes
180
+ test_files:
181
+ - test/helper.rb
182
+ - test/test_silverstripe-deploy.rb