poise-application-ruby 4.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +11 -0
  3. data/.kitchen.travis.yml +9 -0
  4. data/.kitchen.yml +10 -0
  5. data/.travis.yml +21 -0
  6. data/.yardopts +3 -0
  7. data/Berksfile +35 -0
  8. data/CHANGELOG.md +82 -0
  9. data/Gemfile +37 -0
  10. data/LICENSE +201 -0
  11. data/README.md +271 -0
  12. data/Rakefile +17 -0
  13. data/SUPPORTERS.md +81 -0
  14. data/chef/templates/database.yml.erb +3 -0
  15. data/chef/templates/secrets.yml.erb +3 -0
  16. data/lib/poise_application_ruby.rb +24 -0
  17. data/lib/poise_application_ruby/app_mixin.rb +92 -0
  18. data/lib/poise_application_ruby/cheftie.rb +17 -0
  19. data/lib/poise_application_ruby/error.rb +25 -0
  20. data/lib/poise_application_ruby/resources.rb +24 -0
  21. data/lib/poise_application_ruby/resources/bundle_install.rb +54 -0
  22. data/lib/poise_application_ruby/resources/rackup.rb +70 -0
  23. data/lib/poise_application_ruby/resources/rails.rb +260 -0
  24. data/lib/poise_application_ruby/resources/ruby.rb +57 -0
  25. data/lib/poise_application_ruby/resources/ruby_execute.rb +89 -0
  26. data/lib/poise_application_ruby/resources/ruby_gem.rb +46 -0
  27. data/lib/poise_application_ruby/resources/thin.rb +64 -0
  28. data/lib/poise_application_ruby/resources/unicorn.rb +87 -0
  29. data/lib/poise_application_ruby/service_mixin.rb +66 -0
  30. data/lib/poise_application_ruby/version.rb +19 -0
  31. data/poise-application-ruby.gemspec +45 -0
  32. data/test/cookbooks/application_ruby_test/attributes/default.rb +17 -0
  33. data/test/cookbooks/application_ruby_test/metadata.rb +20 -0
  34. data/test/cookbooks/application_ruby_test/recipes/default.rb +66 -0
  35. data/test/cookbooks/application_ruby_test/recipes/rails.rb +41 -0
  36. data/test/cookbooks/application_ruby_test/recipes/sinatra.rb +29 -0
  37. data/test/gemfiles/chef-12.gemfile +19 -0
  38. data/test/gemfiles/master.gemfile +27 -0
  39. data/test/integration/default/serverspec/default_spec.rb +44 -0
  40. data/test/integration/default/serverspec/rails_spec.rb +41 -0
  41. data/test/integration/default/serverspec/sinatra_spec.rb +40 -0
  42. data/test/spec/resources/ruby_execute_spec.rb +46 -0
  43. data/test/spec/spec_helper.rb +20 -0
  44. metadata +202 -0
