foreplay 0.15.4 → 0.16.0

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: 3758e074daab2a595d32666e7eb7034efd7eaff2
4
- data.tar.gz: a40d78f7cbb448bcf8eba79e1b69904f866ac6bc
3
+ metadata.gz: 1acc3d32d3a9059cd7d30b0c94fd940e6b1c01ed
4
+ data.tar.gz: a1bc3da15901ae17b86a4bcc2654bb626bd46265
5
5
  SHA512:
6
- metadata.gz: fc871cf10d5eec20ae4d665c68b4b7fd64db402a32edc6d2de71aa453b8adbd14a4eefe15ca021a72ba59d2b8ae4839f84c3c508d89cb51881b86d4f86031670
7
- data.tar.gz: 745f3bf9544292a942718e600ee1a8c12c7caa248a4f86d8e58cfd0b288c19daf913c5d8dffcfbde02afd43297e1e62eccd0eae36e701919c56f33fa94069c31
6
+ metadata.gz: 0ecf87c49b570cf477f451b52b807494a022c60b7c2f80a2092f11233480271cd7b508d2e9959a132a96c69c698ca2641a97f32dc1b37120e1f49cbf6f53df15
7
+ data.tar.gz: f1a0141cb67f48da58cbc67125b3531716eb5dba45b697f2b4d4bac7789b108b7a81184d4752ba18a1a68cdf9228f68cc7b3f8865d7d1d759f34f4ddacb59237
data/.gitignore CHANGED
@@ -1,4 +1,6 @@
1
1
  Gemfile.lock
2
+ *.local
3
+ *.gem
2
4
  .ruby-version
3
5
  .ruby-gemset
4
6
  ._*
data/.rspec CHANGED
@@ -1,4 +1,5 @@
1
1
  --color
2
- --profile
3
2
  --require spec_helper
3
+ --profile
4
4
  --format progress
5
+ --format RspecJunitFormatter --out <%= ENV.fetch('CIRCLE_TEST_REPORTS', 'tmp') %>/rspec/rspec.xml
data/.rubocop.yml CHANGED
@@ -1,6 +1,10 @@
1
1
  ---
2
- # These are OK:
2
+ AllCops:
3
+ Exclude:
4
+ - '*.gemspec'
5
+ - 'spec/**/*'
3
6
 
7
+ # These are OK:
4
8
  StringLiterals:
5
9
  EnforcedStyle: single_quotes
6
10
  Enabled: true
data/Gemfile CHANGED
@@ -1,3 +1,19 @@
1
1
  source 'https://rubygems.org'
2
2
  ruby '2.1.9'
3
3
  gemspec
4
+
5
+ group :test do
6
+ gem 'rspec'
7
+ gem 'rspec_junit_formatter'
8
+ gem 'cucumber'
9
+ gem 'aruba'
10
+ gem 'simplecov'
11
+ gem 'coveralls'
12
+ gem 'codeclimate-test-reporter'
13
+ end
14
+
15
+ local_gemfile = 'Gemfile.local'
16
+
17
+ if File.exist?(local_gemfile)
18
+ eval(File.read(local_gemfile)) # rubocop:disable Lint/Eval
19
+ end
@@ -0,0 +1,12 @@
1
+ # Copy this file to a file named Gemfile.local to add these gems to your dev toolset
2
+ # Feel free to modify Gemfile.local to suit your own preferences
3
+ group :development do
4
+ gem 'rake'
5
+ gem 'gem-release'
6
+ gem 'rubocop'
7
+ gem 'listen', '~> 3.0', '< 3.1' # Dependency of guard, 3.1 requires Ruby 2.2+
8
+ gem 'guard'
9
+ gem 'guard-rspec'
10
+ gem 'guard-rubocop'
11
+ gem 'guard-cucumber'
12
+ end
data/README.md CHANGED
@@ -80,6 +80,7 @@ production:
80
80
  foreman:
81
81
  concurrency: 'web=1,worker_immediate=2,worker_longjobs=1,scheduler=1,resque_web=1,new_relic_resque=1'
82
82
  auxiliary:
83
+ config: ['stop_first'] # It runs out of memory unless I stop the service before asset precompile
83
84
  servers: [bradman.xenapto.net,edrich.xenapto.net:10022]
84
85
  foreman:
85
86
  concurrency: 'worker_regular=8'
@@ -101,6 +102,7 @@ A quick walk-though of this configuration:
101
102
  6. Each role contains a list of servers and any overrides to the default settings
102
103
  7. For instance the `web` role is deployed to `sandham.xenapto.net`. For that server the database is on the same machine (`localhost`). The Foreman `concurrency` setting defines which workers from my Procfile are launched on that server.
103
104
  8. Note that in the `auxiliary` role I am deploying to two servers. On the second (`edrich.xenapto.net`) I'm using port 10022 for SSH instead of the default.
105
+ 9. Precompiling assets uses a lot of memory. On these servers I get Out Of Memory errors unless I shut down my app first.
104
106
 
105
107
  General format:
106
108
 
@@ -113,6 +115,7 @@ defaults: # global defaults for all environments
113
115
  keyfile: # or a file containing a private key that allows the named user access to the server
114
116
  key: # ...or a private key that allows the named user access to the server
115
117
  path: # absolute path to deploy the app on each server. %s will substitute to the app name
118
+ config: # Configuration parameters to change the behaviour of Foreplay
116
119
  database: # the database.yml elements to write to the config folder
117
120
  env: # contents of the .env file
118
121
  key: value # will go into the .env file as key=value
data/circle.yml ADDED
@@ -0,0 +1,18 @@
1
+ machine:
2
+ ruby:
3
+ version: 2.1.9
4
+
5
+ dependencies:
6
+ pre:
7
+ - echo "export rvm_ignore_gemsets_flag=1" >> ~/.rvmrc
8
+ - gem install bundler
9
+ override:
10
+ - bundle check --path=vendor/bundle || bundle install --path=vendor/bundle --jobs=4 --retry=3 --full-index
11
+
12
+ test:
13
+ override:
14
+ - bundle exec rspec:
15
+ timeout: 600
16
+ parallel: true
17
+ files:
18
+ - spec/**/*_spec.rb
data/foreplay.gemspec CHANGED
@@ -2,39 +2,22 @@ lib = File.expand_path('../lib', __FILE__)
2
2
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
3
  require 'foreplay/version'
4
4
 
5
- Gem::Specification.new do |spec|
6
- spec.name = 'foreplay'
7
- spec.version = Foreplay::VERSION
8
- spec.authors = ['Xenapto']
9
- spec.email = ['developers@xenapto.com']
10
- spec.description = 'Deploying Rails projects to Ubuntu using Foreman'
11
- spec.summary = 'Example: foreplay deploy production'
12
- spec.homepage = 'https://github.com/Xenapto/foreplay'
13
- spec.license = 'MIT'
5
+ Gem::Specification.new do |s|
6
+ s.name = 'foreplay'
7
+ s.version = Foreplay::VERSION
8
+ s.authors = ['Xenapto']
9
+ s.email = ['developers@xenapto.com']
10
+ s.description = 'Deploying Rails projects to Ubuntu using Foreman'
11
+ s.summary = 'Example: foreplay deploy production'
12
+ s.homepage = 'https://github.com/Xenapto/foreplay'
13
+ s.license = 'MIT'
14
14
 
