poise-application-python 4.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) 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 +20 -0
  6. data/.yardopts +3 -0
  7. data/Berksfile +35 -0
  8. data/CHANGELOG.md +71 -0
  9. data/Gemfile +37 -0
  10. data/LICENSE +201 -0
  11. data/README.md +334 -0
  12. data/Rakefile +17 -0
  13. data/SUPPORTERS.md +81 -0
  14. data/chef/templates/celeryconfig.py.erb +5 -0
  15. data/chef/templates/settings.py.erb +13 -0
  16. data/lib/poise_application_python.rb +23 -0
  17. data/lib/poise_application_python/app_mixin.rb +67 -0
  18. data/lib/poise_application_python/cheftie.rb +17 -0
  19. data/lib/poise_application_python/error.rb +25 -0
  20. data/lib/poise_application_python/resources.rb +26 -0
  21. data/lib/poise_application_python/resources/celery_beat.rb +43 -0
  22. data/lib/poise_application_python/resources/celery_config.rb +109 -0
  23. data/lib/poise_application_python/resources/celery_worker.rb +77 -0
  24. data/lib/poise_application_python/resources/django.rb +355 -0
  25. data/lib/poise_application_python/resources/gunicorn.rb +127 -0
  26. data/lib/poise_application_python/resources/pip_requirements.rb +47 -0
  27. data/lib/poise_application_python/resources/python.rb +57 -0
  28. data/lib/poise_application_python/resources/python_execute.rb +89 -0
  29. data/lib/poise_application_python/resources/python_package.rb +62 -0
  30. data/lib/poise_application_python/resources/virtualenv.rb +75 -0
  31. data/lib/poise_application_python/service_mixin.rb +57 -0
  32. data/lib/poise_application_python/version.rb +19 -0
  33. data/poise-application-python.gemspec +45 -0
  34. data/test/cookbooks/application_python_test/attributes/default.rb +17 -0
  35. data/test/cookbooks/application_python_test/metadata.rb +20 -0
  36. data/test/cookbooks/application_python_test/recipes/default.rb +83 -0
  37. data/test/cookbooks/application_python_test/recipes/django.rb +32 -0
  38. data/test/cookbooks/application_python_test/recipes/flask.rb +25 -0
  39. data/test/gemfiles/chef-12.gemfile +19 -0
  40. data/test/gemfiles/master.gemfile +27 -0
  41. data/test/integration/default/serverspec/default_spec.rb +81 -0
  42. data/test/integration/default/serverspec/django_spec.rb +56 -0
  43. data/test/integration/default/serverspec/flask_spec.rb +39 -0
  44. data/test/spec/app_mixin_spec.rb +69 -0
  45. data/test/spec/resources/celery_config_spec.rb +58 -0
  46. data/test/spec/resources/django_spec.rb +303 -0
  47. data/test/spec/resources/gunicorn_spec.rb +96 -0
  48. data/test/spec/resources/python_execute_spec.rb +46 -0
  49. data/test/spec/resources/python_spec.rb +44 -0
  50. data/test/spec/resources/virtualenv_spec.rb +44 -0
  51. data/test/spec/spec_helper.rb +19 -0
  52. metadata +216 -0