@@ -0,0 +1,57 @@
1
+ #
2
+ # Copyright 2015, Noah Kantrowitz
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ require 'poise_ruby/resources/ruby_runtime'
18
+
19
+ require 'poise_application_ruby/app_mixin'
20
+
21
+
22
+ module PoiseApplicationRuby
23
+ module Resources
24
+ # (see Ruby::Resource)
25
+ # @since 4.0.0
26
+ module Ruby
27
+ # An `application_ruby` resource to manage Ruby runtimes
28
+ # inside an Application cookbook deployment.
29
+ #
30
+ # @provides application_ruby
31
+ # @provides application_ruby_runtime
32
+ # @action install
33
+ # @action uninstall
34
+ # @example
35
+ # application '/app' do
36
+ # ruby '2'
37
+ # end
38
+ class Resource < PoiseRuby::Resources::RubyRuntime::Resource
39
+ include PoiseApplicationRuby::AppMixin
40
+ provides(:application_ruby)
41
+ provides(:application_ruby_runtime)
42
+ container_default(false)
43
+ subclass_providers!
44
+
45
+ # Set this resource as the app_state's parent ruby.
46
+ #
47
+ # @api private
48
+ def after_created
49
+ super.tap do |val|
50
+ app_state_ruby(self)
51
+ end
52
+ end
53
+
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,89 @@
1
+ #
2
+ # Copyright 2015, Noah Kantrowitz
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ require 'poise_ruby/resources/ruby_execute'
18
+
19
+ require 'poise_application_ruby/app_mixin'
20
+
21
+
22
+ module PoiseApplicationRuby
23
+ module Resources
24
+ # (see RubyExecute::Resource)
25
+ # @since 4.0.0
26
+ module RubyExecute
27
+ # An `application_ruby_execute` resource to run Ruby commands inside an
28
+ # Application cookbook deployment.
29
+ #
30
+ # @provides application_ruby_execute
31
+ # @action run
32
+ # @example
33
+ # application '/srv/myapp' do
34
+ # ruby_execute 'rake build'
35
+ # end
36
+ class Resource < PoiseRuby::Resources::RubyExecute::Resource
37
+ include PoiseApplicationRuby::AppMixin
38
+ provides(:application_ruby_execute)
39
+
40
+ def initialize(*args)
41
+ super
42
+ # Clear some instance variables so my defaults work.
43
+ remove_instance_variable(:@cwd)
44
+ remove_instance_variable(:@group)
45
+ remove_instance_variable(:@user)
46
+ end
47
+
48
+ # #!attribute cwd
49
+ # Override the default directory to be the app path if unspecified.
50
+ # @return [String]
51
+ attribute(:cwd, kind_of: [String, NilClass, FalseClass], default: lazy { parent && parent.path })
52
+
53
+ # #!attribute group
54
+ # Override the default group to be the app group if unspecified.
55
+ # @return [String, Integer]
56
+ attribute(:group, kind_of: [String, Integer, NilClass, FalseClass], default: lazy { parent && parent.group })
57
+
58
+ # #!attribute user
59
+ # Override the default user to be the app owner if unspecified.
60
+ # @return [String, Integer]
61
+ attribute(:user, kind_of: [String, Integer, NilClass, FalseClass], default: lazy { parent && parent.owner })
62
+ end
63
+
64
+ # The default provider for `application_ruby_execute`.
65
+ #
66
+ # @see Resource
67
+ # @provides application_ruby_execute
68
+ class Provider < PoiseRuby::Resources::RubyExecute::Provider
69
+ provides(:application_ruby_execute)
70
+
71
+ private
72
+
73
+ # Override environment to add the application envivonrment instead.
74
+ #
75
+ # @return [Hash]
76
+ def environment
77
+ super.tap do |environment|
78
+ # Don't use the app_state_environment_ruby because we already have
79
+ # those values in place.
80
+ environment.update(new_resource.app_state_environment)
81
+ # Re-apply the resource environment for correct ordering.
82
+ environment.update(new_resource.environment) if new_resource.environment
83
+ end
84
+ end
85
+ end
86
+
87
+ end
88
+ end
89
+ end
@@ -0,0 +1,46 @@
1
+ #
2
+ # Copyright 2015, Noah Kantrowitz
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ require 'poise_ruby/resources/ruby_gem'
18
+
19
+ require 'poise_application_ruby/app_mixin'
20
+
21
+
22
+ module PoiseApplicationRuby
23
+ module Resources
24
+ # (see RubyGem::Resource)
25
+ # @since 4.0.0
26
+ module RubyGem
27
+ # An `application_ruby_gem` resource to install Ruby gems inside an
28
+ # Application cookbook deployment.
29
+ #
30
+ # @provides application_ruby_gem
31
+ # @action install
32
+ # @action upgrade
33
+ # @action remove
34
+ # @example
35
+ # application '/srv/myapp' do
36
+ # ruby_gem 'rack'
37
+ # end
38
+ class Resource < PoiseRuby::Resources::RubyGem::Resource
39
+ include PoiseApplicationRuby::AppMixin
40
+ provides(:application_ruby_gem)
41
+ subclass_providers!
42
+ end
43
+
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,64 @@
1
+ #
2
+ # Copyright 2015, Noah Kantrowitz
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ require 'chef/provider'
18
+ require 'chef/resource'
19
+
20
+ require 'poise_application_ruby/service_mixin'
21
+
22
+
23
+ module PoiseApplicationRuby
24
+ module Resources
25
+ # (see Thin::Resource)
26
+ # @since 4.0.0
27
+ module Thin
28
+ class Resource < Chef::Resource
29
+ include PoiseApplicationRuby::ServiceMixin
30
+ provides(:application_thin)
31
+
32
+ attribute(:port, kind_of: [String, Integer], default: 80)
33
+ attribute(:config_path, kind_of: String)
34
+ end
35
+
36
+ class Provider < Chef::Provider
37
+ include PoiseApplicationRuby::ServiceMixin
38
+ provides(:application_thin)
39
+
40
+ private
41
+
42
+ # Find the path to the config.ru. If the resource path was to a
43
+ # directory, apparent /config.ru.
44
+ #
45
+ # @return [String]
46
+ def configru_path
47
+ @configru_path ||= if ::File.directory?(new_resource.path)
48
+ ::File.join(new_resource.path, 'config.ru')
49
+ else
50
+ new_resource.path
51
+ end
52
+ end
53
+
54
+ # (see PoiseApplication::ServiceMixin#service_options)
55
+ def service_options(resource)
56
+ super
57
+ cmd = "thin --rackup #{configru_path} --port #{new_resource.port}"
58
+ cmd << " --config #{::File.expand_path(new_resource.config_path, new_resource.path)}" if new_resource.config_path
59
+ resource.ruby_command(cmd)
60
+ end
61
+ end
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,87 @@
1
+ #
2
+ # Copyright 2015, Noah Kantrowitz
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ require 'chef/provider'
18
+ require 'chef/resource'
19
+
20
+ require 'poise_application_ruby/service_mixin'
21
+
22
+
23
+ module PoiseApplicationRuby
24
+ module Resources
25
+ # (see Unicorn::Resource)
26
+ # @since 4.0.0
27
+ module Unicorn
28
+ # An `application_unicorn` resource to manage a unicorn web application
29
+ # server.
30
+ #
31
+ # @since 4.0.0
32
+ # @provides application_unicorn
33
+ # @action enable
34
+ # @action disable
35
+ # @action start
36
+ # @action stop
37
+ # @action restart
38
+ # @action reload
39
+ # @example
40
+ # application '/srv/myapp' do
41
+ # git '...'
42
+ # bundle_install
43
+ # unicorn do
44
+ # port 8080
45
+ # end
46
+ # end
47
+ class Resource < Chef::Resource
48
+ include PoiseApplicationRuby::ServiceMixin
49
+ provides(:application_unicorn)
50
+
51
+ # @!attribute port
52
+ # Port to bind to.
53
+ attribute(:port, kind_of: [String, Integer], default: 80)
54
+ end
55
+
56
+ # Provider for `application_unicorn`.
57
+ #
58
+ # @since 4.0.0
59
+ # @see Resource
60
+ # @provides application_unicorn
61
+ class Provider < Chef::Provider
62
+ include PoiseApplicationRuby::ServiceMixin
63
+ provides(:application_unicorn)
64
+
65
+ private
66
+
67
+ # Find the path to the config.ru. If the resource path was to a
68
+ # directory, apparent /config.ru.
69
+ #
70
+ # @return [String]
71
+ def configru_path
72
+ @configru_path ||= if ::File.directory?(new_resource.path)
73
+ ::File.join(new_resource.path, 'config.ru')
74
+ else
75
+ new_resource.path
76
+ end
77
+ end
78
+
79
+ # Set service resource options.
80
+ def service_options(resource)
81
+ super
82
+ resource.ruby_command("unicorn --port #{new_resource.port} #{configru_path}")
83
+ end
84
+ end
85
+ end
86
+ end
87
+ end
@@ -0,0 +1,66 @@
1
+ #
2
+ # Copyright 2015, Noah Kantrowitz
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ require 'poise/utils'
18
+ require 'poise_application/service_mixin'
19
+ require 'poise_languages/utils'
20
+ require 'poise_ruby/bundler_mixin'
21
+
22
+ require 'poise_application_ruby/app_mixin'
23
+
24
+
25
+ module PoiseApplicationRuby
26
+ # A helper mixin for Ruby service resources and providers.
27
+ #
28
+ # @since 4.0.0
29
+ module ServiceMixin
30
+ include Poise::Utils::ResourceProviderMixin
31
+
32
+ # A helper mixin for Ruby service resources.
33
+ module Resource
34
+ include PoiseApplication::ServiceMixin::Resource
35
+ include PoiseApplicationRuby::AppMixin::Resource
36
+ end
37
+
38
+ # A helper mixin for Ruby service providers.
39
+ module Provider
40
+ include PoiseApplication::ServiceMixin::Provider
41
+ include PoiseApplicationRuby::AppMixin::Provider
42
+ include PoiseRuby::BundlerMixin
43
+
44
+ # Set up the service for running Ruby stuff.
45
+ def service_options(resource)
46
+ super
47
+ # Closure scoping for #ruby_command below.
48
+ self_ = self
49
+ # Create a new singleton method that fills in Python for you.
50
+ resource.define_singleton_method(:ruby_command) do |val|
51
+ path = self_.new_resource.app_state_environment_ruby['PATH']
52
+ cmd = if self_.new_resource.parent_bundle
53
+ bundle_exec_command(val, path: path)
54
+ else
55
+ "#{self_.new_resource.ruby} #{PoiseLanguages::Utils.absolute_command(val, path: path)}"
56
+ end
57
+ resource.command(cmd)
58
+ end
59
+ # Include env vars as needed.
60
+ resource.environment.update(new_resource.parent_ruby.ruby_environment) if new_resource.parent_ruby
61
+ resource.environment['BUNDLE_GEMFILE'] = new_resource.parent_bundle.gemfile_path if new_resource.parent_bundle
62
+ end
63
+
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,19 @@
1
+ #
2
+ # Copyright 2015, Noah Kantrowitz
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ module PoiseApplicationRuby
18
+ VERSION = '4.0.0'
19
+ end
@@ -0,0 +1,45 @@
1
+ #
2
+ # Copyright 2015, Noah Kantrowitz
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ lib = File.expand_path('../lib', __FILE__)
18
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
19
+ require 'poise_application_ruby/version'
20
+
21
+ Gem::Specification.new do |spec|
22
+ spec.name = 'poise-application-ruby'
23
+ spec.version = PoiseApplicationRuby::VERSION
24
+ spec.authors = ['Noah Kantrowitz']
25
+ spec.email = %w{noah@coderanger.net}
26
+ spec.description = "A Chef cookbook for deploying application code."
27
+ spec.summary = spec.description
28
+ spec.homepage = 'https://github.com/poise/application_ruby'
29
+ spec.license = 'Apache 2.0'
30
+ spec.metadata['halite_name'] = 'application_ruby'
31
+
32
+ spec.files = `git ls-files`.split($/)
33
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
34
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
35
+ spec.require_paths = %w{lib}
36
+
37
+ spec.add_dependency 'halite', '~> 1.0'
38
+ spec.add_dependency 'poise', '~> 2.0'
39
+ spec.add_dependency 'poise-application', '~> 5.0'
40
+ spec.add_dependency 'poise-ruby', '~> 2.1'
41
+ spec.add_dependency 'poise-service', '~> 1.0'
42
+
43
+ spec.add_development_dependency 'poise-boiler', '~> 1.0'
44
+ spec.add_development_dependency 'poise-application-git', '~> 1.0'
45
+ end