engineyard 2.2.1 → 2.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -37,7 +37,7 @@ describe "ey deploy" do
37
37
  cmd << "--account" << opts[:account] if opts[:account]
38
38
  cmd << "--ref" << opts[:ref] if opts[:ref]
39
39
  cmd << "--migrate" if opts[:migrate]
40
- cmd << opts[:migrate] if opts[:migrate].respond_to?(:str)
40
+ cmd << opts[:migrate] if opts[:migrate].respond_to?(:to_str)
41
41
  cmd << "--no-migrate" if opts[:migrate] == nil
42
42
  cmd << "--verbose" if opts[:verbose]
43
43
  cmd
@@ -108,12 +108,7 @@ describe "ey deploy" do
108
108
  login_scenario "one app, one environment"
109
109
  end
110
110
 
111
- it "finds engineyard-serverside despite its being buried in the filesystem" do
112
- fast_ey %w[deploy --no-migrate]
113
- @ssh_commands.last.should =~ %r{/usr/local/ey_resin/ruby/bin/engineyard-serverside}
114
- end
115
-
116
- context "without migrate sepecified, interactively reads migration command" do
111
+ context "no ey.yml" do
117
112
  def clean_ey_yml
118
113
  File.unlink 'ey.yml' if File.exist?('ey.yml')
119
114
  FileUtils.rm_r 'config' if FileTest.exist?('config')
@@ -122,48 +117,16 @@ describe "ey deploy" do
122
117
  before { clean_ey_yml }
123
118
  after { clean_ey_yml }
124
119
 
125
- it "defaults to yes, and then rake db:migrate (and installs to config/ey.yml if config/ exists already)" do
126
- ey_yml = Pathname.new('config/ey.yml')
127
- File.exist?('ey.yml').should be_false
128
- ey_yml.dirname.mkpath
129
- ey_yml.should_not be_exist
130
- ey(%w[deploy]) do |input|
131
- input.puts('')
132
- input.puts('')
133
- end
134
- @ssh_commands.last.should =~ /engineyard-serverside.*deploy/
135
- @ssh_commands.last.should =~ /--migrate 'rake db:migrate'/
136
- File.exist?('ey.yml').should be_false
137
- ey_yml.should be_exist
138
- env_conf = read_yaml(ey_yml.to_s)['defaults']
139
- env_conf['migrate'].should == true
140
- env_conf['migration_command'].should == 'rake db:migrate'
120
+ it "tells you to run ey init" do
121
+ fast_failing_ey %w[deploy]
122
+ @err.should match(/ey init/)
123
+ @ssh_commands.should be_empty
141
124
  end
142
125
 
143
- it "accepts new commands" do
144
- File.exist?('ey.yml').should be_false
145
- FileTest.exist?('config').should be_false
146
- ey(%w[deploy], :hide_err => true) do |input|
147
- input.puts("y")
148
- input.puts("ruby migrate")
149
- end
150
- @ssh_commands.last.should =~ /engineyard-serverside.*deploy/
151
- @ssh_commands.last.should =~ /--migrate 'ruby migrate'/
152
- File.exist?('ey.yml').should be_true
153
- env_conf = read_yaml('ey.yml')['defaults']
154
- env_conf['migrate'].should == true
155
- env_conf['migration_command'].should == 'ruby migrate'
156
- end
157
-
158
- it "doesn't ask for the command if you say no" do
159
- File.exist?('ey.yml').should be_false
160
- ey(%w[deploy], :hide_err => true) do |input|
161
- input.puts("no")
162
- end
163
- @ssh_commands.last.should =~ /engineyard-serverside.*deploy/
164
- @ssh_commands.last.should_not =~ /--migrate/
165
- File.exist?('ey.yml').should be_true
166
- read_yaml('ey.yml')['defaults']['migrate'].should == false
126
+ it "tells you to run ey init" do
127
+ fast_failing_ey %w[deploy --migrate]
128
+ @err.should match(/ey init/)
129
+ @ssh_commands.should be_empty
167
130
  end
168
131
  end
169
132
 
@@ -173,40 +136,48 @@ describe "ey deploy" do
173
136
  @ssh_commands.last.should_not =~ /--migrate/
174
137
  end
175
138
 
176
- it "uses the default when --migrate is specified with no value" do
177
- fast_ey %w[deploy --migrate]
178
- @ssh_commands.last.should match(/--migrate 'rake db:migrate'/)
139
+ it "runs the migrate command when one is given" do
140
+ fast_ey ['deploy', '--migrate', 'thor fancy:migrate']
141
+ @ssh_commands.last.should match(/--migrate 'thor fancy:migrate'/)
179
142
  end
180
143
 
181
- context "customized in ey.yml with defaults" do
182
- before { write_yaml({"defaults" => { "migration_command" => "thor fancy:migrate"}}, 'ey.yml') }
144
+ context "ey.yml migrate only" do
145
+ before { write_yaml({"defaults" => {"migrate" => true}}, 'ey.yml') }
183
146
  after { File.unlink 'ey.yml' }
184
147
 
185
- it "migrates with the custom command by default (and fixes ey.yml to reflect the previous default behavior)" do
186
- fast_ey %w[deploy]
187
- @ssh_commands.last.should =~ /--migrate 'thor fancy:migrate'/
188
- read_yaml('ey.yml')['defaults']['migrate'].should == true
148
+ it "tells you to run ey init" do
149
+ fast_failing_ey %w[deploy]
150
+ @err.should match(/ey init/)
189
151
  end
190
152
  end
191
153
 
192
- context "customized in ey.yml with environment specific options overriding the defaults" do
154
+ context "ey.yml migration_command only" do
155
+ before { write_yaml({"defaults" => {"migration_command" => "thor fancy:migrate"}}, 'ey.yml') }
156
+ after { File.unlink 'ey.yml' }
157
+
158
+ it "tells you to run ey init" do
159
+ fast_failing_ey %w[deploy]
160
+ @err.should match(/ey init/)
161
+ end
162
+ end
163
+
164
+ context "ey.yml with environment specific options overriding the defaults" do
193
165
  before do
194
166
  write_yaml({
195
- "defaults" => { "migration_command" => "rake plain:migrate"},
167
+ "defaults" => { "migrate" => true, "migration_command" => "rake plain:migrate"},
196
168
  "environments" => {"giblets" => { "migration_command" => 'thor fancy:migrate' }}
197
169
  }, 'ey.yml')
198
170
  end
199
171
  after { File.unlink 'ey.yml' }
200
172
 
201
- it "migrates with the custom command by default (and fixes ey.yml for the specific environment to reflect the previous default behavior)" do
173
+ it "migrates with the custom command" do
202
174
  fast_ey %w[deploy]
203
175
  @ssh_commands.last.should =~ /--migrate 'thor fancy:migrate'/
204
- read_yaml('ey.yml')['defaults']['migrate'].should == true
205
176
  end
206
177
  end
207
178
 
208
179
  context "disabled in ey.yml" do
209
- before { write_yaml({"environments" => {"giblets" => {"migrate" => false}}}, 'ey.yml') }
180
+ before { write_yaml({"defaults" => {"migrate" => false}}, 'ey.yml') }
210
181
  after { File.unlink 'ey.yml' }
211
182
 
212
183
  it "does not migrate by default" do
@@ -220,25 +191,14 @@ describe "ey deploy" do
220
191
  @ssh_commands.last.should =~ /--migrate 'rake fancy:migrate'/
221
192
  end
222
193
 
223
- it "migrates with the default when --migrate is specified with no value" do
224
- fast_ey %w[deploy --migrate]
225
- @ssh_commands.last.should match(/--migrate 'rake db:migrate'/)
226
- end
227
- end
228
-
229
- context "explicitly enabled in ey.yml (the default)" do
230
- before { write_yaml({"environments" => {"giblets" => {"migrate" => true}}}, 'ey.yml') }
231
- after { File.unlink 'ey.yml' }
232
-
233
- it "migrates with the default (and writes the default to ey.yml)" do
234
- fast_ey %w[deploy]
235
- @ssh_commands.last.should match(/--migrate 'rake db:migrate'/)
236
- read_yaml('ey.yml')['defaults']['migration_command'].should == 'rake db:migrate'
194
+ it "tells you to initialize ey.yml when --migrate is specified with no value" do
195
+ fast_failing_ey %w[deploy --migrate]
196
+ @err.should match(/ey init/)
237
197
  end
238
198
  end
239
199
 
240
200
  context "customized and disabled in ey.yml" do
241
- before { write_yaml({"environments" => {"giblets" => { "migrate" => false, "migration_command" => "thor fancy:migrate" }}}, 'ey.yml') }
201
+ before { write_yaml({"defaults" => { "migrate" => false, "migration_command" => "thor fancy:migrate" }}, 'ey.yml') }
242
202
  after { File.unlink 'ey.yml' }
243
203
 
244
204
  it "does not migrate by default" do
@@ -298,21 +258,6 @@ describe "ey deploy" do
298
258
  end
299
259
  end
300
260
 
301
- context "when there is extra configuration" do
302
- before(:each) do
303
- write_yaml({"environments" => {"giblets" => {"bert" => "ernie"}}}, 'ey.yml')
304
- end
305
-
306
- after(:each) do
307
- File.unlink("ey.yml")
308
- end
309
-
310
- it "no longer gets passed along to engineyard-serverside (since serverside will read it on its own)" do
311
- fast_ey %w[deploy --no-migrate]
312
- @ssh_commands.last.should_not =~ /"bert":"ernie"/
313
- end
314
- end
315
-
316
261
  context "with a configured default branch" do
317
262
  before(:each) do
318
263
  write_yaml({"environments" => {"giblets" => {"branch" => "master", "migrate" => false}}}, 'ey.yml')
@@ -344,6 +289,21 @@ describe "ey deploy" do
344
289
  end
345
290
  end
346
291
 
292
+ context "when there is extra configuration" do
293
+ before(:each) do
294
+ write_yaml({"environments" => {"giblets" => {"migrate" => true, "migration_command" => "rake", "bert" => "ernie"}}}, 'ey.yml')
295
+ end
296
+
297
+ after(:each) do
298
+ File.unlink("ey.yml")
299
+ end
300
+
301
+ it "no longer gets passed along to engineyard-serverside (since serverside will read it on its own)" do
302
+ fast_ey %w[deploy --no-migrate]
303
+ @ssh_commands.last.should_not =~ /"bert":"ernie"/
304
+ end
305
+ end
306
+
347
307
  context "specifying an environment" do
348
308
  before(:all) do
349
309
  login_scenario "one app, many similarly-named environments"
@@ -386,7 +346,7 @@ describe "ey deploy" do
386
346
 
387
347
  context "when ey.yml is present" do
388
348
  before do
389
- write_yaml({"environments" => {"giblets" => {"beer" => "stout", "migrate" => true}}}, 'ey.yml')
349
+ write_yaml({"environments" => {"giblets" => {"beer" => "stout", "migrate" => true, "migration_command" => "rake"}}}, 'ey.yml')
390
350
  end
391
351
 
392
352
  after { File.unlink("ey.yml") }
@@ -416,7 +376,7 @@ describe "ey deploy" do
416
376
  fast_ey %w[deploy --app rails232app --ref master --migrate]
417
377
  @ssh_commands.last.should match(/--app rails232app/)
418
378
  @ssh_commands.last.should match(/--ref resolved-master/)
419
- @ssh_commands.last.should match(/--migrate 'rake db:migrate'/)
379
+ @ssh_commands.last.should match(/--migrate 'rake db:migrate --trace'/)
420
380
  end
421
381
 
422
382
  it "requires that you specify a ref when specifying the application" do
@@ -464,7 +424,7 @@ describe "ey deploy" do
464
424
  end
465
425
 
466
426
  it "passes along the repository URL to engineyard-serverside" do
467
- @deploy_command.should =~ /--repo user@git.host:path\/to\/repo.git/
427
+ @deploy_command.should =~ /--git user@git.host:path\/to\/repo.git/
468
428
  end
469
429
 
470
430
  it "passes along the web server stack to engineyard-serverside" do
