sumodev_deploy 0.3 → 0.3.1

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.
@@ -0,0 +1,98 @@
1
+ Capistrano::Configuration.instance.load do
2
+ namespace :sumodev do
3
+ namespace :db do
4
+ def remote_db_name
5
+ production? && !fetch(:production_db, '').empty? ?
6
+ production_db :
7
+ db_name
8
+ end
9
+
10
+ def remote_db_options
11
+ {:db_host => 'host', :db_username => 'user', :db_password => 'password'}.inject('') do |options, (key, param)|
12
+ value = fetch(key, '')
13
+ options << "--#{param}=#{value} " unless value.empty?
14
+ options
15
+ end
16
+ end
17
+
18
+ desc "Create the database. Reads :db_name variable, or it is composed from client / project"
19
+ task :create, :roles => :db do
20
+ run "create_db #{db_name}"
21
+ end
22
+
23
+ desc "Get database info"
24
+ task :info, :roles => :db do
25
+ run "info_db #{db_name}"
26
+ end
27
+
28
+ desc "Dump the remote database, and outputs the content so you can pipe it"
29
+ task :dump, :roles => :db do
30
+ run "mysqldump --set-charset #{db_name}" do |ch, stream, out|
31
+ if stream == :err
32
+ ch[:options][:logger].send(:important, out, "#{stream} :: #{ch[:server]}" )
33
+ else
34
+ print out
35
+ end
36
+ end
37
+ end
38
+
39
+ desc "Imports the database from the server into your local database"
40
+ task :get, :roles => :db do
41
+ run_locally %{mysqladmin create #{db_name}} rescue nil
42
+
43
+ mysql = IO.popen("mysql #{db_name}", 'r+')
44
+ run "mysqldump --set-charset #{remote_db_options} #{remote_db_name}" do |ch, stream, out|
45
+ if stream == :err
46
+ ch[:options][:logger].send(:important, out, "#{stream} :: #{ch[:server]}" )
47
+ else
48
+ mysql.write out
49
+ end
50
+ end
51
+ mysql.close_write
52
+ puts mysql.read
53
+ mysql.close
54
+ end
55
+
56
+ desc "Imports the database from your local server to the remote one"
57
+ task :put, :roles => :db, :only => {:primary => true} do
58
+ begin
59
+ run("test ! -f #{db_lockfile}")
60
+ rescue
61
+ abort "Database has not been updated because the database has been locked"
62
+ end
63
+
64
+ force.put
65
+ end
66
+
67
+ namespace :force do
68
+ desc "Forced export of your local database to the remote server"
69
+ task :put do
70
+ run "mysqldump --set-charset #{db_name} > #{current_path}/#{release_name}.sql" rescue nil
71
+
72
+ dump = StringIO.new(run_locally "mysqldump --set-charset #{db_name}")
73
+ dump_path = "#{shared_path}/db_upload.tmp.sql"
74
+ upload dump, dump_path
75
+
76
+ run %{
77
+ mysql #{remote_db_options} #{remote_db_name} < #{dump_path} &&
78
+ rm #{dump_path}
79
+ }
80
+ end
81
+ end
82
+
83
+ desc "Locks the remote database from pushing"
84
+ task :lock, :roles => :db, :only => {:primary => true} do
85
+ run %{
86
+ echo #{release_name} > #{db_lockfile}
87
+ }
88
+ end
89
+
90
+ desc "Unlocks the remote database from pushing"
91
+ task :unlock, :roles => :db, :only => {:primary => true} do
92
+ run %{
93
+ rm #{db_lockfile}
94
+ }
95
+ end
96
+ end
97
+ end
98
+ end
@@ -0,0 +1,31 @@
1
+ Capistrano::Configuration.instance.load do
2
+ namespace :sumodev do
3
+ namespace :errbit do
4
+ task :after_deploy, :rolse => :app do
5
+ update_api_key
6
+ notify
7
+ end
8
+ desc "Updates the Errbit API key"
9
+ task :update_api_key, :roles => :app do
10
+ next if fetch(:production_errbit_api_key, "").empty?
11
+ run "if [ -f #{shared_path}/config/library/globals.php ]; then sed -i \"s/define('ERRBIT_API_KEY', '.*');/define('ERRBIT_API_KEY', '#{production_errbit_api_key}');/\" #{shared_path}/config/library/globals.php; fi"
12
+ end
13
+ desc "Notify Errbit about a dqeploy"
14
+ task :notify, :roles => :app do
15
+ next if fetch(:production_errbit_api_key, "").empty?
16
+ require 'active_support/core_ext/object'
17
+
18
+ parameters = {
19
+ :api_key => production_errbit_api_key,
20
+ :deploy => {
21
+ :rails_env => stage,
22
+ :local_username => ENV["USER"],
23
+ :scm_repository => repository,
24
+ :scm_revision => current_revision
25
+ }
26
+ }
27
+ run_locally "curl -d '#{parameters.to_query}' https://errors.sumocoders.be/deploys.txt"
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,58 @@
1
+ Capistrano::Configuration.instance.load do
2
+ namespace :sumodev do
3
+ namespace :files do
4
+ def find_folder_in_parents(folder)
5
+ require 'pathname'
6
+
7
+ path = Pathname.pwd
8
+ begin
9
+ found = Pathname.glob(path + folder)
10
+ return found.first if found.any?
11
+
12
+ path = path.parent
13
+ end until path.root?
14
+ end
15
+
16
+ def rsync(direction, from, to, options = {})
17
+ servers = find_servers_for_task(current_task)
18
+ servers = [servers.first] if options[:once]
19
+
20
+ servers.each do |server|
21
+ host_definition = "#{server.user || user}@#{server.host}"
22
+ host_definition << ":#{server.port}" if server.port && server.port != 22
23
+
24
+ case direction
25
+ when :down
26
+ run_locally "rsync -rtlpv #{host_definition}:#{from} #{to}"
27
+ when :up
28
+ run_locally "rsync -rtlp #{from} #{host_definition}:#{to}"
29
+ end
30
+ end
31
+ end
32
+
33
+ desc "Sync all remote files to your local install"
34
+ task :get, :roles => :app do
35
+ path = find_folder_in_parents('frontend/files')
36
+ if !path
37
+ abort "No frontend/files folder found in this or upper folders. Are you sure you're in a Fork project?"
38
+ else
39
+ rsync :down, shared_files_path, path, :once => true
40
+ end
41
+ end
42
+
43
+ desc "Sync your local files to the remote server"
44
+ task :put, :roles => :app do
45
+ # create a backup on the remote, store it under the release-folder, so it will be automagically removed
46
+ run %{cd #{shared_path} && tar -czf #{current_path}/backup_files.tgz files}
47
+
48
+ # check if folder exists
49
+ path = find_folder_in_parents('frontend/files')
50
+ if !path
51
+ abort "No frontend/files folder found in this or upper folders. Are you sure you're in a Fork project?"
52
+ else
53
+ rsync :up, "#{path}/", shared_files_path
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,28 @@
1
+ Capistrano::Configuration.instance.load do
2
+ namespace :sumodev do
3
+ namespace :redirect do
4
+ desc "Installs the redirect page for the site"
5
+ task :put, :roles => :app do
6
+ unless exists?(:production_url)
7
+ fetch(:production_url) do
8
+ Capistrano::CLI.ui.ask "What is the production url?"
9
+ end
10
+ end
11
+
12
+ run %{
13
+ mkdir -p #{shared_path}/redirect &&
14
+ wget --quiet -O #{shared_path}/redirect/index.php http://static.sumocoders.be/redirect/index.phps &&
15
+ wget --quiet -O #{shared_path}/redirect/.htaccess http://static.sumocoders.be/redirect/htaccess
16
+ }
17
+
18
+ # change the url
19
+ run "if [ -f #{shared_path}/redirect/index.php ]; then sed -i 's|<real-url>|#{production_url}|' #{shared_path}/redirect/index.php; fi"
20
+
21
+ run %{
22
+ rm -f #{current_path} &&
23
+ ln -s #{shared_path}/redirect #{current_path}
24
+ }
25
+ end
26
+ end
27
+ end
28
+ end
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "sumodev_deploy"
5
- s.version = "0.3"
5
+ s.version = "0.3.1"
6
6
 
7
7
  s.authors = ["Jan De Poorter"]
8
8
  s.date = "2012-04-18"
@@ -14,6 +14,10 @@ Gem::Specification.new do |s|
14
14
  s.files = [
15
15
  "sumodev_deploy.gemspec",
16
16
  "lib/sumodev_deploy.rb",
17
+ "lib/sumodev_deploy/tasks/db.rb",
18
+ "lib/sumodev_deploy/tasks/errbit.rb",
19
+ "lib/sumodev_deploy/tasks/files.rb",
20
+ "lib/sumodev_deploy/tasks/redirect.rb",
17
21
  ]
18
22
  s.homepage = "https://github.com/sumocoders/sumodev_deploy"
19
23
  s.require_paths = ["lib"]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sumodev_deploy
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.3'
4
+ version: 0.3.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -19,6 +19,10 @@ extra_rdoc_files: []
19
19
  files:
20
20
  - sumodev_deploy.gemspec
21
21
  - lib/sumodev_deploy.rb
22
+ - lib/sumodev_deploy/tasks/db.rb
23
+ - lib/sumodev_deploy/tasks/errbit.rb
24
+ - lib/sumodev_deploy/tasks/files.rb
25
+ - lib/sumodev_deploy/tasks/redirect.rb
22
26
  homepage: https://github.com/sumocoders/sumodev_deploy
23
27
  licenses: []
24
28
  post_install_message: