pvcglue 0.1.15 → 0.1.17

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 00890a0aee116c26c18b222c0300897a80cd6497
4
- data.tar.gz: 6c68aa88436df5bc55ba9fc0066a0720d976a79f
3
+ metadata.gz: 5317c0a638c5ddacd0a3ee767d7754caa2c04848
4
+ data.tar.gz: 7342a1125dcc1b35fcbb969043455bc8a99c734c
5
5
  SHA512:
6
- metadata.gz: 468eda830f2fd105ccd014bf5c4149d2f4c346ec273b707bf896579be248283806faf5fa779a24935c2ac804325c911f6bd6360dbd7db8955b7cba4c4529396b
7
- data.tar.gz: 65520aed3aead87f2789c8fb7714f93f88421db12720c2e1498b3c8f646e8c3498ee0d4483abc9e8983bbf30e22ee63fe6cf03e53f159aa3a3a874d4f5eeecab
6
+ metadata.gz: eac0304984a7caa026023d250da35441a8b95aa3e4755d9c5efc12175b8cee108f1ef5e96af81b4654028905f535f8ce99e72bd0695bf7fdf307a60f788c2838
7
+ data.tar.gz: a9e4d18207fe3eb2a920125ab4e2df1bf6174957b1f06b874096d62ae7b8d786798b0f17dd9851d2c21847b627d83cb65f068c06a2908d809dddbf6045d25e54
data/.gitignore CHANGED
@@ -1,3 +1,4 @@
1
+ /.idea
1
2
  *.gem
2
3
  *.rbc
3
4
  .bundle
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # PVC Glue
2
2
 
3
- Pico Virtual Cloud
3
+ Pico Virtual Cloud Glue creates a tightly integrated (very small) virtual cloud for your Rails application.
4
4
 
5
5
  An opinionated cloud application manager for Rails applications using your own servers.
6
6
 
@@ -158,7 +158,7 @@ Add these lines to your application's Gemfile. `dotenv-rails` must be listed fi
158
158
 
159
159
  Then add these lines to your application's Gemfile, whereever you like (usually at the end):
160
160
 
161
- gem 'pvcglue', "~> 0.1.12", :group => :development
161
+ gem 'pvcglue', "~> 0.1.15", :group => :development
162
162
  gem 'pvcglue_dbutils', "~> 0.5.3"
163
163
 
164
164
  And then execute:
data/bin/pvc CHANGED
@@ -4,11 +4,11 @@ require 'pvcglue/cli'
4
4
  # Allow use of Capistrano style environment syntax and convert to 'standard' syntax
5
5
  # Example: `pvc production bootstrap` ==> `pvc bootstrap --stage=production`
6
6
  # TODO: refactor to use a list of user specified environments
7
- if ARGV.count >= 2 && %w[alpha beta gamma delta preview production staging all].include?(ARGV[0])
7
+ if ARGV.count >= 2 && %w[local test alpha beta gamma delta preview production staging all].include?(ARGV[0])
8
8
  ARGV[0], ARGV[1] = ARGV[1], "--stage=#{ARGV[0]}"
9
9
  end
10
10
 
11
11
  # puts ARGV.inspect
12
12
 
13
13
  Pvcglue::CLI.start
14
- puts "Done."
14
+ puts "----- Done -----"
@@ -12,6 +12,7 @@ require "pvcglue/capistrano"
12
12
  require "pvcglue/ssl"
13
13
  require "pvcglue/db"
14
14
  require "pvcglue/toml_pvc_dumper.rb"
15
+ require "pvcglue/local.rb"
15
16
  require "tilt"
16
17
 
17
18
  # puts File.join(File.dirname(__FILE__), 'pvcglue', 'packages', '*.rb')
@@ -31,5 +31,9 @@ module Pvcglue
31
31
  def self.deploy
32
32
  system("cap #{Pvcglue.cloud.stage_name} deploy")
33
33
  end
34
+
35
+ def self.rake(params)
36
+ system("cap #{Pvcglue.cloud.stage_name} invoke[#{params.join(" ")}]")
37
+ end
34
38
  end
35
39
  end
@@ -148,6 +148,24 @@ module Pvcglue
148
148
  sh(server)
149
149
  end
150
150
 
151
+ desc "deploy", "deploy the app"
152
+ method_option :stage, :required => true, :aliases => "-s"
153
+
154
+ def deploy
155
+ Pvcglue::Capistrano.deploy
156
+ end
157
+
158
+ desc "rake", "run rake task on remote stage"
159
+ method_option :stage, :required => true, :aliases => "-s"
160
+
161
+ def rake(*tasks)
162
+ if Pvcglue.cloud.stage_name == 'production'
163
+ # if Pvcglue.cloud.stage_name == 'local'
164
+ raise(Thor::Error, "\nDidn't think so!\n") unless yes?("\n\nStop! Think! Are you sure you want to do this on the #{Pvcglue.cloud.stage_name} stage? (y/N)")
165
+ end
166
+ Pvcglue::Capistrano.rake(tasks)
167
+ end
168
+
151
169
  desc "pvcify", "update capistrano, database.yml and other configurations"
152
170
  method_option :stage, :required => true, :aliases => "-s"
153
171
 
@@ -156,12 +174,70 @@ module Pvcglue
156
174
  Pvcglue::Db.configure_database_yml
157
175
  end
158
176
 
159
- desc "deploy", "deploy the app"
177
+ desc "start", "start local virtual machines (build first, if required)"
160
178
  method_option :stage, :required => true, :aliases => "-s"
161
179
 
162
- def deploy
163
- Pvcglue::Capistrano.deploy
180
+ def start
181
+ Pvcglue::Local.start
182
+ end
183
+
184
+ desc "stop", "shut down local virtual machines"
185
+ method_option :stage, :required => true, :aliases => "-s"
186
+
187
+ def stop
188
+ Pvcglue::Local.stop
189
+ end
190
+
191
+ desc "restart", "stop and then start local virtual machines"
192
+ method_option :stage, :required => true, :aliases => "-s"
193
+
194
+ def restart
195
+ Pvcglue::Local.restart
196
+ end
197
+
198
+ desc "destroy", "destory local virtual machines"
199
+ method_option :stage, :required => true, :aliases => "-s"
200
+
201
+ def destroy
202
+ Pvcglue::Local.destroy
203
+ end
204
+
205
+ desc "suspend", "suspend local virtual machines"
206
+ method_option :stage, :required => true, :aliases => "-s"
207
+
208
+ def suspend
209
+ Pvcglue::Local.suspend
210
+ end
211
+
212
+ desc "status", "show status of local virtual machines"
213
+ method_option :stage, :required => true, :aliases => "-s"
214
+
215
+ def status
216
+ Pvcglue::Local.status
217
+ end
218
+
219
+ desc "kill", "force shutdown (power off) local virtual machines - may cause data corruption"
220
+ method_option :stage, :required => true, :aliases => "-s"
221
+
222
+ def kill
223
+ Pvcglue::Local.kill
224
+ end
225
+
226
+ desc "rebuild", "destroy, build and start local virtual machines"
227
+ method_option :stage, :required => true, :aliases => "-s"
228
+
229
+ def rebuild
230
+ Pvcglue::Local.rebuild
164
231
  end
232
+
233
+ desc "update_config", "debug use"
234
+ method_option :stage, :required => true, :aliases => "-s"
235
+
236
+ def update_config
237
+ Pvcglue::Local.update_local_config_from_cache
238
+ end
239
+
240
+
165
241
  end
166
242
 
167
243
  end
@@ -9,6 +9,7 @@ module Pvcglue
9
9
  class Configuration < Thor
10
10
 
11
11
  attr_accessor :cloud_manager
12
+ attr_accessor :local_cloud_manager
12
13
  attr_accessor :cloud_name
13
14
  attr_accessor :application_name
14
15
  attr_accessor :context
@@ -21,19 +22,36 @@ module Pvcglue
21
22
  ENV['PVCGLUE_ENV_PREFIX'] || 'PVCGLUE'
22
23
  end
23
24
 
25
+ def self.project_file_name
26
+ File.join(self.application_dir, file_name)
27
+ end
28
+
29
+ def self.application_dir
30
+ Dir.pwd
31
+ end
24
32
 