@@ -0,0 +1,123 @@
1
+ require 'spec_helper'
2
+
3
+ describe "ey init" do
4
+ given "integration"
5
+
6
+ let(:default_migration_command) { "rake db:migrate --trace" }
7
+
8
+ before do
9
+ login_scenario "one app, one environment"
10
+ end
11
+
12
+ before { clean_ey_yml }
13
+ after { clean_ey_yml }
14
+
15
+ context "with no ey.yml file" do
16
+ it "writes the file" do
17
+ fast_ey %w[init]
18
+
19
+ expect(ey_yml).to exist
20
+ expect_config('migrate').to eq(false)
21
+ end
22
+ end
23
+
24
+ context "with existing ey.yml file" do
25
+ let(:existing) {
26
+ {
27
+ "defaults" => {
28
+ "migrate" => false,
29
+ "migration_command" => "thor fancy:migrate",
30
+ "precompile_assets" => false,
31
+ "precompile_assets_task" => "assets:precompile",
32
+ },
33
+ "environments" => {
34
+ "my_env" => {
35
+ "default" => true,
36
+ "migrate" => true,
37
+ "migration_command" => default_migration_command,
38
+ }
39
+ }
40
+ }
41
+ }
42
+
43
+ before do
44
+ write_yaml(existing, 'ey.yml')
45
+ end
46
+
47
+ it "reinitializes the file" do
48
+ fast_ey %w[init]
49
+
50
+ expect_config('defaults','migration_command').to eq("thor fancy:migrate")
51
+ expect_config('defaults','migrate').to eq(false)
52
+ expect_config('defaults','precompile_assets').to eq(false)
53
+
54
+ expect_config('environments','my_env','default').to eq(true)
55
+ expect_config('environments','my_env','migrate').to eq(true)
56
+ expect_config('environments','my_env','migration_command').to eq(default_migration_command)
57
+ end
58
+
59
+ it "makes a backup when overwriting an existing file" do
60
+ fast_ey %w[init]
61
+ data = read_yaml('ey.yml.backup')
62
+ expect(data['defaults']['migration_command']).to eq('thor fancy:migrate')
63
+ end
64
+ end
65
+
66
+ context "smart defaults" do
67
+ describe "migrate" do
68
+ let(:db) { Pathname.new('db') }
69
+ let(:db_migrate) { db.join('migrate') }
70
+
71
+ context "with db/migrate directory" do
72
+ before { db_migrate.mkpath }
73
+ after { db.rmtree }
74
+
75
+ it "sets migrate to true and uses default migration command" do
76
+ fast_ey %w[init]
77
+
78
+ expect_config('migrate').to eq(true)
79
+ expect_config('migration_command').to eq(default_migration_command)
80
+ end
81
+ end
82
+
83
+ context "without db/migrate directory" do
84
+ it "sets migrate to false and doesn't write migration_command" do
85
+ expect(db_migrate).to_not exist
86
+
87
+ fast_ey %w[init]
88
+
89
+ expect_config('migrate').to eq(false)
90
+ expect_config('migration_command').to be_nil
91
+ end
92
+ end
93
+ end
94
+
95
+ context "precompile_assets" do
96
+ let(:app) { Pathname.new('app') }
97
+ let(:assets) { app.join('assets') }
98
+
99
+ context "with app/assets directory" do
100
+ before { assets.mkpath }
101
+ after { app.rmtree }
102
+
103
+ it "sets precompile_assets to true and doesn't write precompile_assets_task" do
104
+ fast_ey %w[init]
105
+
106
+ expect_config('precompile_assets').to eq(true)
107
+ expect_config('precompile_assets_task').to be_nil
108
+ end
109
+ end
110
+
111
+ context "without app/assets directory" do
112
+ it "sets precompile_assets to false and does not set an precompile_assets_task" do
113
+ expect(assets).to_not exist
114
+
115
+ fast_ey %w[init]
116
+
117
+ expect_config('precompile_assets').to eq(false)
118
+ expect_config('precompile_assets_task').to be_nil
119
+ end
120
+ end
121
+ end
122
+ end
123
+ end
@@ -11,7 +11,7 @@ describe "ey rebuild" do
11
11
  end
12
12
 
13
13
  def verify_ran(scenario)
14
- @out.should =~ /Updating instances on \w+\/#{scenario[:environment]}/
14
+ @out.should =~ /Updating instances on #{scenario[:account]} \/ #{scenario[:environment]}/
15
15
  end
16
16
 
17
17
  include_examples "it takes an environment name and an account name"
