poise-application-javascript 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +11 -0
  3. data/.kitchen.travis.yml +9 -0
  4. data/.kitchen.yml +9 -0
  5. data/.travis.yml +20 -0
  6. data/.yardopts +7 -0
  7. data/Berksfile +35 -0
  8. data/CHANGELOG.md +5 -0
  9. data/Gemfile +37 -0
  10. data/LICENSE +201 -0
  11. data/README.md +132 -0
  12. data/Rakefile +17 -0
  13. data/SUPPORTERS.md +81 -0
  14. data/lib/poise_application_javascript.rb +23 -0
  15. data/lib/poise_application_javascript/app_mixin.rb +67 -0
  16. data/lib/poise_application_javascript/cheftie.rb +17 -0
  17. data/lib/poise_application_javascript/error.rb +25 -0
  18. data/lib/poise_application_javascript/resources.rb +22 -0
  19. data/lib/poise_application_javascript/resources/javascript.rb +64 -0
  20. data/lib/poise_application_javascript/resources/javascript_execute.rb +88 -0
  21. data/lib/poise_application_javascript/resources/javascript_service.rb +59 -0
  22. data/lib/poise_application_javascript/resources/node_package.rb +63 -0
  23. data/lib/poise_application_javascript/resources/npm_install.rb +45 -0
  24. data/lib/poise_application_javascript/resources/npm_start.rb +78 -0
  25. data/lib/poise_application_javascript/service_mixin.rb +57 -0
  26. data/lib/poise_application_javascript/version.rb +19 -0
  27. data/poise-application-javascript.gemspec +45 -0
  28. data/test/cookbooks/application_javascript_test/attributes/default.rb +17 -0
  29. data/test/cookbooks/application_javascript_test/metadata.rb +20 -0
  30. data/test/cookbooks/application_javascript_test/recipes/default.rb +32 -0
  31. data/test/cookbooks/application_javascript_test/recipes/express.rb +22 -0
  32. data/test/gemfiles/chef-12.gemfile +19 -0
  33. data/test/gemfiles/master.gemfile +27 -0
  34. data/test/integration/default/serverspec/default_spec.rb +34 -0
  35. data/test/integration/default/serverspec/express_spec.rb +47 -0
  36. data/test/spec/app_mixin_spec.rb +69 -0
  37. data/test/spec/resources/javascript_execute_spec.rb +46 -0
  38. data/test/spec/resources/javascript_service_spec.rb +28 -0
  39. data/test/spec/resources/javascript_spec.rb +44 -0
  40. data/test/spec/resources/npm_install_spec.rb +28 -0
  41. data/test/spec/resources/npm_start_spec.rb +38 -0
  42. data/test/spec/spec_helper.rb +18 -0
  43. metadata +204 -0
