infrataster 0.3.1 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (31) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +9 -1
  3. data/Gemfile +3 -0
  4. data/README.md +22 -3
  5. data/Rakefile +4 -21
  6. data/infrataster.gemspec +2 -1
  7. data/lib/infrataster.rb +1 -1
  8. data/lib/infrataster/contexts/http_context.rb +24 -7
  9. data/lib/infrataster/faraday_middlewares.rb +6 -0
  10. data/lib/infrataster/faraday_middlewares/follow_redirects.rb +16 -0
  11. data/lib/infrataster/resources/http_resource.rb +15 -2
  12. data/lib/infrataster/server.rb +1 -2
  13. data/lib/infrataster/version.rb +1 -1
  14. data/spec/integration/http_spec.rb +13 -1
  15. data/spec/integration/vm/.gitignore +1 -0
  16. data/spec/integration/vm/Vagrantfile +14 -22
  17. data/spec/integration/vm/recipes/app/default.rb +33 -0
  18. data/spec/integration/vm/{cookbooks/app/files/default → recipes/app/files/etc/supervisor/conf.d}/rackup.conf +0 -0
  19. data/spec/integration/vm/recipes/proxy/default.rb +33 -0
  20. data/spec/integration/vm/{cookbooks/proxy/files/default → recipes/proxy/files/etc/nginx}/.htpasswd +0 -0
  21. data/spec/integration/vm/{cookbooks/proxy/files/default → recipes/proxy/files/usr/share/nginx/html}/auth +0 -0
  22. data/spec/integration/vm/{cookbooks/proxy/files/default → recipes/proxy/files/usr/share/nginx/html}/index.html +0 -0
  23. data/spec/integration/vm/{cookbooks/proxy/templates/default → recipes/proxy/templates/etc/nginx/sites-available}/integration-test.erb +6 -2
  24. metadata +37 -29
  25. data/lib/infrataster/faraday_middleware.rb +0 -6
  26. data/lib/infrataster/faraday_middleware/gzip.rb +0 -68
  27. data/spec/integration/vm/cookbooks/app/recipes/default.rb +0 -35
  28. data/spec/integration/vm/cookbooks/apt-mirror/metadata.rb +0 -2
  29. data/spec/integration/vm/cookbooks/apt-mirror/recipes/default.rb +0 -12
  30. data/spec/integration/vm/cookbooks/proxy/recipes/default.rb +0 -29
  31. data/spec/integration/vm/vendor/.gitignore +0 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0ff908cf5e048950d98851d1c7f145458c03e9a5
4
- data.tar.gz: 17cab0279ab374e31e41f7fa5245c285805c3f5f
3
+ metadata.gz: 458a056dc79c4aea39aaf1040f28a68e2ac5fc70
4
+ data.tar.gz: ad3b19e91d96f101836921ee26eab9073560d793
5
5
  SHA512:
6
- metadata.gz: e210714e8f06214d61ecf493e81186e7b50b80909677c2349832115154acb0907e5a35967966f8dd56741625786078c589e8be96ac66e71558d37f00cce9334a
7
- data.tar.gz: c5c6aeaa5dd65b3162450c334f98323ff41dc2bb999a2e11d85acd1a9e0fc957fb645f67287d370edb22ec22170e901c25834816c3ab5a4faddcfd8ceddf84f0
6
+ metadata.gz: d63ef46773229efc07b2b72153a6ec93ecac8b2ab90327adf410ca4b2db4ed8303249060abbe31ee1bcf9f9c030273f3441b7bfb6252d89ee0332a686c3ef2cb
7
+ data.tar.gz: 4d268ba398749ff3987fc15cbabd8fe4125424339ed12cfdef37666182f97724d40935c881bd3ce2a499ec530023c3f4784544b16449b2a9fba506f4bfd50246
@@ -1,5 +1,14 @@
1
1
  # Infrataster Changelog
2
2
 
3
+ ## v0.3.2
4
+
5
+ * `http` resource: `faraday_middlewares` option
6
+ * `http` resource: `follow_redirects` option
7
+
8
+ ## v0.3.1
9
+
10
+ * Accept DNS name as server address.
11
+
3
12
  ## v0.3.0