@@ -0,0 +1,47 @@
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_python/resources/pip_requirements'
18
+
19
+ require 'poise_application_python/app_mixin'
20
+
21
+
22
+ module PoiseApplicationPython
23
+ module Resources
24
+ # (see PipRequirements::Resource)
25
+ # @since 4.0.0
26
+ module PipRequirements
27
+ # An `application_pip_requirements` resource to manage Python virtual
28
+ # environments inside an Application cookbook deployment.
29
+ #
30
+ # @provides application_pip_requirements
31
+ # @provides application_virtualenv
32
+ # @action install
33
+ # @action upgrade
34
+ # @example
35
+ # application '/app' do
36
+ # pip_requirements
37
+ # end
38
+ class Resource < PoisePython::Resources::PipRequirements::Resource
39
+ include PoiseApplicationPython::AppMixin
40
+ provides(:application_pip_requirements)
41
+ subclass_providers!
42
+
43
+ # @todo This should handle relative paths against parent.path.
44
+ end
45
+ end
46
+ end
47
+ end
@@ -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_python/resources/python_runtime'
18
+
19
+ require 'poise_application_python/app_mixin'
20
+
21
+
22
+ module PoiseApplicationPython
23
+ module Resources
24
+ # (see Python::Resource)
25
+ # @since 4.0.0
26
+ module Python
27
+ # An `application_python` resource to manage Python runtimes
28
+ # inside an Application cookbook deployment.
29
+ #
30
+ # @provides application_python
31
+ # @provides application_python_runtime
32
+ # @action install
33
+ # @action uninstall
34
+ # @example
35
+ # application '/app' do
36
+ # python '2'
37
+ # end
38
+ class Resource < PoisePython::Resources::PythonRuntime::Resource
39
+ include PoiseApplicationPython::AppMixin
40
+ provides(:application_python)
41
+ provides(:application_python_runtime)
42
+ container_default(false)
43
+ subclass_providers!
44
+
45
+ # Set this resource as the app_state's parent python.
46
+ #
47
+ # @api private
48
+ def after_created
49
+ super.tap do |val|
50
+ app_state_python(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_python/resources/python_execute'
18
+
19
+ require 'poise_application_python/app_mixin'
20
+
21
+
22
+ module PoiseApplicationPython
23
+ module Resources
24
+ # (see PythonExecute::Resource)
25
+ # @since 4.0.0
26
+ module PythonExecute
27
+ # An `application_python_execute` resource to run Python commands inside an
28
+ # Application cookbook deployment.
29
+ #
30
+ # @provides application_python_execute
31
+ # @action run
32
+ # @example
33
+ # application '/srv/myapp' do
34
+ # python_execute 'setup.py install'
35
+ # end
36
+ class Resource < PoisePython::Resources::PythonExecute::Resource
37
+ include PoiseApplicationPython::AppMixin
38
+ provides(:application_python_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_python_execute`.
65
+ #
66
+ # @see Resource
67
+ # @provides application_python_execute
68
+ class Provider < PoisePython::Resources::PythonExecute::Provider
69
+ provides(:application_python_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_python 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,62 @@
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_python/resources/python_package'
18
+
19
+ require 'poise_application_python/app_mixin'
20
+
21
+
22
+ module PoiseApplicationPython
23
+ module Resources
24
+ # (see PythonPackage::Resource)
25
+ # @since 4.0.0
26
+ module PythonPackage
27
+ # An `application_python_package` resource to install Python
28
+ # packages inside an Application cookbook deployment.
29
+ #
30
+ # @provides application_python_package
31
+ # @action install
32
+ # @action upgrade
33
+ # @action remove
34
+ # @example
35
+ # application '/srv/myapp' do
36
+ # python_package 'requests'
37
+ # end
38
+ class Resource < PoisePython::Resources::PythonPackage::Resource
39
+ include PoiseApplicationPython::AppMixin
40
+ provides(:application_python_package)
41
+ subclass_providers!
42
+
43
+ def initialize(*args)
44
+ super
45
+ # For older Chef.
46
+ @resource_name = :application_python_package
47
+ end
48
+
49
+ # #!attribute group
50
+ # Override the default group to be the app group if unspecified.
51
+ # @return [String, Integer]
52
+ attribute(:group, kind_of: [String, Integer, NilClass], default: lazy { parent && parent.group })
53
+
54
+ # #!attribute user
55
+ # Override the default user to be the app owner if unspecified.
56
+ # @return [String, Integer]
57
+ attribute(:user, kind_of: [String, Integer, NilClass], default: lazy { parent && parent.owner })
58
+ end
59
+
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,75 @@
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_python/resources/python_virtualenv'
18
+
19
+ require 'poise_application_python/app_mixin'
20
+
21
+
22
+ module PoiseApplicationPython
23
+ module Resources
24
+ # (see Virtualenv::Resource)
25
+ # @since 4.0.0
26
+ module Virtualenv
27
+ # An `application_virtualenv` resource to manage Python virtual
28
+ # environments inside an Application cookbook deployment.
29
+ #
30
+ # @provides application_virtualenv
31
+ # @provides application_python_virtualenv
32
+ # @action create
33
+ # @action delete
34
+ # @example
35
+ # application '/app' do
36
+ # virtualenv
37
+ # end
38
+ class Resource < PoisePython::Resources::PythonVirtualenv::Resource
39
+ include PoiseApplicationPython::AppMixin
40
+ provides(:application_virtualenv)
41
+ provides(:application_python_virtualenv)
42
+ container_default(false)
43
+ subclass_providers!
44
+
45
+ # @!attribute path
46
+ # Override the normal path property to use name/.virtualenv for better
47
+ # compatibility with the application resource DSL.
48
+ # @return [String]
49
+ attribute(:path, kind_of: String, default: lazy { default_path })
50
+
51
+ # Set this resource as the app_state's parent python.
52
+ #
53
+ # @api private
54
+ def after_created
55
+ super.tap do |val|
56
+ # Force evaluation so we get any current parent if set.
57
+ parent_python
58
+ app_state_python(self)
59
+ end
60
+ end
61
+
62
+ private
63
+
64
+ # Default value for the {#path} property.
65
+ #
66
+ # @return [String]
67
+ def default_path
68
+ # @todo This should handle relative paths as a name.
69
+ ::File.join(name, '.virtualenv')
70
+ end
71
+
72
+ end
73
+ end
74
+ end
75
+ end
@@ -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/utils'
18
+ require 'poise_application/service_mixin'
19
+ require 'poise_languages/utils'
20
+
21
+ require 'poise_application_python/app_mixin'
22
+
23
+
24
+ module PoiseApplicationPython
25
+ # A helper mixin for Python service resources and providers.
26
+ #
27
+ # @since 4.0.0
28
+ module ServiceMixin
29
+ include Poise::Utils::ResourceProviderMixin
30
+
31
+ # A helper mixin for Python service resources.
32
+ module Resource
33
+ include PoiseApplication::ServiceMixin::Resource
34
+ include PoiseApplicationPython::AppMixin::Resource
35
+ end
36
+
37
+ # A helper mixin for Python service providers.
38
+ module Provider
39
+ include PoiseApplication::ServiceMixin::Provider
40
+ include PoiseApplicationPython::AppMixin::Provider
41
+
42
+ # Set up the service for running Python stuff.
43
+ def service_options(resource)
44
+ super
45
+ # Closure scoping for #python_command below.
46
+ self_ = self
47
+ # Create a new singleton method that fills in Python for you.
48
+ resource.define_singleton_method(:python_command) do |val|
49
+ resource.command("#{self_.new_resource.python} #{PoiseLanguages::Utils.absolute_command(val, path: self_.new_resource.app_state_environment_python['PATH'])}")
50
+ end
51
+ # Include env vars as needed.
52
+ resource.environment.update(new_resource.parent_python.python_environment) if new_resource.parent_python
53
+ end
54
+
55
+ end
56
+ end
57
+ 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 PoiseApplicationPython
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_python/version'
20
+
21
+ Gem::Specification.new do |spec|
22
+ spec.name = 'poise-application-python'
23
+ spec.version = PoiseApplicationPython::VERSION
24
+ spec.authors = ['Noah Kantrowitz']
25
+ spec.email = %w{noah@coderanger.net}
26
+ spec.description = "A Chef cookbook for deploying Python application code."
27
+ spec.summary = spec.description
28
+ spec.homepage = 'https://github.com/poise/application_python'
29
+ spec.license = 'Apache 2.0'
30
+ spec.metadata['halite_name'] = 'application_python'
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-python', '~> 1.0'
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