25
33
  # silence Thor warnings, as these are not Thor commands. (But we still need 'say' and 'ask' and friends.)
26
34
  no_commands do
27
35
 
28
36
  def initialize
29
- #ENV["PVCGLUE_#{'application_name'.upcase}"] = 'override'
30
- init(:cloud_manager) || configure_manager
31
- raise(Thor::Error, "The manager has not been configured. :(") if cloud_manager.nil?
37
+ if Pvcglue::Manager.local_mode?
38
+ init(:local_cloud_manager)
39
+ @cloud_manager = @local_cloud_manager
40
+ else
41
+ init(:cloud_manager) || configure_manager
42
+ end
43
+
44
+ # raise(Thor::Error, "The manager has not been configured. :(") if cloud_manager.nil?
45
+ raise("The manager has not been configured. :(") if cloud_manager.nil?
32
46
  init_except_manager
33
47
  end
34
48
 
35
49
  def init_except_manager
36
- init(:cloud_name, 'cluster_one')
50
+ if Pvcglue::Manager.local_mode?
51
+ @cloud_name = 'local_cloud'
52
+ else
53
+ init(:cloud_name, 'cluster_one')
54
+ end
37
55
  init(:application_name, find_app_name)
38
56
  end
39
57
 
@@ -84,17 +102,31 @@ module Pvcglue
84
102
  end
85
103
 
86
104
  def project_file_name
87
- File.join(application_dir, self.class.file_name)
105
+ self.class.project_file_name
88
106
  end
89
107
 
90
108
  def user_file_name
91
109
  File.join(Dir.home, self.class.file_name)
92
110
  end
93
111
 
112
+ # Thanks to http://stackoverflow.com/a/1509957/444774
113
+ def underscore(camel_cased_word)
114
+ camel_cased_word.to_s.gsub(/::/, '/').
115
+ gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2').
116
+ gsub(/([a-z\d])([A-Z])/, '\1_\2').
117
+ tr("-", "_").
118
+ downcase
119
+ end
120
+
94
121
  def find_app_name
95
- # try rack file...anyone know a better way, without loading Rails?
122
+ # try known files...anyone know a better way, without loading Rails?
96
123
  rack_up = File.join(application_dir, 'config.ru')
97
- $1.downcase if File.exists?(rack_up) && File.read(rack_up) =~ /^run (.*)::/
124
+ app_name = underscore($1) if File.exists?(rack_up) && File.read(rack_up) =~ /^run (.*)::/
125
+ unless app_name
126
+ file_name = File.join(application_dir, 'config', 'application.rb')
127
+ app_name = underscore($1) if File.exists?(file_name) && File.read(file_name) =~ /^module (.*)/
128
+ end
129
+ app_name
98
130
  end
99
131
 
100
132
  def options
@@ -118,7 +150,7 @@ module Pvcglue
118
150
  end
119
151
 
120
152
  def application_dir
121
- Dir.pwd
153
+ self.class.application_dir
122
154
  end
123
155
 
124
156
  def app_maintenance_files_dir
@@ -126,7 +158,7 @@ module Pvcglue
126
158
  end
127
159
 
128
160
  def ruby_version_file_name
129
- File.join(application_dir,'.ruby-version')
161
+ File.join(application_dir, '.ruby-version')
130
162
  end
131
163
 
132
164
  def ruby_version