15
- spec.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
16
- spec.executables = spec.files.grep(%r{^bin\/}) { |f| File.basename(f) }
17
- spec.test_files = spec.files.grep(%r{^(test|spec|features|coverage)\/})
18
- spec.require_paths = ['lib']
15
+ s.files = `git ls-files`.split($RS).reject { |file| file =~ /^spec\// }
16
+ s.test_files = []
17
+ s.executables = s.files.grep(%r{^bin\/}) { |f| File.basename(f) }
18
+ s.require_paths = ['lib']
19
19
 
20
- spec.add_runtime_dependency 'foreman', '>= 0.76', '< 1.0'
21
- spec.add_runtime_dependency 'ssh-shell', '>= 0.4', '< 1.0'
22
- spec.add_runtime_dependency 'activesupport', '>= 3.2', '< 5.0'
23
-
24
- spec.add_development_dependency 'bundler', '~> 1.9'
25
- spec.add_development_dependency 'rake', '~> 10.4'
26
- spec.add_development_dependency 'rspec', '~> 3.2'
27
- spec.add_development_dependency 'rspec_junit_formatter', '~> 0.2'
28
- spec.add_development_dependency 'cucumber', '~> 2.0'
29
- spec.add_development_dependency 'aruba', '~> 0.6'
30
- spec.add_development_dependency 'gem-release', '~> 0.7'
31
- spec.add_development_dependency 'simplecov', '~> 0.10'
32
- spec.add_development_dependency 'coveralls', '~> 0.8'
33
- spec.add_development_dependency 'codeclimate-test-reporter', '~> 0.4'
34
- spec.add_development_dependency 'rubocop', '~> 0.30'
35
- spec.add_development_dependency 'listen', '~> 3.0', '< 3.1' # Dependency of guard, 3.1 requires Ruby 2.2+
36
- spec.add_development_dependency 'guard', '~> 2'
37
- spec.add_development_dependency 'guard-rspec', '~> 4'
38
- spec.add_development_dependency 'guard-rubocop', '~> 1.2'
39
- spec.add_development_dependency 'guard-cucumber', '~> 1.6'
20
+ s.add_runtime_dependency 'foreman', '>= 0.76', '< 1.0'
21
+ s.add_runtime_dependency 'ssh-shell', '>= 0.4', '< 1.0'
22
+ s.add_runtime_dependency 'activesupport', '>= 3.2', '< 5.0'
40
23
  end
@@ -14,7 +14,8 @@ module Foreplay
14
14
  @defaults = {
15
15
  'name' => File.basename(Dir.getwd),
16
16
  'environment' => environment,
17
- 'port' => DEFAULT_PORT
17
+ 'port' => DEFAULT_PORT,
18
+ 'config' => []
18
19
  }
19
20
 
20
21
  @defaults['env'] = secrets
@@ -14,9 +14,9 @@
14
14
  commentary: 'If you have a .rvmrc file there may be a delay now while we install a new ruby'
15
15
  - command: 'if [ -f .ruby-version ] ; then rvm install `cat .ruby-version` ; else echo "No .ruby-version file found" ; fi'
16
16
  commentary: 'If you have a .ruby-version file there may be a delay now while we install a new ruby'
17
- - command: 'env'
17
+ - command: 'if [ <%= instructions.key?("verbose") ? "1" : "" %> ] ; then env ; fi'
18
18
  commentary: 'Showing environment variables'
19
- - command: 'rvm rvmrc load && rvm info'
19
+ - command: 'if [ <%= instructions.key?("verbose") ? "1" : "" %> ] ; then rvm rvmrc load && rvm info ; fi'
20
20
  commentary: 'Showing RVM environment'
21
21
  - key: 'env'
22
22
  delimiter: '='
@@ -56,6 +56,8 @@
56
56
  commentary: 'Using bundler to install the required gems in deployment mode'
57
57
  - command: 'mkdir -p ../cache/vendor && rsync -aW --no-compress --delete --info=STATS1 vendor/bundle/ ../cache/vendor/bundle'
58
58
  commentary: 'Caching bundle'
59
+ - command: "if [ <%= instructions['config'].include?('stop_first') ? '1' : '' %> ] ; then sudo stop <%= former_service %> || echo 'No previous instance running' ; fi"
60
+ commentary: 'Stopping the previous instance'
59
61
  - command: 'if [ -f public/assets/manifest.yml ] ; then echo "Not precompiling assets" ; else RAILS_ENV=<%= environment %> /usr/bin/bundle exec foreman run rake assets:precompile ; fi'
60
62
  commentary: 'Precompiling assets unless they were supplied'
61
63
  - command: 'sudo /usr/bin/bundle exec foreman export upstart<%= concurrency %> /etc/init'
@@ -1,3 +1,3 @@
1
1
  module Foreplay
2
- VERSION = '0.15.4'.freeze
2
+ VERSION = '0.16.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foreplay
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.15.4
4
+ version: 0.16.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Xenapto
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-10-04 00:00:00.000000000 Z
11
+ date: 2016-10-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: foreman
@@ -70,236 +70,6 @@ dependencies:
70
70
  - - "<"
71
71
  - !ruby/object:Gem::Version
72
72
  version: '5.0'
73
- - !ruby/object:Gem::Dependency
74
- name: bundler
75
- requirement: !ruby/object:Gem::Requirement
76
- requirements:
77
- - - "~>"
78
- - !ruby/object:Gem::Version
79
- version: '1.9'
80
- type: :development
81
- prerelease: false
82
- version_requirements: !ruby/object:Gem::Requirement
83
- requirements:
84
- - - "~>"
85
- - !ruby/object:Gem::Version
86
- version: '1.9'
87
- - !ruby/object:Gem::Dependency
88
- name: rake
89
- requirement: !ruby/object:Gem::Requirement
90
- requirements:
91
- - - "~>"
92
- - !ruby/object:Gem::Version
93
- version: '10.4'
94
- type: :development
95
- prerelease: false
96
- version_requirements: !ruby/object:Gem::Requirement
97
- requirements:
98
- - - "~>"
99
- - !ruby/object:Gem::Version
100
- version: '10.4'
101
- - !ruby/object:Gem::Dependency
102
- name: rspec
103
- requirement: !ruby/object:Gem::Requirement
104
- requirements:
105
- - - "~>"
106
- - !ruby/object:Gem::Version
107
- version: '3.2'
108
- type: :development
109
- prerelease: false
110
- version_requirements: !ruby/object:Gem::Requirement
111
- requirements:
112
- - - "~>"
113
- - !ruby/object:Gem::Version
114
- version: '3.2'
115
- - !ruby/object:Gem::Dependency
116
- name: rspec_junit_formatter
117
- requirement: !ruby/object:Gem::Requirement
118
- requirements:
119
- - - "~>"
120
- - !ruby/object:Gem::Version
121
- version: '0.2'
122
- type: :development
123
- prerelease: false
124
- version_requirements: !ruby/object:Gem::Requirement
125
- requirements:
126
- - - "~>"
127
- - !ruby/object:Gem::Version
128
- version: '0.2'
129
- - !ruby/object:Gem::Dependency
130
- name: cucumber
131
- requirement: !ruby/object:Gem::Requirement
132
- requirements:
133
- - - "~>"
134
- - !ruby/object:Gem::Version
135
- version: '2.0'
136
- type: :development
137
- prerelease: false
138
- version_requirements: !ruby/object:Gem::Requirement
139
- requirements:
140
- - - "~>"
141
- - !ruby/object:Gem::Version
142
- version: '2.0'
143
- - !ruby/object:Gem::Dependency
144
- name: aruba
145
- requirement: !ruby/object:Gem::Requirement
146
- requirements:
147
- - - "~>"
148
- - !ruby/object:Gem::Version
149
- version: '0.6'
150
- type: :development
151
- prerelease: false
152
- version_requirements: !ruby/object:Gem::Requirement
153
- requirements:
154
- - - "~>"
155
- - !ruby/object:Gem::Version
156
- version: '0.6'
157
- - !ruby/object:Gem::Dependency
158
- name: gem-release
159
- requirement: !ruby/object:Gem::Requirement
160
- requirements:
161
- - - "~>"
162
- - !ruby/object:Gem::Version
163
- version: '0.7'
164
- type: :development
165
- prerelease: false
166
- version_requirements: !ruby/object:Gem::Requirement
167
- requirements:
168
- - - "~>"
169
- - !ruby/object:Gem::Version
170
- version: '0.7'
171
- - !ruby/object:Gem::Dependency
172
- name: simplecov
173
- requirement: !ruby/object:Gem::Requirement
174
- requirements:
175
- - - "~>"
176
- - !ruby/object:Gem::Version
177
- version: '0.10'
178
- type: :development
179
- prerelease: false
180
- version_requirements: !ruby/object:Gem::Requirement
181
- requirements:
182
- - - "~>"
183
- - !ruby/object:Gem::Version
184
- version: '0.10'
185
- - !ruby/object:Gem::Dependency
186
- name: coveralls
187
- requirement: !ruby/object:Gem::Requirement
188
- requirements:
189
- - - "~>"
190
- - !ruby/object:Gem::Version
191
- version: '0.8'
192
- type: :development
193
- prerelease: false
194
- version_requirements: !ruby/object:Gem::Requirement
195
- requirements:
196
- - - "~>"
197
- - !ruby/object:Gem::Version
198
- version: '0.8'
199
- - !ruby/object:Gem::Dependency
200
- name: codeclimate-test-reporter
201
- requirement: !ruby/object:Gem::Requirement
202
- requirements:
203
- - - "~>"
204
- - !ruby/object:Gem::Version
205
- version: '0.4'
206
- type: :development
207
- prerelease: false
208
- version_requirements: !ruby/object:Gem::Requirement
209
- requirements:
210
- - - "~>"
211
- - !ruby/object:Gem::Version
212
- version: '0.4'
213
- - !ruby/object:Gem::Dependency
214
- name: rubocop
215
- requirement: !ruby/object:Gem::Requirement
216
- requirements:
217
- - - "~>"
218
- - !ruby/object:Gem::Version
219
- version: '0.30'
220
- type: :development
221
- prerelease: false
222
- version_requirements: !ruby/object:Gem::Requirement
223
- requirements:
224
- - - "~>"
225
- - !ruby/object:Gem::Version
226
- version: '0.30'
227
- - !ruby/object:Gem::Dependency
228
- name: listen
229
- requirement: !ruby/object:Gem::Requirement
230
- requirements:
231
- - - "~>"
232
- - !ruby/object:Gem::Version
233
- version: '3.0'
234
- - - "<"
235
- - !ruby/object:Gem::Version
236
- version: '3.1'
237
- type: :development
238
- prerelease: false
239
- version_requirements: !ruby/object:Gem::Requirement
240
- requirements:
241
- - - "~>"
242
- - !ruby/object:Gem::Version
243
- version: '3.0'
244
- - - "<"
245
- - !ruby/object:Gem::Version
246
- version: '3.1'
247
- - !ruby/object:Gem::Dependency
248
- name: guard
249
- requirement: !ruby/object:Gem::Requirement
250
- requirements:
251
- - - "~>"
252
- - !ruby/object:Gem::Version
253
- version: '2'
254
- type: :development
255
- prerelease: false
256
- version_requirements: !ruby/object:Gem::Requirement
257
- requirements:
258
- - - "~>"
259
- - !ruby/object:Gem::Version
260
- version: '2'
261
- - !ruby/object:Gem::Dependency
262
- name: guard-rspec
263
- requirement: !ruby/object:Gem::Requirement
264
- requirements:
265
- - - "~>"
266
- - !ruby/object:Gem::Version
267
- version: '4'
268
- type: :development
269
- prerelease: false
270
- version_requirements: !ruby/object:Gem::Requirement
271
- requirements:
272
- - - "~>"
273
- - !ruby/object:Gem::Version
274
- version: '4'
275
- - !ruby/object:Gem::Dependency
276
- name: guard-rubocop
277
- requirement: !ruby/object:Gem::Requirement
278
- requirements:
279
- - - "~>"
280
- - !ruby/object:Gem::Version
281
- version: '1.2'
282
- type: :development
283
- prerelease: false
284
- version_requirements: !ruby/object:Gem::Requirement
285
- requirements:
286
- - - "~>"
287
- - !ruby/object:Gem::Version
288
- version: '1.2'
289
- - !ruby/object:Gem::Dependency
290
- name: guard-cucumber
291
- requirement: !ruby/object:Gem::Requirement
292
- requirements:
293
- - - "~>"
294
- - !ruby/object:Gem::Version
295
- version: '1.6'
296
- type: :development
297
- prerelease: false
298
- version_requirements: !ruby/object:Gem::Requirement
299
- requirements:
300
- - - "~>"
301
- - !ruby/object:Gem::Version
302
- version: '1.6'
303
73
  description: Deploying Rails projects to Ubuntu using Foreman
304
74
  email:
305
75
  - developers@xenapto.com
@@ -313,11 +83,13 @@ files:
313
83
  - ".rspec"
314
84
  - ".rubocop.yml"
315
85
  - Gemfile
86
+ - Gemfile.local.example
316
87
  - Guardfile
317
88
  - LICENSE.txt
318
89
  - README.md
319
90
  - Rakefile
320
91
  - bin/foreplay
92
+ - circle.yml
321
93
  - features/check.feature
322
94
  - features/deploy.feature
323
95
  - features/setup.feature
@@ -342,12 +114,6 @@ files:
342
114
  - lib/foreplay/setup.rb
343
115
  - lib/foreplay/setup/foreplay.template.yml
344
116
  - lib/foreplay/version.rb
345
- - spec/lib/foreplay/deploy_spec.rb
346
- - spec/lib/foreplay/secrets_spec.rb
347
- - spec/lib/foreplay/setup_spec.rb
348
- - spec/lib/hash_spec.rb
349
- - spec/lib/yaml_spec.rb
350
- - spec/spec_helper.rb
351
117
  homepage: https://github.com/Xenapto/foreplay
352
118
  licenses:
353
119
  - MIT
@@ -372,14 +138,4 @@ rubygems_version: 2.6.7
372
138
  signing_key:
373
139
  specification_version: 4
374
140
  summary: 'Example: foreplay deploy production'
375
- test_files:
376
- - features/check.feature
377
- - features/deploy.feature
378
- - features/setup.feature
379
- - features/support/env.rb
380
- - spec/lib/foreplay/deploy_spec.rb
381
- - spec/lib/foreplay/secrets_spec.rb
382
- - spec/lib/foreplay/setup_spec.rb
383
- - spec/lib/hash_spec.rb
384
- - spec/lib/yaml_spec.rb
385
- - spec/spec_helper.rb
141
+ test_files: []
@@ -1,225 +0,0 @@
1
- require 'net/ssh/shell'
2
-
3
- describe Foreplay::Launcher do
4
- let(:session) { double(Net::SSH::Connection::Session) }
5
- let(:shell) { double(Net::SSH::Shell) }
6
- let(:process) { double(Net::SSH::Shell::Process) }
7
-
8
- before :each do
9
- # Setup foreplay
10
- `rm -f config/foreplay.yml`
11
- command = 'foreplay setup '\
12
- '-r git@github.com:Xenapto/foreplay.git '\
13
- '-s web1.example.com web2.example.com '\
14
- '-f apps/%a '\
15
- '-u fred '\
16
- '--password trollope'
17
- `#{command}`
18
-
19
- # Stub all the things
20
- allow(Net::SSH).to receive(:start).and_return(session)
21
- allow(session).to receive(:close)
22
- allow(session).to receive(:shell).and_yield(shell)
23
- allow(shell).to receive(:execute).and_return(process)
24
- allow(shell).to receive(:wait!).and_return(false)
25
- allow(process).to receive(:on_output).and_yield(process, "output message 1\noutput message 2\n")
26
- allow(process).to receive(:exit_status).and_return(0)
27
- end
28
-
29
- it "complains on check if there's no config file" do
30
- `rm -f config/foreplay.yml`
31
- expect { Foreplay::Launcher.start([:check, 'production', '']) }
32
- .to raise_error(RuntimeError, /.*Please run foreplay setup or create the file manually.*/)
33
- end
34
-
35
- it "complains on deploy if there's no config file" do
36
- `rm -f config/foreplay.yml`
37
- expect { Foreplay::Launcher.start([:deploy, 'production', '']) }
38
- .to raise_error(RuntimeError, /.*Please run foreplay setup or create the file manually.*/)
39
- end
40
-
41
- it 'complains on check if the config file is not valid YAML' do
42
- `echo %*:*: > config/foreplay.yml`
43
- expect { Foreplay::Launcher.start([:check, 'production', '']) }
44
- .to raise_error(RuntimeError, /.*Please run foreplay setup or edit the file manually.*/)
45
- end
46
-
47
- it 'complains on deploy if the config file is not valid YAML' do
48
- `echo %*:*: > config/foreplay.yml`
49
- expect { Foreplay::Launcher.start([:deploy, 'production', '']) }
50
- .to raise_error(RuntimeError, /.*Please run foreplay setup or edit the file manually.*/)
51
- end
52
-
53
- it 'complains if there are no authentication methods defined in the config file' do
54
- command = 'foreplay setup '\
55
- '-r git@github.com:Xenapto/foreplay.git '\
56
- '-s web.example.com '\
57
- '-f apps/%a '\
58
- '-u fred '\
59
- '--password ""'
60
-
61
- match = 'No authentication methods supplied. '\
62
- 'You must supply a private key, key file or password in the configuration file.'
63
-
64
- `rm -f config/foreplay.yml`
65
- `#{command}`
66
-
67
- expect { Foreplay::Launcher.start([:deploy, 'production', '']) }
68
- .to raise_error(
69
- RuntimeError,
70
- /.*#{Regexp.quote(match)}*/
71
- )
72
- end
73
-
74
- it "complains if the private keyfile defined in the config file doesn't exist" do
75
- command = 'foreplay setup '\
76
- '-r git@github.com:Xenapto/foreplay.git '\
77
- '-s web.example.com '\
78
- '-f apps/%a '\
79
- '-u fred '\
80
- '--keyfile "/home/fred/no-such-file"'
81
-
82
- `rm -f config/foreplay.yml`
83
- `#{command}`
84
-
85
- # Exact error message text is Ruby version dependent
86
- expect { Foreplay::Launcher.start([:deploy, 'production', '']) }
87
- .to raise_error(Errno::ENOENT, %r{.*No such file or directory.+/home/fred/no-such-file.*})
88
- end
89
-
90
- it 'complains if a mandatory key is missing from the config file' do
91
- `sed -i 's/path:/pxth:/' config/foreplay.yml`
92
-
93
- expect { Foreplay::Launcher.start([:deploy, 'production', '']) }
94
- .to raise_error(
95
- RuntimeError,
96
- /.*Required key path not found in instructions for production environment.*/
97
- )
98
- end
99
-
100
- it 'complains if we try to deploy an environment that isn\'t defined' do
101
- expect { Foreplay::Launcher.start([:deploy, 'unknown', '']) }
102
- .to raise_error(
103
- RuntimeError,
104
- /.*No deployment configuration defined for unknown environment.*/
105
- )
106
- end
107
-
108
- it 'terminates if a remote process exits with a non-zero status' do
109
- allow(process).to receive(:exit_status).and_return(1)
110
- expect { Foreplay::Launcher.start([:deploy, 'production', '']) }.to raise_error(RuntimeError, /.*output message.*/)
111
- end
112
-
113
- it "terminates if a connection can't be established with the remote server" do
114
- allow(Net::SSH).to receive(:start).and_call_original
115
- expect { Foreplay::Launcher.start([:deploy, 'production', '']) }
116
- .to raise_error(RuntimeError, /.*There was a problem starting an ssh session on web1.example.com.*/)
117
- end
118
-
119
- it 'checks the config' do
120
- expect($stdout).to receive(:puts).at_least(:once)
121
- Foreplay::Launcher.start [:check, 'production', '']
122
- end
123
-
124
- it 'deploys to the environment' do
125
- secret_data = { 'BIG_SECRET' => '123', 'MOUSTACHE' => '{{moustache}}' }
126
- secrets = double(Foreplay::Engine::Secrets)
127
- allow(secrets).to receive(:fetch).and_return(secret_data)
128
- allow(Foreplay::Engine::Secrets).to receive(:new).and_return(secrets)
129
-
130
- expect(Net::SSH)
131
- .to(receive(:start))
132
- .with(/web[12].example.com/, 'fred', verbose: :warn, port: 22, password: 'trollope')
133
- .exactly(4).times
134
- .and_return(session)
135
-
136
- [
137
- "echo Foreplay version #{Foreplay::VERSION}",
138
- 'mkdir -p apps/foreplay && cd apps/foreplay && rm -rf 50000 && '\
139
- 'git clone -b master git@github.com:Xenapto/foreplay.git 50000',
140
- 'rvm rvmrc trust 50000',
141
- 'rvm rvmrc warning ignore 50000',
142
- 'gpg --keyserver hkp://pool.sks-keyservers.net --recv-keys D39DC0E3',
143
- 'cd 50000 && mkdir -p tmp doc log config',
144
- 'rvm rvmrc load && rvm info',
145
- 'if [ -f .ruby-version ] ; then rvm install `cat .ruby-version` ; else echo "No .ruby-version file found" ; fi',
146
- 'echo "BIG_SECRET=123" > .env',
147
- 'echo "MOUSTACHE={{moustache}}" >> .env',
148
- 'echo "HOME=$HOME" >> .env',
149
- 'echo "SHELL=$SHELL" >> .env',
150
- 'echo "PATH=$PATH:`which bundle`" >> .env',
151
- 'echo "GEM_HOME=$HOME/.rvm/gems/`rvm tools identifier`" >> .env',
152
- 'echo "RAILS_ENV=production" >> .env',
153
- 'echo "---" > config/application.yml',
154
- 'echo "production:" >> config/application.yml',
155
- 'echo " BIG_SECRET: \'123\'" >> config/application.yml',
156
- 'echo " MOUSTACHE: \"{{moustache}}\"" >> config/application.yml',
157
- 'echo "---" > .foreman',
158
- 'echo "concurrency: web=1,worker=0,scheduler=0" >> .foreman',
159
- 'echo "app: foreplay-50000" >> .foreman',
160
- 'echo "port: 50000" >> .foreman',
161
- 'echo "user: fred" >> .foreman',
162
- 'echo "---" > config/database.yml',
163
- 'echo "production:" >> config/database.yml',
164
- 'echo " adapter: postgresql" >> config/database.yml',
165
- 'echo " encoding: utf8" >> config/database.yml',
166
- 'echo " database: TODO Put the database name here" >> config/database.yml',
167
- 'echo " pool: 5" >> config/database.yml',
168
- 'echo " host: TODO Put here the database host name" >> config/database.yml',
169
- 'echo " username: TODO Put here the database user" >> config/database.yml',
170
- 'echo " password: TODO Put here the database user\'s password" >> config/database.yml',
171
- 'if [ -d ../cache/vendor/bundle ] ; then '\
172
- 'rsync -aW --no-compress --delete --info=STATS1 ../cache/vendor/bundle/ vendor/bundle'\
173
- ' ; else echo No bundle to restore ; fi',
174
- 'gem install bundler -v "> 1.8"',
175
- 'sudo ln -f `which bundle` /usr/bin/bundle || echo Using default version of bundle',
176
- '/usr/bin/bundle install --deployment --clean --full-index --jobs 2 --without development test',
177
- 'mkdir -p ../cache/vendor && '\
178
- 'rsync -aW --no-compress --delete --info=STATS1 vendor/bundle/ ../cache/vendor/bundle',
179
- 'if [ -f public/assets/manifest.yml ] ; then echo "Not precompiling assets"'\
180
- ' ; else RAILS_ENV=production /usr/bin/bundle exec foreman run rake assets:precompile ; fi',
181
- 'sudo /usr/bin/bundle exec foreman export upstart -m web=1,worker=0,scheduler=0 /etc/init',
182
- 'sudo start foreplay-50000 || sudo restart foreplay-50000',
183
- 'mkdir -p .foreplay/foreplay && touch .foreplay/foreplay/current_port && cat .foreplay/foreplay/current_port',
184
- 'echo 50000 > $HOME/.foreplay/foreplay/current_port',
185
- 'sleep 60',
186
- 'sudo stop foreplay-51000 || echo \'No previous instance running\''
187
- ].each do |command|
188
- expect(shell).to receive(:execute).with(command).and_return(process)
189
- end
190
-
191
- Foreplay::Launcher.start [:deploy, 'production', '']
192
- end
193
-
194
- it "uses another port if there's already an installed instance" do
195
- allow(process).to receive(:on_output).and_yield(process, "50000\n")
196
- expect(shell).to receive(:execute).with('echo 51000 > $HOME/.foreplay/foreplay/current_port').and_return(process)
197
- Foreplay::Launcher.start [:deploy, 'production', '']
198
- end
199
-
200
- it 'uses the private key provided in the config file' do
201
- command = 'foreplay setup '\
202
- '-r git@github.com:Xenapto/foreplay.git '\
203
- '-s web.example.com '\
204
- '-f apps/%a '\
205
- '-u fred '\
206
- '-k "top secret private key"'
207
-
208
- `rm -f config/foreplay.yml`
209
- `#{command}`
210
- Foreplay::Launcher.start([:deploy, 'production', ''])
211
- end
212
-
213
- it 'adds Redis details for Resque' do
214
- command = 'foreplay setup '\
215
- '-r git@github.com:Xenapto/foreplay.git '\
216
- '-s web.example.com '\
217
- '-f apps/%a '\
218
- '-u fred '\
219
- '--resque-redis "redis://localhost:6379"'
220
-
221
- `rm -f config/foreplay.yml`
222
- `#{command}`
223
- Foreplay::Launcher.start([:deploy, 'production', ''])
224
- end
225
- end
@@ -1,66 +0,0 @@
1
- describe Foreplay::Engine::Secrets do
2
- context '#fetch' do
3
- it 'returns nil if there is no secret location' do
4
- expect(Foreplay::Engine::Secrets.new('x', nil).fetch).to be_nil
5
- end
6
-
7
- it 'fails if the secret location is not a hash' do
8
- expect { Foreplay::Engine::Secrets.new('x', 'y').fetch } .to raise_error(NoMethodError)
9
- end
10
-
11
- it 'returns an empty hash if the secret location has no url' do
12
- expect(Foreplay::Engine::Secrets.new('x', []).fetch).to eq({})
13
- end
14
-
15
- it 'returns an empty hash if the secret location does not return valid YAML' do
16
- expect(Foreplay::Engine::Secrets.new('x', [{ 'url' => 'http://iana.org' }]).fetch).to eq({})
17
- end
18
-
19
- it 'returns an empty hash if the secret location does not exist' do
20
- expect(Foreplay::Engine::Secrets.new('x', [{ 'url' => 'http://iana.org/404' }]).fetch).to eq({})
21
- end
22
- end
23
-
24
- context '#fetch successful' do
25
- let(:secrets) { { 'a' => 'x', 'b' => 'y', 'c' => 'z' } }
26
- let(:secret) { Foreplay::Engine::Secrets.new('', ['x']) }
27
-
28
- before :each do
29
- allow(secret).to receive(:location_secrets).and_return(secrets)
30
- end
31
-
32
- it 'does what it is told' do
33
- expect(secret.location_secrets).to eq(secrets)
34
- end
35
-
36
- it 'returns a hash of secrets' do
37
- expect(secret.fetch).to eq(secrets)
38
- end
39
- end
40
-
41
- context '#fetch successful with merge' do
42
- let(:secrets1) { { 'a' => 'x', 'b' => 'f' } }
43
- let(:secrets2) { { 'b' => 'y', 'c' => 'z' } }
44
- let(:secrets) { { 'a' => 'x', 'b' => 'y', 'c' => 'z' } }
45
- let(:secret) { Foreplay::Engine::Secrets.new('', %w(x x)) }
46
-
47
- before :each do
48
- allow(secret).to receive(:location_secrets).and_return(secrets1, secrets2)
49
- end
50
-
51
- it 'returns a hash of secrets' do
52
- expect(secret.fetch).to eq(secrets)
53
- end
54
- end
55
-
56
- context 'Location returns a hash if one is found' do
57
- let(:location) { Foreplay::Engine::Secrets::Location.new('', 'p') }
58
- let(:secrets) { { 'p' => { 'a' => 'x', 'b' => 'y', 'c' => 'z' }, 'q' => 'zzz', 'r' => { 'd' => 1 } } }
59
-
60
- before { allow(location).to receive(:all_secrets).and_return(secrets) }
61
-
62
- it 'returns the secrets for the right environment' do
63
- expect(location.secrets).to eq(secrets['p'])
64
- end
65
- end
66
- end
@@ -1,10 +0,0 @@
1
- describe Foreplay::Setup do
2
- before :each do
3
- `rm -f config/foreplay.yml`
4
- end
5
-
6
- it 'should create a config file' do
7
- expect(File).to receive(:open)
8
- Foreplay::Setup.start
9
- end
10
- end
@@ -1,27 +0,0 @@
1
- describe Hash do
2
- context '#supermerge' do
3
- it 'should complain unless two hashes are passed to it' do
4
- expect { {}.supermerge('y') }.to raise_error(RuntimeError)
5
- end
6
-
7
- it 'should merge two simple hashes' do
8
- expect({ a: 'x' }.supermerge(b: 'y')).to eq(a: 'x', b: 'y')
9
- end
10
-
11
- it 'should merge two hashes both with arrays at the same key' do
12
- expect({ a: ['x'] }.supermerge(a: ['y'])).to eq(a: %w(x y))
13
- end
14
-
15
- it 'should merge an array and a value at the same key' do
16
- expect({ a: 'x' }.supermerge(a: ['y'])).to eq(a: %w(x y))
17
- end
18
-
19
- it 'should replace a value at the same key' do
20
- expect({ a: 'x' }.supermerge(a: 'y')).to eq(a: 'y')
21
- end
22
-
23
- it 'should merge two subhashes at the same key' do
24
- expect({ a: { b: 'x' } }.supermerge(a: { c: 'y' })).to eq(a: { b: 'x', c: 'y' })
25
- end
26
- end
27
- end
@@ -1,20 +0,0 @@
1
- describe YAML do
2
- context '#escape' do
3
- it 'uses the expected Ruby version' do
4
- expect(RUBY_VERSION).to eq '2.1.9'
5
- end
6
-
7
- it 'uses the expected YAML version' do
8
- expect(YAML::VERSION).to eq '2.0.5' # The escaping below changes with different YAML versions
9
- end
10
-
11
- it 'correctly escape a basic string' do
12
- expect(YAML.escape('brian')).to eq('brian')
13
- end
14
-
15
- it 'correctly escape a troublesome string' do
16
- expect(YAML.escape('{{moustache}} beard')).to eq('"{{moustache}} beard"')
17
- expect(YAML.escape("Brian O'Brien")).to eq("Brian O'Brien")
18
- end
19
- end
20
- end
data/spec/spec_helper.rb DELETED
@@ -1,29 +0,0 @@
1
- # CodeClimate code coverage reporting
2
- require 'codeclimate-test-reporter'
3
- CodeClimate::TestReporter.start
4
-
5
- unless ENV['NO_SIMPLECOV']
6
- require 'simplecov'
7
- require 'coveralls'
8
-
9
- if ENV['CIRCLE_ARTIFACTS']
10
- dir = File.join('..', '..', '..', ENV['CIRCLE_ARTIFACTS'], 'coverage')
11
- SimpleCov.coverage_dir(dir)
12
- end
13
-
14
- SimpleCov.start
15
- Coveralls.wear!('rails') if ENV['COVERALLS_REPO_TOKEN']
16
- end
17
-
18
- require 'foreplay'
19
-
20
- RSpec.configure do |config|
21
- # Run specs in random order to surface order dependencies. If you find an
22
- # order dependency and want to debug it, you can fix the order by providing
23
- # the seed, which is printed after each run.
24
- # --seed 1234
25
- config.order = 'random'
26
-
27
- # Manually-added
28
- config.tty = true
29
- end