@@ -0,0 +1,143 @@
1
+ require 'spec_helper'
2
+
3
+ describe "ey servers" do
4
+
5
+ given "integration"
6
+
7
+ def command_to_run(opts)
8
+ cmd = ["servers"]
9
+ cmd << "--environment" << opts[:environment] if opts[:environment]
10
+ cmd << "--account" << opts[:account] if opts[:account]
11
+ cmd
12
+ end
13
+
14
+ def verify_ran(scenario)
15
+ @out.should match(/#{scenario[:environment]}/) if scenario[:environment]
16
+ @out.should match(/#{scenario[:account]}/) if scenario[:account]
17
+ end
18
+
19
+ include_examples "it takes an environment name and an account name"
20
+
21
+ context "with no servers" do
22
+ before do
23
+ login_scenario "empty"
24
+ end
25
+
26
+ it "prints error when no application found" do
27
+ fast_failing_ey %w[servers]
28
+ @err.should =~ /No application found/
29
+ end
30
+ end
31
+
32
+ context "with 1 server" do
33
+ before(:all) do
34
+ login_scenario "one app, many environments"
35
+ end
36
+
37
+ it "lists the servers with specified env" do
38
+ fast_ey %w[servers -e giblets]
39
+ @out.should =~ /main \/ giblets/
40
+ @out.should include('1 server ')
41
+ end
42
+ end
43
+
44
+ context "with servers" do
45
+ before(:all) do
46
+ login_scenario "two accounts, two apps, two environments, ambiguous"
47
+ end
48
+
49
+ it "lists the servers with specified env" do
50
+ fast_ey %w[servers -c main -e giblets]
51
+ @out.should include("# 7 servers on main / giblets")
52
+ @out.should include("app_master_hostname.compute-1.amazonaws.com \ti-ddbbdd92\tapp_master")
53
+ @out.should include("app_hostname.compute-1.amazonaws.com \ti-d2e3f1b9\tapp")
54
+ @out.should include("db_master_hostname.compute-1.amazonaws.com \ti-d4cdddbf\tdb_master")
55
+ @out.should include("db_slave_1_hostname.compute-1.amazonaws.com \ti-asdfasdfaj\tdb_slave \tSlave I")
56
+ @out.should include("db_slave_2_hostname.compute-1.amazonaws.com \ti-asdfasdfaj\tdb_slave")
57
+ @out.should include("util_fluffy_hostname.compute-1.amazonaws.com\ti-80e3f1eb\tutil \tfluffy")
58
+ @out.should include("util_rocky_hostname.compute-1.amazonaws.com \ti-80etf1eb\tutil \trocky")
59
+ end
60
+
61
+ it "lists the servers with specified env with users" do
62
+ fast_ey %w[servers -c main -e giblets -u]
63
+ @out.should include("# 7 servers on main / giblets")
64
+ @out.should include("turkey@app_master_hostname.compute-1.amazonaws.com \ti-ddbbdd92\tapp_master")
65
+ @out.should include("turkey@app_hostname.compute-1.amazonaws.com \ti-d2e3f1b9\tapp")
66
+ @out.should include("turkey@db_master_hostname.compute-1.amazonaws.com \ti-d4cdddbf\tdb_master")
67
+ @out.should include("turkey@db_slave_1_hostname.compute-1.amazonaws.com \ti-asdfasdfaj\tdb_slave \tSlave I")
68
+ @out.should include("turkey@db_slave_2_hostname.compute-1.amazonaws.com \ti-asdfasdfaj\tdb_slave")
69
+ @out.should include("turkey@util_fluffy_hostname.compute-1.amazonaws.com\ti-80e3f1eb\tutil \tfluffy")
70
+ @out.should include("turkey@util_rocky_hostname.compute-1.amazonaws.com \ti-80etf1eb\tutil \trocky")
71
+ end
72
+
73
+ it "lists simple format servers" do
74
+ fast_ey %w[servers -c main -e giblets -qs], :debug => false
75
+ @out.split(/\n/).map {|x| x.split(/\t/) }.should == [
76
+ ['app_master_hostname.compute-1.amazonaws.com', 'i-ddbbdd92', 'app_master' ],
77
+ ['app_hostname.compute-1.amazonaws.com', 'i-d2e3f1b9', 'app' ],
78
+ ['db_master_hostname.compute-1.amazonaws.com', 'i-d4cdddbf', 'db_master' ],
79
+ ['db_slave_1_hostname.compute-1.amazonaws.com', 'i-asdfasdfaj', 'db_slave', 'Slave I'],
80
+ ['db_slave_2_hostname.compute-1.amazonaws.com', 'i-asdfasdfaj', 'db_slave' ],
81
+ ['util_fluffy_hostname.compute-1.amazonaws.com', 'i-80e3f1eb', 'util', 'fluffy' ],
82
+ ['util_rocky_hostname.compute-1.amazonaws.com', 'i-80etf1eb', 'util', 'rocky' ],
83
+ ]
84
+ end
85
+
86
+ it "lists simple format servers with users" do
87
+ fast_ey %w[servers -c main -e giblets -qsu], :debug => false
88
+ @out.split(/\n/).map {|x| x.split(/\t/) }.should == [
89
+ ['turkey@app_master_hostname.compute-1.amazonaws.com', 'i-ddbbdd92', 'app_master' ],
90
+ ['turkey@app_hostname.compute-1.amazonaws.com', 'i-d2e3f1b9', 'app' ],
91
+ ['turkey@db_master_hostname.compute-1.amazonaws.com', 'i-d4cdddbf', 'db_master' ],
92
+ ['turkey@db_slave_1_hostname.compute-1.amazonaws.com', 'i-asdfasdfaj', 'db_slave', 'Slave I'],
93
+ ['turkey@db_slave_2_hostname.compute-1.amazonaws.com', 'i-asdfasdfaj', 'db_slave' ],
94
+ ['turkey@util_fluffy_hostname.compute-1.amazonaws.com', 'i-80e3f1eb', 'util', 'fluffy' ],
95
+ ['turkey@util_rocky_hostname.compute-1.amazonaws.com', 'i-80etf1eb', 'util', 'rocky' ],
96
+ ]
97
+ end
98
+
99
+ it "lists host only" do
100
+ fast_ey %w[servers -c main -e giblets -qS], :debug => false
101
+ @out.split(/\n/).should == [
102
+ 'app_master_hostname.compute-1.amazonaws.com',
103
+ 'app_hostname.compute-1.amazonaws.com',
104
+ 'db_master_hostname.compute-1.amazonaws.com',
105
+ 'db_slave_1_hostname.compute-1.amazonaws.com',
106
+ 'db_slave_2_hostname.compute-1.amazonaws.com',
107
+ 'util_fluffy_hostname.compute-1.amazonaws.com',
108
+ 'util_rocky_hostname.compute-1.amazonaws.com',
109
+ ]
110
+ end
111
+
112
+ it "lists host only with users" do
113
+ fast_ey %w[servers -c main -e giblets -qSu], :debug => false
114
+ @out.split(/\n/).should == [
115
+ 'turkey@app_master_hostname.compute-1.amazonaws.com',
116
+ 'turkey@app_hostname.compute-1.amazonaws.com',
117
+ 'turkey@db_master_hostname.compute-1.amazonaws.com',
118
+ 'turkey@db_slave_1_hostname.compute-1.amazonaws.com',
119
+ 'turkey@db_slave_2_hostname.compute-1.amazonaws.com',
120
+ 'turkey@util_fluffy_hostname.compute-1.amazonaws.com',
121
+ 'turkey@util_rocky_hostname.compute-1.amazonaws.com',
122
+ ]
123
+ end
124
+
125
+ it "finds no servers with gibberish " do
126
+ fast_failing_ey %w[servers --account main --environment gibberish]
127
+ @err.should include('No environment found matching "gibberish"')
128
+ end
129
+
130
+ it "finds no servers with gibberish account" do
131
+ fast_failing_ey %w[servers --account gibberish --environment giblets]
132
+ @err.should include('No account found matching "gibberish"')
133
+ end
134
+
135
+ it "reports failure to find a git repo when not in one" do
136
+ Dir.chdir(Dir.tmpdir) do
137
+ fast_failing_ey %w[servers]
138
+ @err.should =~ /fatal: Not a git repository \(or any of the parent directories\): .*#{Regexp.escape(Dir.tmpdir)}/
139
+ @out.should_not =~ /no application configured/
140
+ end
141
+ end
142
+ end
143
+ end