@@ -0,0 +1,231 @@
1
+ module Pvcglue
2
+ class Local
3
+ MACHINES = %w(manager lb web web_2 db memcached)
4
+
5
+ def self.vagrant(command)
6
+ raise(Thor::Error, "This command can only be used for the 'local' and 'test' stages.") unless Pvcglue.cloud.stage_name.in? %w(local test)
7
+ raise(Thor::Error, "Vagrant (www.vagrantup.com) does not appear to be installed. :(") unless vagrant_available?
8
+ Bundler.with_clean_env { system("vagrant #{command}") }
9
+ end
10
+
11
+ def self.vagrant_available?
12
+ # puts Bundler.with_clean_env { `vagrant --version` }
13
+ Bundler.with_clean_env { `vagrant --version` } =~ /Vagrant \d+\.\d+\.\d+/
14
+ end
15
+
16
+ def self.start
17
+ if vagrant("up #{machines_in_stage}")
18
+ update_local_config(get_info_for_machines)
19
+ else
20
+ remove_cache_info_for_machines
21
+ raise(Thor::Error, "Error starting virtual machines. :(")
22
+ end
23
+ end
24
+
25
+ def self.machines_in_stage
26
+ "/#{Pvcglue.cloud.stage_name}-\\|manager/" # must escape '|' for shell
27
+ end
28
+
29
+ def self.update_local_config_from_cache
30
+ data = File.read(cache_file_name)
31
+ machines = JSON.parse(data)
32
+ update_local_config(machines)
33
+ end
34
+
35
+ def self.update_local_config(machines)
36
+ machines = machines.with_indifferent_access
37
+ Pvcglue::Manager.set_local_mode
38
+ manager_file_name = Pvcglue::Configuration.project_file_name
39
+ data = File.exists?(manager_file_name) ? TOML.load_file(manager_file_name) : {}
40
+ # puts data.inspect
41
+ # puts machines.inspect
42
+ # puts machines[:manager][:public_ip].inspect
43
+ manager_ip = machines[:manager][:public_ip].to_s # to_s in case it's nil
44
+ raise(Thor::Error, "Manager IP is not valid. :(") unless manager_ip =~ /\b(?:\d{1,3}\.){3}\d{1,3}\b/
45
+ data["local_cloud_manager"] = manager_ip
46
+ # data["#{Pvcglue.cloud.stage_name}_cloud_manager"] = manager_ip
47
+ File.write(manager_file_name, TOML.dump(data.stringify_keys))
48
+
49
+ app_name = Pvcglue.configuration.application_name
50
+ data = {}
51
+ data = TOML.load_file(::Pvcglue.cloud.local_file_name) if File.exists?(::Pvcglue.cloud.local_file_name)
52
+ data = TOML.load_file(Pvcglue.configuration.cloud_cache_file_name) if data.empty? && File.exists?(Pvcglue.configuration.cloud_cache_file_name)
53
+ # TODO: get repo_url from git, if possible
54
+ if data.empty?
55
+ data = {app_name =>
56
+ {"excluded_db_tables" => ["versions"],
57
+ "name" => app_name,
58
+ "repo_url" => "git@github.com:talyric/pvcglue-dev-box.git", # TODO: get with git
59
+ "ssh_allowed_from_all_port" => "22222",
60
+ "swapfile_size" => 128,
61
+ "time_zone" => "America/Los_Angeles",
62
+ "authorized_keys" => {"example" => File.read(File.expand_path('~/.ssh/id_rsa.pub'))}, # TODO: error checking
63
+ "dev_ip_addresses" => {"example" => "127.0.0.1"},
64
+ "gems" => {"delayed_job" => false, "whenever" => false},
65
+ "stages" =>
66
+ {"local" =>
67
+ {"db_rebuild" => true,
68
+ "domains" => ["#{app_name}.local"],
69
+ "ssl" => "none",
70
+ "roles" =>
71
+ {"caching" =>
72
+ {"memcached" => {"private_ip" => "0.0.0.0", "public_ip" => "0.0.0.0"}},
73
+ "db" => {"db" => {"private_ip" => "0.0.0.0", "public_ip" => "0.0.0.0"}},
74
+ "lb" =>
75
+ {"lb" =>
76
+ {"allow_public_access" => true,
77
+ "private_ip" => "0.0.0.0",
78
+ "public_ip" => "0.0.0.0"}},
79
+ "web" => {"web_1" => {"private_ip" => "0.0.0.0", "public_ip" => "0.0.0.0"}}}},
80
+ "test" =>
81
+ {"db_rebuild" => false,
82
+ "domains" => ["#{app_name}.test"],
83
+ "ssl" => "none",
84
+ "roles" =>
85
+ {"caching" =>
86
+ {"memcached" => {"private_ip" => "0.0.0.0", "public_ip" => "0.0.0.0"}},
87
+ "db" => {"db" => {"private_ip" => "0.0.0.0", "public_ip" => "0.0.0.0"}},
88
+ "lb" =>
89
+ {"lb" =>
90
+ {"allow_public_access" => true,
91
+ "private_ip" => "0.0.0.0",
92
+ "public_ip" => "0.0.0.0"}},
93
+ "web" =>
94
+ {"web_1" => {"private_ip" => "0.0.0.0", "public_ip" => "0.0.0.0"}}}}}}}
95
+ end
96
+ data = data.with_indifferent_access
97
+
98
+ # pp data
99
+ # pp machines
100
+ # puts "*"*80
101
+ # puts machines[:memcached][:public_ip].inspect
102
+ # puts "*"*80
103
+ # puts data[app_name].inspect
104
+ # puts "*"*80
105
+ # puts data[app_name][:stages].inspect
106
+ # puts "*"*80
107
+ # puts data[app_name][:stages][:local].inspect
108
+ # puts "*"*80
109
+ # puts data[app_name][:stages][:local][:roles].inspect
110
+ # puts "*"*80
111
+ # puts data[app_name][:stages][:local][:roles][:caching].inspect
112
+ # puts "*"*80
113
+ # puts data[app_name][:stages][:local][:roles][:caching][:memcached].inspect
114
+ # puts "*"*80
115
+ # puts data[app_name][:stages][:local][:roles][:caching][:memcached][:public_ip].inspect
116
+ # puts "*"*80
117
+ stage_name = Pvcglue.cloud.stage_name
118
+ data[app_name][:stages][stage_name][:roles][:caching][:memcached][:public_ip] = machines[:memcached][:public_ip]
119
+ data[app_name][:stages][stage_name][:roles][:caching][:memcached][:private_ip] = machines[:memcached][:private_ip]
120
+ data[app_name][:stages][stage_name][:roles][:db][:db][:public_ip] = machines[:db][:public_ip]
121
+ data[app_name][:stages][stage_name][:roles][:db][:db][:private_ip] = machines[:db][:private_ip]
122
+ data[app_name][:stages][stage_name][:roles][:lb][:lb][:public_ip] = machines[:lb][:public_ip]
123
+ data[app_name][:stages][stage_name][:roles][:lb][:lb][:private_ip] = machines[:lb][:private_ip]
124
+ data[app_name][:stages][stage_name][:roles][:web][:web_1][:public_ip] = machines[:web][:public_ip]
125
+ data[app_name][:stages][stage_name][:roles][:web][:web_1][:private_ip] = machines[:web][:private_ip]
126
+ # data[app_name][:stages][:local][:roles][:web][:web_2][:public_ip] = machines[:web_2][:public_ip]
127
+ # data[app_name][:stages][:local][:roles][:web][:web_2][:private_ip] = machines[:web_2][:private_ip]
128
+
129
+ Pvcglue.cloud.data = data
130
+ File.write(::Pvcglue.cloud.local_file_name, TOML.dump(Pvcglue.cloud.data))
131
+ File.write(Pvcglue.configuration.cloud_cache_file_name, TOML.dump(Pvcglue.cloud.data))
132
+ end
133
+
134
+ def self.stop
135
+ vagrant("halt #{machines_in_stage}")
136
+ end
137
+
138
+ def self.restart
139
+ vagrant("reload #{machines_in_stage}")
140
+ end
141
+
142
+ def self.rebuild
143
+ vagrant("destroy #{machines_in_stage} --force")
144
+ start
145
+ end
146
+
147
+ def self.destroy
148
+ vagrant("destroy #{machines_in_stage} --force")
149
+ end
150
+
151
+ def self.suspend
152
+ vagrant("suspend #{machines_in_stage}")
153
+ end
154
+
155
+ def self.kill
156
+ vagrant("halt #{machines_in_stage} --force")
157
+ end
158
+
159
+ def self.status
160
+ vagrant("status")
161
+ end
162
+
163
+ def self.remove_cache_info_for_machines
164
+ File.delete(cache_file_name)
165
+ end
166
+
167
+ =begin
168
+ 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default
169
+ link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
170
+ inet 127.0.0.1/8 scope host lo
171
+ valid_lft forever preferred_lft forever
172
+ inet6 ::1/128 scope host
173
+ valid_lft forever preferred_lft forever
174
+ 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
175
+ link/ether 08:00:27:e7:ab:02 brd ff:ff:ff:ff:ff:ff
176
+ inet 10.0.2.15/24 brd 10.0.2.255 scope global eth0
177
+ valid_lft forever preferred_lft forever
178
+ inet6 fe80::a00:27ff:fee7:ab02/64 scope link
179
+ valid_lft forever preferred_lft forever
180
+ 3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
181
+ link/ether 08:00:27:8e:64:5a brd ff:ff:ff:ff:ff:ff
182
+ inet 10.10.10.208/24 brd 10.10.10.255 scope global eth1
183
+ valid_lft forever preferred_lft forever
184
+ inet6 fe80::a00:27ff:fe8e:645a/64 scope link
185
+ valid_lft forever preferred_lft forever
186
+ 4: eth2: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
187
+ link/ether 08:00:27:9a:14:92 brd ff:ff:ff:ff:ff:ff
188
+ inet 172.28.128.3/24 brd 172.28.128.255 scope global eth2
189
+ valid_lft forever preferred_lft forever
190
+ inet6 fe80::a00:27ff:fe9a:1492/64 scope link
191
+ valid_lft forever preferred_lft forever
192
+ =end
193
+
194
+
195
+ def self.get_info_for_machines
196
+ machines = {}
197
+ MACHINES.each do |machine|
198
+ machines[machine] = {}
199
+ machine_name = machine == 'manager' ? machine : "#{Pvcglue.cloud.stage_name}-#{machine}"
200
+ puts "Getting networking info from #{machine_name}..."
201
+ data = `vagrant ssh #{machine_name} -c "ip a"`
202
+ puts data
203
+ data.scan(/inet (.*)\/.*global (eth[12])/) do |ip, eth|
204
+ type = eth == 'eth2' ? :private_ip : :public_ip
205
+ machines[machine][type] = ip
206
+ end
207
+ puts "Adding you public key to the root user for #{machine_name}..."
208
+ # cat ~/.ssh/id_rsa.pub | vagrant ssh manager -c 'sudo tee /root/.ssh/authorized_keys'
209
+ raise $? unless system %Q(cat ~/.ssh/id_rsa.pub | vagrant ssh #{machine_name} -c 'sudo tee /root/.ssh/authorized_keys')
210
+ end
211
+ FileUtils.mkdir_p(File.dirname(cache_file_name)) # the 'tmp' directory may not always exist
212
+ File.write(cache_file_name, machines.to_json)
213
+ machines
214
+ end
215
+
216
+ def self.cache_file_name
217
+ # TODO: Remove caching, maybe?
218
+ File.join(Pvcglue::Configuration.application_dir, 'tmp', 'pvcglue-machines.json')
219
+ end
220
+ end
221
+
222
+
223
+ # def self.local
224
+ # @local ||= Local.new
225
+ # end
226
+
227
+ # def self.local=(config)
228
+ # @local = config
229
+ # end
230
+
231
+ end
@@ -75,9 +75,31 @@ module Pvcglue
75
75
  Pvcglue.configuration.configure_manager
76
76
  end
77
77
 
78
+ desc "mode", "set mode (default or local)"
79
+
80
+ def mode(mode = "default")
81
+ raise(Thor::Error, "invalid manager mode :( (Hint: try 'default' or 'local'.)") unless mode.in?(%w(default local))
82
+ if mode == 'default' && Pvcglue::Manager.local_mode?
83
+ Pvcglue::Manager.set_default_mode
84
+ elsif mode == 'local' && !Pvcglue::Manager.local_mode?
85
+ Pvcglue::Manager.set_local_mode
86
+ else
87
+ puts "The manager is already set to the #{mode} mode."
88
+ end
89
+ end
90
+
78
91
  # ------------------------------------------------------------------------------------------------------------------
79
92
 
93
+ def self.set_local_mode
94
+ File.write(Pvcglue::Manager.mode_file_name, %q(description = "The existence of this file sets the pvcglue manager mode to 'local'. Use `pvc manager mode default` to reset."))
95
+ end
96
+
97
+ def self.set_default_mode
98
+ File.delete(Pvcglue::Manager.mode_file_name) if Pvcglue::Manager.local_mode?
99
+ end
100
+
80
101
  def self.initialize_cloud_data
102
+ # return if get_local_cloud_data
81
103
  unless read_cached_cloud_data
82
104
  Pvcglue::Packages.apply('manager-get-config'.to_sym, :manager, manager_node, 'pvcglue', 'manager')
83
105
  # Pvcglue::Packages.apply('manager-get-config'.to_sym, :manager, manager_node, 'pvcglue') # Can not use package as it causes infinite recursion, we'll just do it manually
@@ -94,6 +116,15 @@ module Pvcglue
94
116
  end
95
117
  end
96
118
 
119
+ # def self.get_local_cloud_data
120
+ # return unless Pvcglue.cloud.stage_name.in? %w(local test)
121
+ # puts "*"*80
122
+ # puts Pvcglue.cloud.stage_name
123
+ # puts "*"*80
124
+ # raise(Thor::Error, "stopped. :(")
125
+ #
126
+ # end
127
+
97
128
  def self.write_cloud_data_cache
98
129
  File.write(Pvcglue.configuration.cloud_cache_file_name, TOML.dump(Pvcglue.cloud.data))
99
130
  end
@@ -149,6 +180,14 @@ module Pvcglue
149
180
  clear_cloud_data_cache
150
181
  end
151
182
 
183
+ def self.local_mode?
184
+ File.exists?(Pvcglue::Manager.mode_file_name)
185
+ end
186
+
187
+ def self.mode_file_name
188
+ File.join(Pvcglue::Configuration.application_dir, '.pvcglue-manager-mode-local.toml')
189
+ end
190
+
152
191
  end
153
192
 
154
193
  end
@@ -7,6 +7,7 @@ package 'rvm' do
7
7
  end
8
8
 
9
9
  apply do
10
+ run 'gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3'
10
11
  run '\curl -sSL https://get.rvm.io | bash -s stable'
11
12
  run "rvm requirements"
12
13
  end
@@ -55,3 +55,7 @@ preview:
55
55
  production:
56
56
  <<: *default_settings
57
57
  database: <%= Pvcglue.cloud.app_name + '_production' %>
58
+
59
+ local:
60
+ <<: *default_settings
61
+ database: <%= Pvcglue.cloud.app_name + '_local' %>
@@ -9,6 +9,19 @@ set :linked_dirs, %w{log tmp/pids tmp/cache tmp/sockets}
9
9
 
10
10
  set :bundle_flags, '--deployment' # Remove the `--quiet` flag
11
11
 
12
+ # Thanks to marinosbern!
13
+ # From http://stackoverflow.com/a/22234123/444774
14
+ desc 'Invoke a rake command on the remote server--Example usage: cap staging invoke[db:migrate]'
15
+ task :invoke, [:command] => 'deploy:set_rails_env' do |task, args|
16
+ on primary(:app) do
17
+ within current_path do
18
+ with :rails_env => fetch(:rails_env) do
19
+ rake args[:command]
20
+ end
21
+ end
22
+ end
23
+ end
24
+
12
25
  namespace :deploy do
13
26
  <% if Pvcglue.cloud.gems[:delayed_job] %>
14
27
  def args
@@ -1,3 +1,3 @@
1
1
  module Pvcglue
2
- VERSION = "0.1.15"
2
+ VERSION = "0.1.17"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pvcglue
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.15
4
+ version: 0.1.17
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Lyric
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-17 00:00:00.000000000 Z
11
+ date: 2015-04-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -228,6 +228,7 @@ files:
228
228
  - lib/pvcglue/db.rb
229
229
  - lib/pvcglue/deploy.rb
230
230
  - lib/pvcglue/env.rb
231
+ - lib/pvcglue/local.rb
231
232
  - lib/pvcglue/manager.rb
232
233
  - lib/pvcglue/nodes.rb
233
234
  - lib/pvcglue/packages.rb