mina-data_sync 0.0.11 → 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.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/config/database.yml +2 -2
- data/config/deploy.rb +7 -168
- data/lib/mina/data_sync/helpers.rb +0 -31
- data/lib/mina/data_sync/tasks.rb +5 -8
- data/lib/mina/data_sync/version.rb +1 -1
- data/lib/mina/data_sync.rb +12 -5
- data/lib/mina/tasks/config.rake +26 -0
- metadata +3 -4
- data/config_pg/database.yml +0 -39
- data/config_pg/deploy.rb +0 -125
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3d58104d7068180adc905c2bd922ba4eee9666da
|
4
|
+
data.tar.gz: 3805c517428a3161f12fef18c5c2f2a5cdf4946a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: df60b6a711f9d35d993324a41036109390db09a4da859eebcfe1ec45c481b4fdd78191edd440f4fb7d838158392235ea92cff29a1f2bd6dc551cae053e88ab4a
|
7
|
+
data.tar.gz: 3f95e89310c6d1d7013e0243a3f97ec624af08922cd2793f3b57c48c7570031baf5884e0ec3cf20576fdda7f9a8133b6b9dfbe2891ab5fa126e16d45d1c65114
|
data/.gitignore
CHANGED
data/config/database.yml
CHANGED
@@ -11,7 +11,7 @@
|
|
11
11
|
development:
|
12
12
|
adapter: mysql2
|
13
13
|
encoding: utf8
|
14
|
-
database:
|
14
|
+
database: test
|
15
15
|
pool: 5
|
16
16
|
username: root
|
17
17
|
password:
|
@@ -43,4 +43,4 @@ staging:
|
|
43
43
|
database: psylog_staging_infinum_co
|
44
44
|
pool: 5
|
45
45
|
username: psylog_s
|
46
|
-
password: uRfbBD1S
|
46
|
+
password: uRfbBD1S
|
data/config/deploy.rb
CHANGED
@@ -4,174 +4,13 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
require 'mina/bundler'
|
5
5
|
require 'mina/rails'
|
6
6
|
require 'mina/git'
|
7
|
-
require 'mina/whenever' # uncomment if using whenever
|
8
7
|
require 'mina/data_sync'
|
9
8
|
|
9
|
+
set :repository, 'git@bitbucket.org:infinum_hr/rails-truck.git'
|
10
|
+
set :user, 'deploy'
|
11
|
+
set :domain, 'truck-ec2.infinum.co'
|
12
|
+
set :deploy_to, '/home/deploy/www/t/truck-staging.infinum.co'
|
13
|
+
set :rails_env, 'staging'
|
14
|
+
set :branch, 'master'
|
15
|
+
set :port, 22
|
10
16
|
|
11
|
-
# Setup project
|
12
|
-
# - mina production setup
|
13
|
-
# Deploy project
|
14
|
-
# - mina production deploy
|
15
|
-
# Tail log from project
|
16
|
-
# - mina prodution log
|
17
|
-
# Pull data from production
|
18
|
-
# - mina production data:pull
|
19
|
-
|
20
|
-
set :repository, 'git@bitbucket.org:infinum_hr/web_psylog.git'
|
21
|
-
set :user, 'legacy'
|
22
|
-
set :port, 22219
|
23
|
-
|
24
|
-
task :production do
|
25
|
-
set :domain, 'psylog.eu'
|
26
|
-
set :deploy_to, '/home/legacy/www/p/psylog.eu'
|
27
|
-
set :rails_env, 'production'
|
28
|
-
set :branch, 'master'
|
29
|
-
end
|
30
|
-
|
31
|
-
task :staging do
|
32
|
-
set :domain, 'psylog-staging.infinum.co'
|
33
|
-
set :deploy_to, '/home/legacy/www/p/psylog-staging.infinum.co'
|
34
|
-
set :rails_env, 'staging'
|
35
|
-
set :branch, 'master'
|
36
|
-
end
|
37
|
-
|
38
|
-
|
39
|
-
##################################################################################
|
40
|
-
########################## DO NOT EDIT THE CODE BELOW ############################
|
41
|
-
##################################################################################
|
42
|
-
|
43
|
-
set :shared_paths, ['log', 'pids']
|
44
|
-
|
45
|
-
task :deploy => :stages do
|
46
|
-
deploy do
|
47
|
-
to :default do
|
48
|
-
invoke :'git:clone'
|
49
|
-
invoke :'deploy:link_shared_paths'
|
50
|
-
invoke :'bundle:install'
|
51
|
-
invoke :'rails:db_migrate'
|
52
|
-
invoke :'rails:assets_precompile'
|
53
|
-
invoke :'deploy:cleanup'
|
54
|
-
end
|
55
|
-
|
56
|
-
to :launch do
|
57
|
-
# Capistrano to Mina Fix, symlink system to shared
|
58
|
-
queue! %[echo "-----> Symlink system to shared"]
|
59
|
-
queue! %[ln -nFs #{deploy_to}/shared/system #{deploy_to}/#{current_path}/public/system]
|
60
|
-
|
61
|
-
queue %[echo "-----> Restarting jobs"]
|
62
|
-
queue "RAILS_ENV=#{rails_env} #{deploy_to}/#{current_path}/bin/delayed_job restart --pid-dir=pids"
|
63
|
-
|
64
|
-
invoke :restart_application
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
# First ensure that the stage is selected
|
70
|
-
task :stages do
|
71
|
-
unless domain
|
72
|
-
print_error "A server needs to be specified. e.g. production/staging"
|
73
|
-
exit
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
# Just overwrote to execute stages first
|
78
|
-
task :setup => :stages do
|
79
|
-
queue! %[mkdir -p "#{deploy_to}/shared/log"]
|
80
|
-
queue! %[chmod g+rx,u+rwx "#{deploy_to}/shared/log"]
|
81
|
-
|
82
|
-
queue! %[mkdir -p "#{deploy_to}/shared/system"]
|
83
|
-
queue! %[chmod g+rx,u+rwx "#{deploy_to}/shared/system"]
|
84
|
-
end
|
85
|
-
|
86
|
-
# Import dummy data
|
87
|
-
task :import => :stages do
|
88
|
-
queue "bundle exec rake import:effects"
|
89
|
-
queue "bundle exec rake import:lifestyles"
|
90
|
-
queue "bundle exec rake import:medications"
|
91
|
-
queue "bundle exec rake import:users"
|
92
|
-
queue "bundle exec rake import:friendships"
|
93
|
-
end
|
94
|
-
|
95
|
-
task :import_effects => :stages do
|
96
|
-
queue "bundle exec rake import:effects"
|
97
|
-
end
|
98
|
-
|
99
|
-
task :import_lifestyles => :stages do
|
100
|
-
queue "bundle exec rake import:lifestyles"
|
101
|
-
end
|
102
|
-
|
103
|
-
task :import_medications => :stages do
|
104
|
-
queue "bundle exec rake import:medications"
|
105
|
-
end
|
106
|
-
|
107
|
-
task :import_users => :stages do
|
108
|
-
queue "bundle exec rake import:users"
|
109
|
-
end
|
110
|
-
|
111
|
-
task :import_friendships => :stages do
|
112
|
-
queue "bundle exec rake import:friendships"
|
113
|
-
end
|
114
|
-
|
115
|
-
# Tail log from server
|
116
|
-
task :log => :stages do
|
117
|
-
queue "tail -f #{deploy_to}/#{current_path}/log/#{rails_env}.log"
|
118
|
-
end
|
119
|
-
|
120
|
-
# Restart application after deployment
|
121
|
-
task :restart_application do
|
122
|
-
queue %[echo "-----> Restarting application"]
|
123
|
-
queue "mkdir -p #{deploy_to}/#{current_path}/tmp"
|
124
|
-
queue "touch #{deploy_to}/#{current_path}/tmp/restart.txt"
|
125
|
-
end
|
126
|
-
|
127
|
-
# Ping application
|
128
|
-
task :ping_application do
|
129
|
-
queue %[echo "-----> Ping domain"]
|
130
|
-
queue %[curl -s #{domain} > /dev/null]
|
131
|
-
end
|
132
|
-
|
133
|
-
# Stop delayed job
|
134
|
-
task :stop_delayed_job do
|
135
|
-
queue! %[echo "-----> Stop delayed job"]
|
136
|
-
queue! %[cd #{deploy_to}/#{current_path} ; RAILS_ENV=#{rails_env} bin/delayed_job stop]
|
137
|
-
end
|
138
|
-
|
139
|
-
# Start delayed job
|
140
|
-
task :start_delayed_job do
|
141
|
-
queue! %[echo "-----> Start delayed job"]
|
142
|
-
queue! %[cd #{deploy_to}/#{current_path} ; mkdir -p tmp/pids ; RAILS_ENV=#{rails_env} bin/delayed_job start]
|
143
|
-
end
|
144
|
-
|
145
|
-
# Restart delayed job
|
146
|
-
task :restart_delayed_job do
|
147
|
-
queue! %[echo "-----> Restart delayed job"]
|
148
|
-
queue! %[cd #{deploy_to}/#{current_path} ; RAILS_ENV=#{rails_env} bin/delayed_job restart]
|
149
|
-
end
|
150
|
-
|
151
|
-
# Sync database
|
152
|
-
RYAML = <<-BASH
|
153
|
-
function ryaml {
|
154
|
-
ruby -ryaml -e 'puts ARGV[1..-1].inject(YAML.load(File.read(ARGV[0]))) {|acc, key| acc[key] }' "$@"
|
155
|
-
};
|
156
|
-
BASH
|
157
|
-
|
158
|
-
namespace :data do
|
159
|
-
task :pull => :stages do
|
160
|
-
isolate do
|
161
|
-
queue RYAML
|
162
|
-
queue "HOST=$(ryaml #{deploy_to}/#{current_path}/config/database.yml #{rails_env} host)"
|
163
|
-
queue "DATABASE=$(ryaml #{deploy_to}/#{current_path}/config/database.yml #{rails_env} database)"
|
164
|
-
queue "USERNAME=$(ryaml #{deploy_to}/#{current_path}/config/database.yml #{rails_env} username)"
|
165
|
-
queue "PASSWORD=$(ryaml #{deploy_to}/#{current_path}/config/database.yml #{rails_env} password)"
|
166
|
-
queue "mysqldump $DATABASE --host=$HOST --user=$USERNAME --password=$PASSWORD > #{deploy_to}/dump.sql"
|
167
|
-
queue "gzip -f #{deploy_to}/dump.sql"
|
168
|
-
|
169
|
-
mina_cleanup!
|
170
|
-
end
|
171
|
-
|
172
|
-
%x[scp #{user}@#{domain}:#{deploy_to}/dump.sql.gz .]
|
173
|
-
%x[gunzip -f dump.sql.gz]
|
174
|
-
%x[#{RYAML} mysql --verbose --user=$(ryaml config/database.yml development username) --password=$(ryaml config/database.yml development password) $(ryaml config/database.yml development database) < dump.sql]
|
175
|
-
%x[rm dump.sql]
|
176
|
-
end
|
177
|
-
end
|
@@ -1,34 +1,3 @@
|
|
1
|
-
ARGUMENTS = <<-RUBY
|
2
|
-
dc = YAML.load(ERB.new(File.read(ARGV[0])).result)[ARGV[1]]
|
3
|
-
adapter = dc["adapter"]
|
4
|
-
database = dc["database"]
|
5
|
-
host = dc["host"]
|
6
|
-
username = dc["username"]
|
7
|
-
password = dc["password"]
|
8
|
-
port = dc["port"]
|
9
|
-
arguments = ""
|
10
|
-
case adapter.to_s
|
11
|
-
when "postgresql"
|
12
|
-
arguments += " -d " + database if database
|
13
|
-
arguments += " -h " + host if host
|
14
|
-
arguments += " -U " + username if username
|
15
|
-
arguments += " -p " + port.to_s if port
|
16
|
-
when "mysql2"
|
17
|
-
arguments += " " + database if database
|
18
|
-
arguments += " -h " + host if host
|
19
|
-
arguments += " -u " + username if username
|
20
|
-
arguments += " --password=" + password if password
|
21
|
-
arguments += " -P " + port.to_s if port
|
22
|
-
end
|
23
|
-
puts arguments
|
24
|
-
RUBY
|
25
|
-
|
26
|
-
CONF = <<-BASH
|
27
|
-
function conf {
|
28
|
-
ruby -ryaml -rerb -e '#{ARGUMENTS}' "$@"
|
29
|
-
};
|
30
|
-
BASH
|
31
|
-
|
32
1
|
def read_conf(path, rails_env)
|
33
2
|
@conf ||= YAML.load(ERB.new(File.read(path)).result)[rails_env]
|
34
3
|
end
|
data/lib/mina/data_sync/tasks.rb
CHANGED
@@ -8,10 +8,9 @@ namespace :data_sync do
|
|
8
8
|
|
9
9
|
queue "echo '-----> Dumping database'"
|
10
10
|
queue "cd #{deploy_to}/#{current_path}"
|
11
|
-
queue "#{
|
12
|
-
queue "ARGS=$(conf #{database_path} #{rails_env})"
|
11
|
+
queue "ARGS=$(#{rake} mina_data_sync:config)"
|
13
12
|
queue "mkdir -p #{remote_backup_path}"
|
14
|
-
queue!
|
13
|
+
queue! 'echo $ARGS'
|
15
14
|
queue! "#{dump} $ARGS #{options} > #{remote_backup_path}/#{backup_file}"
|
16
15
|
|
17
16
|
to :after_hook do
|
@@ -20,8 +19,8 @@ namespace :data_sync do
|
|
20
19
|
queue! "rsync --progress -e 'ssh -p #{port}' #{user}@#{domain}:#{deploy_to}/#{current_path}/#{remote_backup_path}/#{backup_file} #{local_backup_path}/#{backup_file}"
|
21
20
|
queue "echo '-----> Restoring database'"
|
22
21
|
if restore_data == 'true'
|
23
|
-
queue "#{
|
24
|
-
queue
|
22
|
+
queue "ARGS=$(#{rake} mina_data_sync:config)"
|
23
|
+
queue! 'echo $ARGS'
|
25
24
|
queue! "#{restore} $ARGS < #{local_backup_path}/#{backup_file}"
|
26
25
|
end
|
27
26
|
end
|
@@ -29,10 +28,9 @@ namespace :data_sync do
|
|
29
28
|
|
30
29
|
task push: :setup_sync do
|
31
30
|
set :term_mode, :pretty
|
32
|
-
|
31
|
+
|
33
32
|
to :before_hook do
|
34
33
|
queue "echo '-----> Dumping database'"
|
35
|
-
queue "#{CONF}"
|
36
34
|
queue "ARGS=$(conf #{database_path} development)"
|
37
35
|
queue! "#{dump} $ARGS #{options} > #{local_backup_path}/#{backup_file}"
|
38
36
|
queue "echo '-----> Copying backup'"
|
@@ -42,7 +40,6 @@ namespace :data_sync do
|
|
42
40
|
if restore_data == 'true'
|
43
41
|
queue "echo '-----> Restoring database'"
|
44
42
|
queue "cd #{deploy_to}/#{current_path}"
|
45
|
-
queue "#{CONF}"
|
46
43
|
queue "ARGS=$(conf #{database_path} #{rails_env})"
|
47
44
|
queue! "#{restore} $ARGS < #{deploy_to}/#{current_path}/#{remote_backup_path}/#{backup_file}"
|
48
45
|
end
|
data/lib/mina/data_sync.rb
CHANGED
@@ -1,12 +1,19 @@
|
|
1
1
|
require 'yaml'
|
2
2
|
require 'erb'
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
3
|
+
require 'mina/data_sync/defaults'
|
4
|
+
require 'mina/data_sync/helpers'
|
5
|
+
require 'mina/data_sync/version'
|
6
|
+
require 'mina/data_sync/tasks'
|
7
7
|
|
8
8
|
module Mina
|
9
9
|
module DataSync
|
10
|
-
|
10
|
+
if defined? Rails::Railtie
|
11
|
+
require 'rails'
|
12
|
+
class Railtie < Rails::Railtie
|
13
|
+
rake_tasks do
|
14
|
+
load 'tasks/config.rake'
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
11
18
|
end
|
12
19
|
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
namespace :mina_data_sync do
|
2
|
+
task config: :environment do
|
3
|
+
dc = ActiveRecord::Base.configurations[Rails.env].to_yaml
|
4
|
+
adapter = dc['adapter']
|
5
|
+
database = dc['database']
|
6
|
+
host = dc['host']
|
7
|
+
username = dc['username']
|
8
|
+
password = dc['password']
|
9
|
+
port = dc['port']
|
10
|
+
arguments = ''
|
11
|
+
case adapter.to_s
|
12
|
+
when 'postgresql'
|
13
|
+
arguments += ' -d ' + database if database
|
14
|
+
arguments += ' -h ' + host if host
|
15
|
+
arguments += ' -U ' + username if username
|
16
|
+
arguments += ' -p ' + port.to_s if port
|
17
|
+
when 'mysql2'
|
18
|
+
arguments += ' ' + database if database
|
19
|
+
arguments += ' -h ' + host if host
|
20
|
+
arguments += ' -u ' + username if username
|
21
|
+
arguments += ' --password=' + password if password
|
22
|
+
arguments += ' -P ' + port.to_s if port
|
23
|
+
end
|
24
|
+
puts arguments
|
25
|
+
end
|
26
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mina-data_sync
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stjepan Hadjic
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-02-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -80,13 +80,12 @@ files:
|
|
80
80
|
- Rakefile
|
81
81
|
- config/database.yml
|
82
82
|
- config/deploy.rb
|
83
|
-
- config_pg/database.yml
|
84
|
-
- config_pg/deploy.rb
|
85
83
|
- lib/mina/data_sync.rb
|
86
84
|
- lib/mina/data_sync/defaults.rb
|
87
85
|
- lib/mina/data_sync/helpers.rb
|
88
86
|
- lib/mina/data_sync/tasks.rb
|
89
87
|
- lib/mina/data_sync/version.rb
|
88
|
+
- lib/mina/tasks/config.rake
|
90
89
|
- mina-data_sync.gemspec
|
91
90
|
homepage: https://github.com/d4be4st/mina-data_sync
|
92
91
|
licenses:
|
data/config_pg/database.yml
DELETED
@@ -1,39 +0,0 @@
|
|
1
|
-
default: &default
|
2
|
-
adapter: postgresql
|
3
|
-
encoding: utf8
|
4
|
-
pool: 5
|
5
|
-
username: postgres
|
6
|
-
password:
|
7
|
-
host: localhost
|
8
|
-
|
9
|
-
rakovac: &rakovac
|
10
|
-
<<: *default
|
11
|
-
username: <%= ENV['PGSQL_USER'] %>
|
12
|
-
password: <%= ENV['PGSQL_PASSWORD'] %>
|
13
|
-
host: <%= ENV['PGSQL_HOST'] %>
|
14
|
-
port: <%= ENV['PGSQL_PORT'] %>
|
15
|
-
|
16
|
-
# development:
|
17
|
-
# adapter: mysql2
|
18
|
-
# encoding: utf8
|
19
|
-
# database: miramo_club_development
|
20
|
-
# pool: 5
|
21
|
-
# username: root
|
22
|
-
# password:
|
23
|
-
# host: localhost
|
24
|
-
|
25
|
-
development: &development
|
26
|
-
<<: *default
|
27
|
-
database: miramo_club_development
|
28
|
-
|
29
|
-
test:
|
30
|
-
<<: *default
|
31
|
-
database: miramo_club_test
|
32
|
-
|
33
|
-
production: &production
|
34
|
-
<<: *rakovac
|
35
|
-
database: miramo_infinum_co
|
36
|
-
|
37
|
-
staging:
|
38
|
-
<<: *rakovac
|
39
|
-
database: miramo_staging_infinum_co
|
data/config_pg/deploy.rb
DELETED
@@ -1,125 +0,0 @@
|
|
1
|
-
lib = File.expand_path('../../lib', __FILE__)
|
2
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
-
|
4
|
-
require 'mina/bundler'
|
5
|
-
require 'mina/rails'
|
6
|
-
require 'mina/git'
|
7
|
-
require 'pry'
|
8
|
-
require 'mina/data_sync'
|
9
|
-
# require 'mina/whenever' # uncomment if using whenever
|
10
|
-
|
11
|
-
# Setup project
|
12
|
-
# - mina production setup
|
13
|
-
# Deploy project
|
14
|
-
# - mina production deploy
|
15
|
-
# Tail log from project
|
16
|
-
# - mina prodution log
|
17
|
-
# Pull data from production
|
18
|
-
# - mina production data:pull
|
19
|
-
|
20
|
-
set :repository, 'git@bitbucket.org:infinum_hr/web_miramoclub.git'
|
21
|
-
set :local_backup_path, '/Users/stef/dev/databases/pg'
|
22
|
-
set :port, 22220
|
23
|
-
set :user, 'staging'
|
24
|
-
set :domain, 'miramo.infinum.co'
|
25
|
-
|
26
|
-
task :production do
|
27
|
-
set :deploy_to, '/home/staging/www/m/miramo.infinum.co'
|
28
|
-
set :rails_env, 'production'
|
29
|
-
set :branch, 'master'
|
30
|
-
set :bundle_withouts, 'development:test:staging'
|
31
|
-
end
|
32
|
-
|
33
|
-
# If you have
|
34
|
-
task :staging do
|
35
|
-
set :domain, 'miramo-club.infinum.co'
|
36
|
-
set :deploy_to, '/home/staging/www/m/miramo-staging.infinum.co'
|
37
|
-
set :rails_env, 'staging'
|
38
|
-
set :branch, 'develop'
|
39
|
-
set :bundle_withouts, 'development:test:production'
|
40
|
-
end
|
41
|
-
|
42
|
-
task :development do
|
43
|
-
set :rails_env, 'development'
|
44
|
-
end
|
45
|
-
##################################################################################
|
46
|
-
########################## DO NOT EDIT THE CODE BELOW ############################
|
47
|
-
##################################################################################
|
48
|
-
|
49
|
-
# While linking asssets it will only precompile that assets that was changed, not all of them
|
50
|
-
set :shared_paths, ['log']
|
51
|
-
|
52
|
-
task :deploy => :stages do
|
53
|
-
deploy do
|
54
|
-
invoke :'git:clone'
|
55
|
-
invoke :'deploy:link_shared_paths'
|
56
|
-
invoke :'bundle:install'
|
57
|
-
invoke :'rails:db_migrate'
|
58
|
-
invoke :'rails:assets_precompile'
|
59
|
-
invoke :'deploy:cleanup'
|
60
|
-
|
61
|
-
to :launch do
|
62
|
-
# Capistrano to Mina Fix, symlink system to shared
|
63
|
-
queue! %[echo "-----> Symlink system to shared"]
|
64
|
-
queue! %[ln -nFs #{deploy_to}/shared/system #{deploy_to}/#{current_path}/public/system]
|
65
|
-
|
66
|
-
#invoke :'whenever:update' # uncomment if using whenever (why here? read https://gist.github.com/gabskoro/abfc245a55a9d155f8de)
|
67
|
-
invoke :restart_application
|
68
|
-
end
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
# First ensure that the stage is selected
|
73
|
-
task :stages do
|
74
|
-
unless domain
|
75
|
-
print_error "A server needs to be specified. e.g. production/staging"
|
76
|
-
exit
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
# Just overwrote to execute stages first
|
81
|
-
task :setup => :stages do
|
82
|
-
queue! %[mkdir -p "#{deploy_to}/shared/log"]
|
83
|
-
queue! %[chmod g+rx,u+rwx "#{deploy_to}/shared/log"]
|
84
|
-
end
|
85
|
-
|
86
|
-
# Tail log from server
|
87
|
-
task :log => :stages do
|
88
|
-
queue "tail -f #{deploy_to}/#{current_path}/log/#{rails_env}.log"
|
89
|
-
end
|
90
|
-
|
91
|
-
# Restart application after deployment
|
92
|
-
task :restart_application do
|
93
|
-
queue %[echo "-----> Restarting application"]
|
94
|
-
queue "mkdir -p #{deploy_to}/#{current_path}/tmp"
|
95
|
-
queue "touch #{deploy_to}/#{current_path}/tmp/restart.txt"
|
96
|
-
end
|
97
|
-
|
98
|
-
namespace :data do
|
99
|
-
set :pretty_print, true
|
100
|
-
set :db_path, '/Users/stef/dev/databases'
|
101
|
-
|
102
|
-
# # Sync database
|
103
|
-
# RYAML = <<-BASH
|
104
|
-
# function ryaml {
|
105
|
-
# ruby -ryaml -e 'puts ARGV[1..-1].inject(YAML.load(File.read(ARGV[0]))) {|acc, key| acc[key] }' "$@"
|
106
|
-
# };
|
107
|
-
# BASH
|
108
|
-
|
109
|
-
task :pull => :stages do
|
110
|
-
queue RYAML
|
111
|
-
queue! "HOST=$(ryaml #{deploy_to}/#{current_path}/config/database.yml #{rails_env} host)"
|
112
|
-
queue! "DATABASE=$(ryaml #{deploy_to}/#{current_path}/config/database.yml #{rails_env} database)"
|
113
|
-
queue! "USERNAME=$(ryaml #{deploy_to}/#{current_path}/config/database.yml #{rails_env} username)"
|
114
|
-
queue! "PASSWORD=$(ryaml #{deploy_to}/#{current_path}/config/database.yml #{rails_env} password)"
|
115
|
-
queue! "mysqldump $DATABASE --host=$HOST --user=$USERNAME --password=$PASSWORD > #{deploy_to}/dump.sql"
|
116
|
-
queue! "gzip -f #{deploy_to}/dump.sql"
|
117
|
-
|
118
|
-
to :after_hook do
|
119
|
-
queue! "scp -P #{port} #{user}@#{domain}:#{deploy_to}/dump.sql.gz ."
|
120
|
-
queue! "gunzip -f dump.sql.gz"
|
121
|
-
queue! "#{RYAML} mysql --verbose --user=$(ryaml config/database.yml development username) --password=$(ryaml config/database.yml development password) $(ryaml config/database.yml development database) < dump.sql"
|
122
|
-
queue! "rm dump.sql"
|
123
|
-
end
|
124
|
-
end
|
125
|
-
end
|