4
13
 
5
14
  * [Fix deprecation of example_group in metadata (by @otahi)](https://github.com/ryotarai/infrataster/pull/64)
@@ -96,4 +105,3 @@
96
105
  ## v0.1.0
97
106
 
98
107
  * Initial release
99
-
data/Gemfile CHANGED
@@ -2,3 +2,6 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in infrataster.gemspec
4
4
  gemspec
5
+
6
+ gem 'vagrant', github: 'mitchellh/vagrant'
7
+ gem 'vagrant-itamae'
data/README.md CHANGED
@@ -242,20 +242,37 @@ describe server(:app) do
242
242
  # See: https://github.com/lostisland/faraday/blob/master/lib/faraday/response.rb
243
243
  end
244
244
  end
245
-
245
+
246
246
  # Gzip support
247
247
  describe http('http://app.example.com/gzipped') do
248
248
  it "responds with content deflated by gzip" do
249
249
  expect(response.headers['content-encoding']).to eq('gzip')
250
250
  end
251
251
  end
252
-
252
+
253
253
  describe http('http://app.example.com/gzipped', inflate_gzip: true) do
254
254
  it "responds with content inflated automatically" do
255
255
  expect(response.headers['content-encoding']).to be_nil
256
256
  expect(response.body).to eq('plain text')
257
257
  end
258
258
  end
259
+
260
+ # Redirects
261
+ describe http('http://app.example.com/redirect', follow_redirects: true) do
262
+ it "follows redirects" do
263
+ expect(response.status).to eq(200)
264
+ end
265
+ end
266
+
267
+ # Custom Faraday middleware
268
+ describe http('http://app.example.com', faraday_middleware: [
269
+ YourMiddleware,
270
+ [YourMiddleware, options]
271
+ ]) do
272
+ it "uses the middlewares" do
273
+ expect(response.status).to eq(200)
274
+ end
275
+ end
259
276
  end
260
277
  ```
261
278
 
@@ -333,7 +350,7 @@ $ bundle exec rake spec:integration:prepare
333
350
  $ bundle exec rake spec:integration
334
351
  ```
335
352
 
336
- ## Presentations
353
+ ## Presentations and Articles
337
354
 
338
355
  * https://speakerdeck.com/ryotarai/introducing-infrataster
339
356
 
@@ -342,6 +359,8 @@ $ bundle exec rake spec:integration
342
359
  </a>
343
360
 
344
361
  * https://speakerdeck.com/ryotarai/infrataster-infra-behavior-testing-framework-number-oedo04
362
+ * [Infratasterでリバースプロキシのテストをする](http://techlife.cookpad.com/entry/2014/11/19/151557)
363
+ * Google-Translated: [Testing reverse proxy with Infrataster](https://translate.google.com/translate?hl=ja&sl=ja&tl=en&u=http%3A%2F%2Ftechlife.cookpad.com%2Fentry%2F2014%2F11%2F19%2F151557)
345
364
 
346
365
  ## Changelog
347
366
 
data/Rakefile CHANGED
@@ -25,38 +25,21 @@ namespace :spec do
25
25
  integration_dir = 'spec/integration'
26
26
 
27
27
  desc 'Clean'
28
- task :clean => ['destroy_vm', 'remove_berks'] do
28
+ task :clean => ['destroy_vm'] do
29
29
  end
30
30
 
31
31
  desc 'Prepare'
32
32
  task :prepare => ['start_vm'] do
33
33
  end
34
34
 
35
- task :berks_vendor do
36
- dir = File.join(integration_dir, 'vm/vendor/cookbooks')
37
- # Berkshelf
38
- if Dir.exist?(dir)
39
- puts yellow("'#{dir}' already exists. If you want update cookbooks, delete the directory and re-run rake command")
40
- else
41
- puts yellow('Installing cookbooks by berkshelf...')
42
- system "cd #{integration_dir}/vm && berks vendor vendor/cookbooks"
43
- end
44
- end
45
-
46
- task :start_vm => ['berks_vendor'] do
35
+ task :start_vm do
47
36
  puts yellow('Starting VM...')
48
- system '/usr/bin/vagrant up'
37
+ system 'vagrant', 'up'
49
38
  end
50
39
 
51
40
  task :destroy_vm do
52
41
  puts yellow('Destroying VM...')
53
- system '/usr/bin/vagrant destroy -f'
54
- end
55
-
56
- task :remove_berks do
57
- dir = File.join(integration_dir, 'vm/vendor/cookbooks')
58
- FileUtils.rm_rf(dir)
42
+ system 'vagrant', 'destroy', '-f'
59
43
  end
60
44
  end
61
45
  end
62
-
@@ -26,9 +26,10 @@ Gem::Specification.new do |spec|
26
26
  spec.add_runtime_dependency "capybara"
27
27
  spec.add_runtime_dependency "poltergeist"
28
28
  spec.add_runtime_dependency "faraday"
29
+ spec.add_runtime_dependency "faraday_middleware", '>= 0.10.0'
29
30
  spec.add_runtime_dependency "thor"
30
31
 
31
32
  spec.add_development_dependency "bundler", "~> 1.5"
32
33
  spec.add_development_dependency "rake"
33
- spec.add_development_dependency "berkshelf", '~> 3.1.1'
34
+ spec.add_development_dependency "itamae"
34
35
  end
@@ -3,7 +3,7 @@ require "infrataster/resources"
3
3
  require "infrataster/server"
4
4
  require "infrataster/helpers"
5
5
  require "infrataster/contexts"
6
- require "infrataster/faraday_middleware"
6
+ require "infrataster/faraday_middlewares"
7
7
  require 'logger'
8
8
 
9
9
  module Infrataster
@@ -1,4 +1,5 @@
1
1
  require 'faraday'
2
+ require 'faraday_middleware'
2
3
 
3
4
  module Infrataster
4
5
  module Contexts
@@ -7,16 +8,18 @@ module Infrataster
7
8
  server.forward_port(resource.uri.port) do |address, port|
8
9
  url = "#{resource.uri.scheme}://#{address}:#{port}"
9
10
  options = {:url => url}
10
-
11
+
11
12
  if resource.uri.scheme == 'https'
12
13
  options[:ssl] = resource.ssl_option
13
14
  end
14
-
15
+
16
+ host = determine_host(address)
17
+
15
18
  conn = Faraday.new(options) do |faraday|
16
19
  faraday.request :url_encoded
17
20
  faraday.response :logger, Logger
18
- if resource.inflate_gzip?
19
- faraday.use Infrataster::FaradayMiddleware::Gzip
21
+ middlewares(host => address).each do |middleware|
22
+ faraday.use(*middleware)
20
23
  end
21
24
  faraday.adapter Faraday.default_adapter
22
25
  faraday.basic_auth(*resource.basic_auth) if resource.basic_auth
@@ -26,7 +29,7 @@ module Infrataster
26
29
  resource.params.each_pair do |k, v|
27
30
  req.params[k] = v
28
31
  end
29
- req.headers['Host'] = determine_host(address)
32
+ req.headers['Host'] = host
30
33
  resource.headers.each_pair do |k, v|
31
34
  req.headers[k] = v
32
35
  end
@@ -41,8 +44,22 @@ module Infrataster
41
44
  def determine_host(default)
42
45
  resource.uri.host || (server.options[:http] && server.options[:http][:host]) || default
43
46
  end
47
+
48
+ private
49
+
50
+ def middlewares(host_mapping)
51
+ host_mapping = resource.host_mapping.merge(host_mapping)
52
+
53
+ ms = resource.faraday_middlewares.dup
54
+ if resource.follow_redirects?
55
+ ms << [Infrataster::FaradayMiddlewares::FollowRedirects, host_mapping: host_mapping]
56
+ end
57
+ if resource.inflate_gzip?
58
+ ms << [FaradayMiddleware::Gzip]
59
+ end
60
+
61
+ ms
62
+ end
44
63
  end
45
64
  end
46
65
  end
47
-
48
-
@@ -0,0 +1,6 @@
1
+ require 'infrataster/faraday_middlewares/follow_redirects'
2
+
3
+ module Infrataster
4
+ module FaradayMiddlewares
5
+ end
6
+ end
@@ -0,0 +1,16 @@
1
+ require 'faraday_middleware'
2
+
3
+ module Infrataster
4
+ module FaradayMiddlewares
5
+ class FollowRedirects < ::FaradayMiddleware::FollowRedirects
6
+ def update_env(env, request_body, response)
7
+ super.tap do |e|
8
+ if replacement = @options[:host_mapping][e[:url].hostname]
9
+ e[:request_headers]['Host'] = e[:url].hostname
10
+ e[:url].hostname = replacement
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -40,7 +40,7 @@ module Infrataster
40
40
  def headers
41
41
  @options[:headers]
42
42
  end
43
-
43
+
44
44
  def body
45
45
  @options[:body]
46
46
  end
@@ -56,7 +56,20 @@ module Infrataster
56
56
  def inflate_gzip?
57
57
  !!@options[:inflate_gzip]
58
58
  end
59
+
60
+ def follow_redirects?
61
+ !!@options[:follow_redirects]
62
+ end
63
+
64
+ def faraday_middlewares
65
+ (@options[:faraday_middlewares] || []).map do |m|
66
+ Array(m)
67
+ end
68
+ end
69
+
70
+ def host_mapping
71
+ @options[:host_mapping] || {}
72
+ end
59
73
  end
60
74
  end
61
75
  end
62
-
@@ -142,7 +142,7 @@ module Infrataster
142
142
 
143
143
  Dir.mktmpdir do |dir|
144
144
  output = File.join(dir, 'ssh-config')
145
- `/usr/bin/vagrant ssh-config #{Shellwords.shellescape(name)} > #{Shellwords.shellescape(output)}`
145
+ `vagrant ssh-config #{Shellwords.shellescape(name)} > #{Shellwords.shellescape(output)}`
146
146
  if $?.exitstatus != 0
147
147
  raise Error, "`vagrant ssh-config` failed. Please check if VMs are running or not."
148
148
  end
@@ -196,4 +196,3 @@ module Infrataster
196
196
  end
197
197
  end
198
198
  end
199
-
@@ -1,3 +1,3 @@
1
1
  module Infrataster
2
- VERSION = "0.3.1"
2
+ VERSION = "0.3.2"
3
3
  end
@@ -39,6 +39,19 @@ describe server(:proxy) do
39
39
  expect(response.body).to include('auth')
40
40
  end
41
41
  end
42
+
43
+ describe http('http://static.example.com/redirect') do
44
+ it "doesn't follow redirects" do
45
+ expect(response.status).to eq 302
46
+ end
47
+ end
48
+
49
+ describe http('http://static.example.com/redirect', follow_redirects: true) do
50
+ it "follows redirects" do
51
+ expect(response.status).to eq 200
52
+ expect(response.body).to eq("This is static site.\n")
53
+ end
54
+ end
42
55
  end
43
56
 
44
57
  describe server(:app) do
@@ -101,4 +114,3 @@ describe server(:example_com) do
101
114
  end
102
115
  end
103
116
  end
104
-
@@ -1,2 +1,3 @@
1
1
  .vagrant
2
2
  Berksfile.lock
3
+ /node.json
@@ -1,48 +1,40 @@
1
1
  # -*- mode: ruby -*-
2
2
  # vi: set ft=ruby :
3
3
 
4
+ require 'vagrant-itamae'
5
+
4
6
  # Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
5
7
  VAGRANTFILE_API_VERSION = "2"
6
- COOKBOOK_PATH = ['./cookbooks', './vendor/cookbooks']
7
8
 
8
9
  INTERNAL_ADDRESSES = {
9
10
  'proxy' => '172.16.44.10',
10
11
  'app' => '172.16.44.11',
11
12
  }
12
13
 
13
- Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
14
- if ENV['CI']
15
- config.vm.box = "hashicorp/precise32"
16
- else
17
- config.vm.box = "hashicorp/precise64"
18
- end
14
+ node_json = File.join(__dir__, 'node.json')
15
+ File.write(node_json, {'addresses' => INTERNAL_ADDRESSES}.to_json)
19
16
 
20
- if ENV['CI']
21
- config.vm.provider "virtualbox" do |v|
22
- v.customize ["modifyvm", :id, "--memory", "256"]
23
- end
24
- end
17
+ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
18
+ config.vm.box = "ubuntu/trusty64"
25
19
 
26
20
  config.vm.define :proxy do |c|
27
21
  c.vm.network "private_network", ip: "192.168.44.10"
28
22
  c.vm.network "private_network", ip: INTERNAL_ADDRESSES['proxy'], virtualbox__intnet: "infrataster-integration-test"
29
23
 
30
- c.vm.provision "chef_solo" do |chef|
31
- chef.cookbooks_path = COOKBOOK_PATH
32
- chef.add_recipe "apt-mirror"
33
- chef.add_recipe "proxy"
34
- chef.json = {'addresses' => INTERNAL_ADDRESSES}
24
+ c.vm.provision :itamae do |c|
25
+ c.sudo = true
26
+ c.recipes = [File.join(__dir__, 'recipes/proxy/default.rb')]
27
+ c.json = node_json
35
28
  end
36
29
  end
37
30
 
38
31
  config.vm.define :app do |c|
39
32
  c.vm.network "private_network", ip: INTERNAL_ADDRESSES['app'], virtualbox__intnet: "infrataster-integration-test"
40
33
 
41
- c.vm.provision "chef_solo" do |chef|
42
- chef.cookbooks_path = COOKBOOK_PATH
43
- chef.add_recipe "apt-mirror"
44
- chef.add_recipe "app"
45
- chef.json = {'addresses' => INTERNAL_ADDRESSES}
34
+ c.vm.provision :itamae do |c|
35
+ c.sudo = true
36
+ c.recipes = [File.join(__dir__, 'recipes/app/default.rb')]
37
+ c.json = node_json
46
38
  end
47
39
  end
48
40
  end
@@ -0,0 +1,33 @@
1
+ execute "sed -i -e 's|http://archive.ubuntu.com/ubuntu|mirror://mirrors.ubuntu.com/mirrors.txt|g' /etc/apt/sources.list"
2
+
3
+ execute 'apt-get update'
4
+
5
+ package 'python-software-properties'
6
+
7
+ execute 'apt-add-repository -y ppa:brightbox/ruby-ng && apt-get update'
8
+
9
+ package 'build-essential'
10
+
11
+ package 'ruby2.2'
12
+
13
+ package 'ruby2.2-dev'
14
+
15
+ gem_package "bundler"
16
+
17
+ execute 'bundle install' do
18
+ cwd '/vagrant/app'
19
+ end
20
+
21
+ # supervisor
22
+ package 'supervisor'
23
+
24
+ execute 'reload supervisor' do
25
+ command 'supervisorctl reload'
26
+ action :nothing
27
+ end
28
+
29
+ remote_file '/etc/supervisor/conf.d/rackup.conf' do
30
+ notifies :run, 'execute[reload supervisor]'
31
+ end
32
+
33
+ execute 'supervisorctl restart rackup'
@@ -0,0 +1,33 @@
1
+ execute "sed -i -e 's|http://archive.ubuntu.com/ubuntu|mirror://mirrors.ubuntu.com/mirrors.txt|g' /etc/apt/sources.list"
2
+
3
+ execute 'apt-get update'
4
+
5
+ package 'nginx'
6
+
7
+ service 'nginx' do
8
+ action :start
9
+ end
10
+
11
+ file '/etc/nginx/sites-enabled/default' do
12
+ action :delete
13
+ end
14
+
15
+ template '/etc/nginx/sites-available/integration-test' do
16
+ notifies :restart, 'service[nginx]'
17
+ end
18
+
19
+ link '/etc/nginx/sites-enabled/integration-test' do
20
+ to '/etc/nginx/sites-available/integration-test'
21
+ end
22
+
23
+ remote_file '/usr/share/nginx/html/index.html' do
24
+ mode '644'
25
+ end
26
+
27
+ remote_file '/usr/share/nginx/html/auth' do
28
+ mode '644'
29
+ end
30
+
31
+ remote_file '/etc/nginx/.htpasswd' do
32
+ mode '644'
33
+ end
@@ -4,7 +4,7 @@ server {
4
4
  gzip on;
5
5
  gzip_min_length 0;
6
6
 
7
- root /usr/share/nginx/www;
7
+ root /usr/share/nginx/html;
8
8
  index index.html index.htm;
9
9
 
10
10
  server_name static.example.com;
@@ -17,12 +17,16 @@ server {
17
17
  auth_basic "Restricted";
18
18
  auth_basic_user_file /etc/nginx/.htpasswd;
19
19
  }
20
+
21
+ location = /redirect {
22
+ return 302 http://$server_name/;
23
+ }
20
24
  }
21
25
 
22
26
  server {
23
27
  listen 80;
24
28
 
25
- root /usr/share/nginx/www;
29
+ root /usr/share/nginx/html;
26
30
  index index.html index.htm;
27
31
 
28
32
  server_name app.example.com;
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: infrataster
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryota Arai
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-10-13 00:00:00.000000000 Z
11
+ date: 2015-11-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -100,6 +100,20 @@ dependencies:
100
100
  - - ">="
101
101
  - !ruby/object:Gem::Version
102
102
  version: '0'
103
+ - !ruby/object:Gem::Dependency
104
+ name: faraday_middleware
105
+ requirement: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: 0.10.0
110
+ type: :runtime
111
+ prerelease: false
112
+ version_requirements: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: 0.10.0
103
117
  - !ruby/object:Gem::Dependency
104
118
  name: thor
105
119
  requirement: !ruby/object:Gem::Requirement
@@ -143,19 +157,19 @@ dependencies:
143
157
  - !ruby/object:Gem::Version
144
158
  version: '0'
145
159
  - !ruby/object:Gem::Dependency
146
- name: berkshelf
160
+ name: itamae
147
161
  requirement: !ruby/object:Gem::Requirement
148
162
  requirements:
149
- - - "~>"
163
+ - - ">="
150
164
  - !ruby/object:Gem::Version
151
- version: 3.1.1
165
+ version: '0'
152
166
  type: :development
153
167
  prerelease: false
154
168
  version_requirements: !ruby/object:Gem::Requirement
155
169
  requirements:
156
- - - "~>"
170
+ - - ">="
157
171
  - !ruby/object:Gem::Version
158
- version: 3.1.1
172
+ version: '0'
159
173
  description:
160
174
  email:
161
175
  - ryota.arai@gmail.com
@@ -180,8 +194,8 @@ files:
180
194
  - lib/infrataster/contexts/capybara_context.rb
181
195
  - lib/infrataster/contexts/http_context.rb
182
196
  - lib/infrataster/contexts/no_resource_context.rb
183
- - lib/infrataster/faraday_middleware.rb
184
- - lib/infrataster/faraday_middleware/gzip.rb
197
+ - lib/infrataster/faraday_middlewares.rb
198
+ - lib/infrataster/faraday_middlewares/follow_redirects.rb
185
199
  - lib/infrataster/fixtures/Gemfile.erb
186
200
  - lib/infrataster/fixtures/Rakefile.erb
187
201
  - lib/infrataster/fixtures/Vagrantfile.erb
@@ -208,16 +222,13 @@ files:
208
222
  - spec/integration/vm/app/Gemfile
209
223
  - spec/integration/vm/app/app.rb
210
224
  - spec/integration/vm/app/config.ru
211
- - spec/integration/vm/cookbooks/app/files/default/rackup.conf
212
- - spec/integration/vm/cookbooks/app/recipes/default.rb
213
- - spec/integration/vm/cookbooks/apt-mirror/metadata.rb
214
- - spec/integration/vm/cookbooks/apt-mirror/recipes/default.rb
215
- - spec/integration/vm/cookbooks/proxy/files/default/.htpasswd
216
- - spec/integration/vm/cookbooks/proxy/files/default/auth
217
- - spec/integration/vm/cookbooks/proxy/files/default/index.html
218
- - spec/integration/vm/cookbooks/proxy/recipes/default.rb
219
- - spec/integration/vm/cookbooks/proxy/templates/default/integration-test.erb
220
- - spec/integration/vm/vendor/.gitignore
225
+ - spec/integration/vm/recipes/app/default.rb
226
+ - spec/integration/vm/recipes/app/files/etc/supervisor/conf.d/rackup.conf
227
+ - spec/integration/vm/recipes/proxy/default.rb
228
+ - spec/integration/vm/recipes/proxy/files/etc/nginx/.htpasswd
229
+ - spec/integration/vm/recipes/proxy/files/usr/share/nginx/html/auth
230
+ - spec/integration/vm/recipes/proxy/files/usr/share/nginx/html/index.html
231
+ - spec/integration/vm/recipes/proxy/templates/etc/nginx/sites-available/integration-test.erb
221
232
  - spec/unit/lib/infrataster/contexts/http_context_spec.rb
222
233
  - spec/unit/lib/infrataster/resources/http_resource_spec.rb
223
234
  - spec/unit/lib/infrataster/server_spec.rb
@@ -257,16 +268,13 @@ test_files:
257
268
  - spec/integration/vm/app/Gemfile
258
269
  - spec/integration/vm/app/app.rb
259
270
  - spec/integration/vm/app/config.ru
260
- - spec/integration/vm/cookbooks/app/files/default/rackup.conf
261
- - spec/integration/vm/cookbooks/app/recipes/default.rb
262
- - spec/integration/vm/cookbooks/apt-mirror/metadata.rb
263
- - spec/integration/vm/cookbooks/apt-mirror/recipes/default.rb
264
- - spec/integration/vm/cookbooks/proxy/files/default/.htpasswd
265
- - spec/integration/vm/cookbooks/proxy/files/default/auth
266
- - spec/integration/vm/cookbooks/proxy/files/default/index.html
267
- - spec/integration/vm/cookbooks/proxy/recipes/default.rb
268
- - spec/integration/vm/cookbooks/proxy/templates/default/integration-test.erb
269
- - spec/integration/vm/vendor/.gitignore
271
+ - spec/integration/vm/recipes/app/default.rb
272
+ - spec/integration/vm/recipes/app/files/etc/supervisor/conf.d/rackup.conf
273
+ - spec/integration/vm/recipes/proxy/default.rb
274
+ - spec/integration/vm/recipes/proxy/files/etc/nginx/.htpasswd
275
+ - spec/integration/vm/recipes/proxy/files/usr/share/nginx/html/auth
276
+ - spec/integration/vm/recipes/proxy/files/usr/share/nginx/html/index.html
277
+ - spec/integration/vm/recipes/proxy/templates/etc/nginx/sites-available/integration-test.erb
270
278
  - spec/unit/lib/infrataster/contexts/http_context_spec.rb
271
279
  - spec/unit/lib/infrataster/resources/http_resource_spec.rb
272
280
  - spec/unit/lib/infrataster/server_spec.rb
@@ -1,6 +0,0 @@
1
- require 'infrataster/faraday_middleware/gzip'
2
-
3
- module Infrataster
4
- module FaradayMiddleware
5
- end
6
- end
@@ -1,68 +0,0 @@
1
- # This module is ported from faraday_middleware:
2
- # https://github.com/lostisland/faraday_middleware/blob/138766e3d1cfd58b01d1c3ccb453bb8bc7c1633a/lib/faraday_middleware/gzip.rb
3
- #
4
- # Copyright (c) 2011 Erik Michaels-Ober, Wynn Netherland, et al.
5
- #
6
- # Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
7
- #
8
- # The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
9
- #
10
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
11
-
12
- require 'faraday'
13
-
14
- module Infrataster
15
- module FaradayMiddleware
16
- # Middleware to automatically decompress response bodies. If the
17
- # "Accept-Encoding" header wasn't set in the request, this sets it to
18
- # "gzip,deflate" and appropriately handles the compressed response from the
19
- # server. This resembles what Ruby 1.9+ does internally in Net::HTTP#get.
20
- #
21
- # This middleware is NOT necessary when these adapters are used:
22
- # - net_http on Ruby 1.9+
23
- # - net_http_persistent on Ruby 2.0+
24
- # - em_http
25
- class Gzip < Faraday::Middleware
26
- dependency 'zlib'
27
-
28
- ACCEPT_ENCODING = 'Accept-Encoding'.freeze
29
- CONTENT_ENCODING = 'Content-Encoding'.freeze
30
- CONTENT_LENGTH = 'Content-Length'.freeze
31
- SUPPORTED_ENCODINGS = 'gzip,deflate'.freeze
32
- RUBY_ENCODING = '1.9'.respond_to?(:force_encoding)
33
-
34
- def call(env)
35
- env[:request_headers][ACCEPT_ENCODING] ||= SUPPORTED_ENCODINGS
36
- @app.call(env).on_complete do |response_env|
37
- case response_env[:response_headers][CONTENT_ENCODING]
38
- when 'gzip'
39
- reset_body(response_env, &method(:uncompress_gzip))
40
- when 'deflate'
41
- reset_body(response_env, &method(:inflate))
42
- end
43
- end
44
- end
45
-
46
- def reset_body(env)
47
- env[:body] = yield(env[:body])
48
- env[:response_headers].delete(CONTENT_ENCODING)
49
- env[:response_headers][CONTENT_LENGTH] = env[:body].length
50
- end
51
-
52
- def uncompress_gzip(body)
53
- io = StringIO.new(body)
54
- gzip_reader = if RUBY_ENCODING
55
- Zlib::GzipReader.new(io, :encoding => 'ASCII-8BIT')
56
- else
57
- Zlib::GzipReader.new(io)
58
- end
59
- gzip_reader.read
60
- end
61
-
62
- def inflate(body)
63
- Zlib::Inflate.inflate(body)
64
- end
65
- end
66
- end
67
- end
68
-
@@ -1,35 +0,0 @@
1
- # install ruby and so on
2
- package 'python-software-properties'
3
-
4
- execute 'apt-add-repository ppa:brightbox/ruby-ng && apt-get update' do
5
- not_if 'test -e /etc/apt/sources.list.d/brightbox-ruby-ng-precise.list'
6
- end
7
-
8
- package 'build-essential'
9
-
10
- package 'ruby2.1'
11
-
12
- package 'ruby2.1-dev'
13
-
14
- execute 'gem install bundler' do
15
- not_if "gem list | grep -q 'bundler '"
16
- end
17
-
18
- execute 'bundle install' do
19
- cwd '/vagrant/app'
20
- end
21
-
22
- # supervisor
23
- package 'supervisor'
24
-
25
- execute 'reload supervisor' do
26
- command 'supervisorctl reload'
27
- action :nothing
28
- end
29
-
30
- cookbook_file '/etc/supervisor/conf.d/rackup.conf' do
31
- notifies :run, 'execute[reload supervisor]'
32
- end
33
-
34
- execute 'supervisorctl restart rackup'
35
-
@@ -1,2 +0,0 @@
1
- name 'apt-mirror'
2
- depends 'apt'
@@ -1,12 +0,0 @@
1
- require 'net/http'
2
- require 'uri'
3
-
4
- apt_servers = Net::HTTP.get(URI.parse('http://mirrors.ubuntu.com/mirrors.txt')).split("\n")
5
- # ftp.riken.jp is unstable and slow?
6
- apt_servers.delete('http://ftp.riken.jp/Linux/ubuntu/')
7
- apt_server = apt_servers[rand(apt_servers.size)]
8
-
9
- execute "sed -i -e 's| \\(http[^ ]\\+\\)| #{apt_server}|g' /etc/apt/sources.list"
10
-
11
- include_recipe 'apt'
12
-
@@ -1,29 +0,0 @@
1
- package 'nginx'
2
-
3
- service 'nginx' do
4
- action :start
5
- supports :restart => true
6
- end
7
-
8
- file '/etc/nginx/sites-enabled/default' do
9
- action :delete
10
- end
11
-
12
- template '/etc/nginx/sites-available/integration-test'
13
-
14
- link '/etc/nginx/sites-enabled/integration-test' do
15
- to '/etc/nginx/sites-available/integration-test'
16
- notifies :restart, 'service[nginx]'
17
- end
18
-
19
- cookbook_file '/usr/share/nginx/www/index.html' do
20
- mode '0644'
21
- end
22
-
23
- cookbook_file '/usr/share/nginx/www/auth' do
24
- mode '0644'
25
- end
26
-
27
- cookbook_file '/etc/nginx/.htpasswd' do
28
- mode '0644'
29
- end
@@ -1,2 +0,0 @@
1
- *
2
- !.gitignore