@@ -0,0 +1,63 @@
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_javascript/resources/node_package'
18
+
19
+ require 'poise_application_javascript/app_mixin'
20
+
21
+
22
+ module PoiseApplicationJavascript
23
+ module Resources
24
+ # (see NodePackage::Resource)
25
+ # @since 1.0.0
26
+ module NodePackage
27
+ # An `application_node_package` resource to install NPM packages inside
28
+ # an Application cookbook deployment.
29
+ #
30
+ # @provides application_node_package
31
+ # @action install
32
+ # @action upgrade
33
+ # @action remove
34
+ # @example
35
+ # application '/app' do
36
+ # node_package %w{grunt-cli gulp}
37
+ # end
38
+ class Resource < PoiseJavascript::Resources::NodePackage::Resource
39
+ include PoiseApplicationJavascript::AppMixin
40
+ provides(:application_node_package)
41
+ subclass_providers!
42
+
43
+ def initialize(*args)
44
+ super
45
+ # For older Chef.
46
+ @resource_name = :application_node_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
+
59
+ # @todo This should handle relative paths against parent.path.
60
+ end
61
+ end
62
+ end
63
+ 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
+ require 'poise_javascript/resources/npm_install'
18
+
19
+ require 'poise_application_javascript/app_mixin'
20
+
21
+
22
+ module PoiseApplicationJavascript
23
+ module Resources
24
+ # (see NpmInstall::Resource)
25
+ # @since 1.0.0
26
+ module NpmInstall
27
+ # An `application_npm_install` resource to install package
28
+ # dependencies inside an Application cookbook deployment.
29
+ #
30
+ # @provides application_npm_install
31
+ # @action install
32
+ # @example
33
+ # application '/app' do
34
+ # npm_install
35
+ # end
36
+ class Resource < PoiseJavascript::Resources::NpmInstall::Resource
37
+ include PoiseApplicationJavascript::AppMixin
38
+ provides(:application_npm_install)
39
+ subclass_providers!
40
+
41
+ # @todo This should handle relative paths against parent.path.
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,78 @@
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 'shellwords'
18
+
19
+ require 'chef/provider'
20
+ require 'chef/resource'
21
+ require 'poise'
22
+
23
+ require 'poise_application_javascript/service_mixin'
24
+
25
+
26
+ module PoiseApplicationJavascript
27
+ module Resources
28
+ # (see NpmStart::Resource)
29
+ # @since 1.0.0
30
+ module NpmStart
31
+ # An `application_npm_start` resource to create a service for a Javascript
32
+ # application using `npm start`.
33
+ #
34
+ # @provides application_npm_start
35
+ # @action enable
36
+ # @action disable
37
+ # @action start
38
+ # @action stop
39
+ # @action restart
40
+ # @action reload
41
+ # @example
42
+ # application '/app' do
43
+ # npm_start
44
+ # end
45
+ class Resource < Chef::Resource
46
+ include PoiseApplicationJavascript::ServiceMixin
47
+ provides(:application_npm_start)
48
+
49
+ # @!attribute command
50
+ # NPM sub-command to run. Defaults to `start`.
51
+ # @return [String, Array<String>]
52
+ attribute(:command, kind_of: [String, Array], default: 'start')
53
+ end
54
+
55
+ # The default provider for `application_npm_start`.
56
+ #
57
+ # @see Resource
58
+ # @provides application_npm_start
59
+ class Provider < Chef::Provider
60
+ include PoiseApplicationJavascript::ServiceMixin
61
+ provides(:application_npm_start)
62
+
63
+ private
64
+
65
+ # (see PoiseApplication::ServiceMixin#service_options)
66
+ def service_options(resource)
67
+ super
68
+ npm_cmd = [new_resource.npm_binary] + Array(new_resource.command)
69
+ resource.javascript_command(Shellwords.join(npm_cmd))
70
+ # Make sure node is on $PATH because grrr.
71
+ new_path = [::File.dirname(new_resource.javascript), (new_resource.app_state_environment_javascript['PATH'] || ENV['PATH']).to_s].join(::File::PATH_SEPARATOR)
72
+ resource.environment['PATH'] = new_path
73
+ end
74
+
75
+ end
76
+ end
77
+ end
78
+ 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_javascript/app_mixin'
22
+
23
+
24
+ module PoiseApplicationJavascript
25
+ # A helper mixin for Javascript service resources and providers.
26
+ #
27
+ # @since 1.0.0
28
+ module ServiceMixin
29
+ include Poise::Utils::ResourceProviderMixin
30
+
31
+ # A helper mixin for Javascript service resources.
32
+ module Resource
33
+ include PoiseApplication::ServiceMixin::Resource
34
+ include PoiseApplicationJavascript::AppMixin::Resource
35
+ end
36
+
37
+ # A helper mixin for Javascript service providers.
38
+ module Provider
39
+ include PoiseApplication::ServiceMixin::Provider
40
+ include PoiseApplicationJavascript::AppMixin::Provider
41
+
42
+ # Set up the service for running Javascript stuff.
43
+ def service_options(resource)
44
+ super
45
+ # Closure scoping for #javascript_command below.
46
+ self_ = self
47
+ # Create a new singleton method that fills in `node` for you.
48
+ resource.define_singleton_method(:javascript_command) do |val|
49
+ resource.command("#{self_.new_resource.javascript} #{PoiseLanguages::Utils.absolute_command(val, path: self_.new_resource.app_state_environment_javascript['PATH'])}")
50
+ end
51
+ # Include env vars as needed.
52
+ resource.environment.update(new_resource.parent_javascript.javascript_environment) if new_resource.parent_javascript
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 PoiseApplicationJavascript
18
+ VERSION = '1.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_javascript/version'
20
+
21
+ Gem::Specification.new do |spec|
22
+ spec.name = 'poise-application-javascript'
23
+ spec.version = PoiseApplicationJavascript::VERSION
24
+ spec.authors = ['Noah Kantrowitz']
25
+ spec.email = %w{noah@coderanger.net}
26
+ spec.description = "A Chef cookbook for deploying server-side JavaScript application code."
27
+ spec.summary = spec.description
28
+ spec.homepage = 'https://github.com/poise/application_javascript'
29
+ spec.license = 'Apache 2.0'
30
+ spec.metadata['halite_name'] = 'application_javascript'
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-javascript', '~> 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
@@ -0,0 +1,17 @@
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
+ override['poise-service']['provider'] = 'dummy'
@@ -0,0 +1,20 @@
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
+ name 'application_javascript_test'
18
+ depends 'application_git'
19
+ depends 'application_javascript'
20
+ depends 'build-essential'
@@ -0,0 +1,32 @@
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
+ include_recipe 'poise-javascript'
18
+
19
+ # For netstat in serverspec.
20
+ package 'net-tools'
21
+
22
+ application '/opt/node1' do
23
+ file '/opt/node1/main.js' do
24
+ content <<-EOH
25
+ require('http').createServer(function(request, response) {
26
+ response.end('Hello world!\\n');
27
+ }).listen(8000);
28
+ EOH
29
+ end
30
+ javascript_service 'main.js'
31
+ end
32
+
@@ -0,0 +1,22 @@
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
+ application '/opt/test_express' do
18
+ git 'https://github.com/poise/test_express.git'
19
+ javascript '0.12'
20
+ npm_install
21
+ npm_start
22
+ 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
+ eval_gemfile File.expand_path('../../../Gemfile', __FILE__)
18
+
19
+ gem 'chef', '~> 12.0'
@@ -0,0 +1,27 @@
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
+ eval_gemfile File.expand_path('../../../Gemfile', __FILE__)
18
+
19
+ gem 'chef', github: 'chef/chef'
20
+ gem 'halite', github: 'poise/halite'
21
+ gem 'poise', github: 'poise/poise'
22
+ gem 'poise-application', github: 'poise/application'
23
+ gem 'poise-application-git', github: 'poise/application_git'
24
+ gem 'poise-boiler', github: 'poise/poise-boiler'
25
+ gem 'poise-javascript', github: 'poise/poise-javascript'
26
+ gem 'poise-languages', github: 'poise/poise-languages'
27
+ gem 'poise-service', github: 'poise/poise-service'