Set up an instance of Mastodon for Kosmos
Refs #19 Use new application cookbook, update our cookbooks
This commit is contained in:
86
cookbooks/application_ruby/CHANGELOG.md
Normal file
86
cookbooks/application_ruby/CHANGELOG.md
Normal file
@@ -0,0 +1,86 @@
|
||||
# Application_Ruby Changelog
|
||||
|
||||
## v4.0.1
|
||||
|
||||
* Correct `gem_binary` results for `application_ruby`.
|
||||
|
||||
## v4.0.0
|
||||
|
||||
* Massive rewrite on top of newer Chef patterns. See the 4.0 README for details.
|
||||
|
||||
## v3.0.2
|
||||
|
||||
* No changes, bumping version to get bits in various places in sync.
|
||||
|
||||
## v3.0.0
|
||||
|
||||
* Major version bump. Breaking backwards compatibility with Chef 10.
|
||||
|
||||
## v2.2.0
|
||||
|
||||
* [COOK-3895](https://tickets.opscode.com/browse/COOK-3895) - application_ruby use_omnibus_ruby attr needs to default to false.
|
||||
* [COOK-3894](https://tickets.opscode.com/browse/COOK-3894) - application_ruby cookbook needs version bump to pick up application v4.0 cookbook.
|
||||
* [COOK-2079](https://tickets.opscode.com/browse/COOK-2079) - Attempting to touch restart.txt should not cause a chef-client run to fail.
|
||||
|
||||
## v2.1.4
|
||||
|
||||
* [COOK-3625](https://tickets.opscode.com/browse/COOK-3625) - Fix an issue where unicorn fails when node does not provide cpu count.
|
||||
|
||||
## v2.1.2
|
||||
|
||||
* [COOK-3616](https://tickets.opscode.com/browse/COOK-3616) - Simplify log symlinking for rails apps.
|
||||
|
||||
## v2.1.0
|
||||
|
||||
* [COOK-3367](https://tickets.opscode.com/browse/COOK-3367) - Support more of unicorn's configuration.
|
||||
* [COOK-3124](https://tickets.opscode.com/browse/COOK-3124) - Add `memcached_template` attribute to so alternative templates may be used.
|
||||
|
||||
## v2.0.0
|
||||
|
||||
### Bug
|
||||
|
||||
* [COOK-3306]: Multiple Memory Leaks in Application Cookbook.
|
||||
* [COOK-3219]: `application_ruby` cookbook bundle install in 1.9.3-based omnibus installs 1.9.x gems into ruby 2.0 apps.
|
||||
|
||||
## v1.1.4
|
||||
|
||||
* [COOK-2806]: Including `passenger_apache2::mod_rails` does not enable passenger.
|
||||
|
||||
## v1.1.2
|
||||
|
||||
* [COOK-2638]: cookbook attribute is not treated as a string when specifying `database_yml_template`.
|
||||
* [COOK-2525]: application_ruby: split runit template into multiple lines.
|
||||
|
||||
## v1.1.0
|
||||
|
||||
* [COOK-2362] - `application_ruby` unicorn uses `run_restart`.
|
||||
* [COOK-2363] - `application_ruby` unicorn should set `log_template_name` and `run_template_name`.
|
||||
|
||||
## v1.0.10
|
||||
|
||||
* [COOK-2260] - pin runit version.
|
||||
|
||||
## v1.0.8
|
||||
|
||||
* [COOK-2159] - cookbook attribute is not treated as a string.
|
||||
|
||||
## v1.0.6
|
||||
|
||||
* [COOK-1481] - unicorn provider in application_ruby cookbook should run its restart command as root.
|
||||
|
||||
## v1.0.4
|
||||
|
||||
* [COOK-1572] - allow specification of 'bundle' command via attribute.
|
||||
|
||||
## v1.0.2
|
||||
|
||||
* [COOK-1360] - fix typo in README.
|
||||
* [COOK-1374] - use runit attribute in unicorn run script.
|
||||
* [COOK-1408] - use user and group from parent resource for runit service.
|
||||
|
||||
## v1.0.0
|
||||
|
||||
* [COOK-1247] - Initial release - relates to COOK-634.
|
||||
* [COOK-1248] - special cases memcached.
|
||||
* [COOK-1258] - Precompile assets for Rails 3.
|
||||
* [COOK-1297] - Unicorn sub-resource should allow strings for 'port' attribute.
|
||||
271
cookbooks/application_ruby/README.md
Normal file
271
cookbooks/application_ruby/README.md
Normal file
@@ -0,0 +1,271 @@
|
||||
# Application_Ruby Cookbook
|
||||
|
||||
[](https://travis-ci.org/poise/application_ruby)
|
||||
[](https://rubygems.org/gems/poise-application-ruby)
|
||||
[](https://supermarket.chef.io/cookbooks/application_ruby)
|
||||
[](https://codecov.io/github/poise/application_ruby)
|
||||
[](https://gemnasium.com/poise/application_ruby)
|
||||
[](https://www.apache.org/licenses/LICENSE-2.0)
|
||||
|
||||
A [Chef](https://www.chef.io/) cookbook to deploy Ruby applications.
|
||||
|
||||
## Quick Start
|
||||
|
||||
To deploy a Rails application from git:
|
||||
|
||||
```ruby
|
||||
application '/srv/myapp' do
|
||||
git 'https://github.com/example/myapp.git'
|
||||
bundle_install do
|
||||
deployment true
|
||||
without %w{development test}
|
||||
end
|
||||
rails do
|
||||
database 'sqlite3:///db.sqlite3'
|
||||
secret_token 'd78fe08df56c9'
|
||||
migrate true
|
||||
end
|
||||
unicorn do
|
||||
port 8000
|
||||
end
|
||||
end
|
||||
```
|
||||
|
||||
## Requirements
|
||||
|
||||
Chef 12 or newer is required.
|
||||
|
||||
## Resources
|
||||
|
||||
### `application_bundle_install`
|
||||
|
||||
The `application_bundle_install` resource installs gems using Bundler for a
|
||||
deployment.
|
||||
|
||||
```ruby
|
||||
application '/srv/myapp' do
|
||||
bundle_install do
|
||||
deployment true
|
||||
without %w{development test}
|
||||
end
|
||||
end
|
||||
```
|
||||
|
||||
All actions and properties are the same as the [`bundle_install` resource](https://github.com/poise/poise-ruby#bundle_install).
|
||||
|
||||
### `application_rackup`
|
||||
|
||||
The `application_rackup` resource creates a service for `rackup`.
|
||||
|
||||
```ruby
|
||||
application '/srv/myapp' do
|
||||
rackup do
|
||||
port 8000
|
||||
end
|
||||
end
|
||||
```
|
||||
|
||||
#### Actions
|
||||
|
||||
* `:enable` – Create, enable and start the service. *(default)*
|
||||
* `:disable` – Stop, disable, and destroy the service.
|
||||
* `:start` – Start the service.
|
||||
* `:stop` – Stop the service.
|
||||
* `:restart` – Stop and then start the service.
|
||||
* `:reload` – Send the configured reload signal to the service.
|
||||
|
||||
#### Properties
|
||||
|
||||
* `path` – Base path for the application. *(name attribute)*
|
||||
* `port` – Port to listen on. *(default: 80)*
|
||||
* `service_name` – Name of the service to create. *(default: auto-detect)*
|
||||
# `user` – User to run the service as. *(default: application owner)*
|
||||
|
||||
### `application_rails`
|
||||
|
||||
The `application_rails` resource
|
||||
|
||||
```ruby
|
||||
application '/srv/myapp' do
|
||||
rails do
|
||||
database 'sqlite3:///db.sqlite3'
|
||||
secret_token 'd78fe08df56c9'
|
||||
migrate true
|
||||
end
|
||||
end
|
||||
```
|
||||
|
||||
#### Actions
|
||||
|
||||
* `:deploy` – Create config files and run required deployments steps. *(default)*
|
||||
|
||||
#### Properties
|
||||
|
||||
* `path` – Base path for the application. *(name attribute)*
|
||||
* `database` – Database settings for Rails. See [the database section
|
||||
below](#database-parameters) for more information. *(option collector)*
|
||||
* `migrate` – Run database migrations. *(default: false)*
|
||||
* `precompile_assets` – Run `rake assets:precompile`. *(default: auto-detect)()
|
||||
* `rails_env` – Rails environment name. *(default: node.chef_environment)*
|
||||
* `secret_token` – Secret token for Rails session verification et al.
|
||||
* `secrets_mode` – Secrets configuration mode. Set to `:yaml` to generate a
|
||||
Rails 4.2 secrets.yml. Set to `:initializer` to update
|
||||
`config/initializers/secret_token.rb`. *(default: auto-detect)*
|
||||
|
||||
**NOTE:** At this time `secrets_mode :initializer` is not implemented.
|
||||
|
||||
#### Database Parameters
|
||||
|
||||
The database parameters can be set in three ways: URL, hash, and block.
|
||||
|
||||
If you have a single URL for the parameters, you can pass it directly to
|
||||
`database`:
|
||||
|
||||
```ruby
|
||||
rails do
|
||||
database 'mysql2://myuser@dbhost/myapp'
|
||||
end
|
||||
```
|
||||
|
||||
Passing a single URL will also set the `$DATABASE_URL` environment variable
|
||||
automatically for compatibility with Heroku-based applications.
|
||||
|
||||
As with other option collector resources, you can pass individual settings as
|
||||
either a hash or block:
|
||||
|
||||
```ruby
|
||||
rails do
|
||||
database do
|
||||
adapter 'mysql2'
|
||||
username 'myuser'
|
||||
host 'dbhost'
|
||||
database 'myapp'
|
||||
end
|
||||
end
|
||||
|
||||
rails do
|
||||
database({
|
||||
adapter: 'mysql2',
|
||||
username: 'myuser',
|
||||
host: 'dbhost',
|
||||
database: 'myapp',
|
||||
})
|
||||
end
|
||||
```
|
||||
|
||||
### `application_ruby`
|
||||
|
||||
The `application_ruby` resource installs a Ruby runtime for the deployment.
|
||||
|
||||
```ruby
|
||||
application '/srv/myapp' do
|
||||
ruby '2.2'
|
||||
end
|
||||
```
|
||||
|
||||
All actions and properties are the same as the [`ruby_runtime` resource](https://github.com/poise/poise-ruby#ruby_runtime).
|
||||
|
||||
### `application_ruby_gem`
|
||||
|
||||
The `application_ruby_gem` resource installs Ruby gems for the deployment.
|
||||
|
||||
```ruby
|
||||
application '/srv/myapp' do
|
||||
ruby_gem 'rake'
|
||||
end
|
||||
```
|
||||
|
||||
All actions and properties are the same as the [`ruby_gem` resource](https://github.com/poise/poise-ruby#ruby_gem).
|
||||
|
||||
### `application_ruby_execute`
|
||||
|
||||
The `application_ruby_execute` resource runs Ruby commands for the deployment.
|
||||
|
||||
```ruby
|
||||
application '/srv/myapp' do
|
||||
ruby_execute 'rake'
|
||||
end
|
||||
```
|
||||
|
||||
All actions and properties are the same as the [`ruby_execute` resource](https://github.com/poise/poise-ruby#ruby_execute),
|
||||
except that the `cwd`, `environment`, `group`, and `user` properties default to
|
||||
the application-level data if not specified.
|
||||
|
||||
### `application_thin`
|
||||
|
||||
The `application_thin` resource creates a service for `thin`.
|
||||
|
||||
```ruby
|
||||
application '/srv/myapp' do
|
||||
thin do
|
||||
port 8000
|
||||
end
|
||||
end
|
||||
```
|
||||
|
||||
#### Actions
|
||||
|
||||
* `:enable` – Create, enable and start the service. *(default)*
|
||||
* `:disable` – Stop, disable, and destroy the service.
|
||||
* `:start` – Start the service.
|
||||
* `:stop` – Stop the service.
|
||||
* `:restart` – Stop and then start the service.
|
||||
* `:reload` – Send the configured reload signal to the service.
|
||||
|
||||
#### Properties
|
||||
|
||||
* `path` – Base path for the application. *(name attribute)*
|
||||
* `config_path` – Path to a Thin configuration file.
|
||||
* `port` – Port to listen on. *(default: 80)*
|
||||
* `service_name` – Name of the service to create. *(default: auto-detect)*
|
||||
# `user` – User to run the service as. *(default: application owner)*
|
||||
|
||||
### `application_unicorn`
|
||||
|
||||
The `application_unicorn` resource creates a service for `unicorn`.
|
||||
|
||||
```ruby
|
||||
application '/srv/myapp' do
|
||||
unicorn do
|
||||
port 8000
|
||||
end
|
||||
end
|
||||
```
|
||||
|
||||
#### Actions
|
||||
|
||||
* `:enable` – Create, enable and start the service. *(default)*
|
||||
* `:disable` – Stop, disable, and destroy the service.
|
||||
* `:start` – Start the service.
|
||||
* `:stop` – Stop the service.
|
||||
* `:restart` – Stop and then start the service.
|
||||
* `:reload` – Send the configured reload signal to the service.
|
||||
|
||||
#### Properties
|
||||
|
||||
* `path` – Base path for the application. *(name attribute)*
|
||||
* `port` – Port to listen on. *(default: 80)*
|
||||
* `service_name` – Name of the service to create. *(default: auto-detect)*
|
||||
# `user` – User to run the service as. *(default: application owner)*
|
||||
|
||||
## Sponsors
|
||||
|
||||
Development sponsored by [Chef Software](https://www.chef.io/), [Symonds & Son](http://symondsandson.com/), and [Orion](https://www.orionlabs.co/).
|
||||
|
||||
The Poise test server infrastructure is sponsored by [Rackspace](https://rackspace.com/).
|
||||
|
||||
## License
|
||||
|
||||
Copyright 2015, Noah Kantrowitz
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
@@ -0,0 +1,24 @@
|
||||
#
|
||||
# Copyright 2015, Noah Kantrowitz
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
|
||||
module PoiseApplicationRuby
|
||||
autoload :AppMixin, 'poise_application_ruby/app_mixin'
|
||||
autoload :Error, 'poise_application_ruby/error'
|
||||
autoload :Resources, 'poise_application_ruby/resources'
|
||||
autoload :ServiceMixin, 'poise_application_ruby/service_mixin'
|
||||
autoload :VERSION, 'poise_application_ruby/version'
|
||||
end
|
||||
@@ -0,0 +1,92 @@
|
||||
#
|
||||
# Copyright 2015, Noah Kantrowitz
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
require 'poise/backports'
|
||||
require 'poise/utils'
|
||||
require 'poise_application/app_mixin'
|
||||
require 'poise_ruby/ruby_command_mixin'
|
||||
|
||||
|
||||
module PoiseApplicationRuby
|
||||
# A helper mixin for Ruby application resources and providers.
|
||||
#
|
||||
# @since 4.0.0
|
||||
module AppMixin
|
||||
include Poise::Utils::ResourceProviderMixin
|
||||
|
||||
# A helper mixin for Ruby application resources.
|
||||
module Resource
|
||||
include PoiseApplication::AppMixin::Resource
|
||||
include PoiseRuby::RubyCommandMixin::Resource
|
||||
|
||||
# @!attribute parent_ruby
|
||||
# Override the #parent_ruby from RubyCommandMixin to grok the
|
||||
# application level parent as a default value.
|
||||
# @return [PoiseRuby::Resources::RubyRuntime::Resource, nil]
|
||||
parent_attribute(:ruby, type: :ruby_runtime, optional: true, default: lazy { app_state_ruby.equal?(self) ? nil : app_state_ruby })
|
||||
|
||||
# @!attribute parent_bundle
|
||||
# Parent bundle install context.
|
||||
# @return [PoiseRuby::Resources::BundleInstall::Resource, nil]
|
||||
parent_attribute(:bundle, type: :ruby_runtime, optional: true, auto: false, default: lazy { app_state_bundle.equal?(self) ? nil : app_state_bundle })
|
||||
|
||||
# @attribute app_state_ruby
|
||||
# The application-level Ruby parent.
|
||||
# @return [PoiseRuby::Resources::RubyRuntime::Resource, nil]
|
||||
def app_state_ruby(ruby=Poise::NOT_PASSED)
|
||||
unless ruby == Poise::NOT_PASSED
|
||||
app_state[:ruby] = ruby
|
||||
end
|
||||
app_state[:ruby]
|
||||
end
|
||||
|
||||
# @attribute app_state_bundle
|
||||
# The application-level Bundle parent.
|
||||
# @return [PoiseRuby::Resources::BundleInstall::Resource, nil]
|
||||
def app_state_bundle(bundle=Poise::NOT_PASSED)
|
||||
unless bundle == Poise::NOT_PASSED
|
||||
app_state[:bundle] = bundle
|
||||
end
|
||||
app_state[:bundle]
|
||||
end
|
||||
|
||||
# A merged hash of environment variables for both the application state
|
||||
# and parent ruby.
|
||||
#
|
||||
# @return [Hash<String, String>]
|
||||
def app_state_environment_ruby
|
||||
env = app_state_environment
|
||||
env = env.merge(parent_ruby.ruby_environment) if parent_ruby
|
||||
env['BUNDLE_GEMFILE'] = parent_bundle.gemfile_path if parent_bundle
|
||||
env
|
||||
end
|
||||
|
||||
# Update ruby_from_parent to transfer {#parent_bundle} too.
|
||||
#
|
||||
# @param resource [Chef::Resource] Resource to inherit from.
|
||||
# @return [void]
|
||||
def ruby_from_parent(resource)
|
||||
super
|
||||
parent_bundle(resource.parent_bundle) if resource.parent_bundle
|
||||
end
|
||||
end
|
||||
|
||||
# A helper mixin for Ruby application providers.
|
||||
module Provider
|
||||
include PoiseApplication::AppMixin::Provider
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,17 @@
|
||||
#
|
||||
# Copyright 2015, Noah Kantrowitz
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
require 'poise_application_ruby/resources'
|
||||
@@ -0,0 +1,25 @@
|
||||
#
|
||||
# Copyright 2015, Noah Kantrowitz
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
require 'poise_application/error'
|
||||
|
||||
module PoiseApplicationRuby
|
||||
# Base exception class for poise-application-ruby errors.
|
||||
#
|
||||
# @since 4.0.0
|
||||
class Error < PoiseApplication::Error
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,24 @@
|
||||
#
|
||||
# Copyright 2015, Noah Kantrowitz
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
require 'poise_application_ruby/resources/bundle_install'
|
||||
require 'poise_application_ruby/resources/rackup'
|
||||
require 'poise_application_ruby/resources/rails'
|
||||
require 'poise_application_ruby/resources/ruby'
|
||||
require 'poise_application_ruby/resources/ruby_execute'
|
||||
require 'poise_application_ruby/resources/ruby_gem'
|
||||
require 'poise_application_ruby/resources/thin'
|
||||
require 'poise_application_ruby/resources/unicorn'
|
||||
@@ -0,0 +1,54 @@
|
||||
#
|
||||
# Copyright 2015, Noah Kantrowitz
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
require 'poise_ruby/resources/bundle_install'
|
||||
|
||||
require 'poise_application_ruby/app_mixin'
|
||||
|
||||
|
||||
module PoiseApplicationRuby
|
||||
module Resources
|
||||
# (see BundleInstall::Resource)
|
||||
# @since 4.0.0
|
||||
module BundleInstall
|
||||
# An `application_bundle_install` resource to install a
|
||||
# [Bundler](http://bundler.io/) Gemfile in a web application.
|
||||
#
|
||||
# @note
|
||||
# This resource is not idempotent itself, it will always run `bundle
|
||||
# install`.
|
||||
# @example
|
||||
# application '/srv/my_app' do
|
||||
# bundle_install
|
||||
# end
|
||||
class Resource < PoiseRuby::Resources::BundleInstall::Resource
|
||||
include PoiseApplicationRuby::AppMixin
|
||||
provides(:application_bundle_install)
|
||||
subclass_providers!
|
||||
|
||||
# Set this resource as the app_state's parent bundle.
|
||||
#
|
||||
# @api private
|
||||
def after_created
|
||||
super.tap do |val|
|
||||
app_state_bundle(self)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,70 @@
|
||||
#
|
||||
# Copyright 2015, Noah Kantrowitz
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
require 'chef/provider'
|
||||
require 'chef/resource'
|
||||
|
||||
require 'poise_application_ruby/service_mixin'
|
||||
|
||||
|
||||
module PoiseApplicationRuby
|
||||
module Resources
|
||||
# (see Rackup::Resource)
|
||||
# @since 4.0.0
|
||||
module Rackup
|
||||
class Resource < Chef::Resource
|
||||
include PoiseApplicationRuby::ServiceMixin
|
||||
provides(:application_rackup)
|
||||
|
||||
# @!attribute port
|
||||
# TCP port to listen on. Defaults to 80.
|
||||
# @return [String, Integer]
|
||||
attribute(:port, kind_of: [String, Integer], default: 80)
|
||||
end
|
||||
|
||||
class Provider < Chef::Provider
|
||||
include PoiseApplicationRuby::ServiceMixin
|
||||
provides(:application_rackup)
|
||||
|
||||
private
|
||||
|
||||
# Find the path to the config.ru. If the resource path was to a
|
||||
# directory, apparent /config.ru.
|
||||
#
|
||||
# @return [String]
|
||||
def configru_path
|
||||
@configru_path ||= if ::File.directory?(new_resource.path)
|
||||
::File.join(new_resource.path, 'config.ru')
|
||||
else
|
||||
new_resource.path
|
||||
end
|
||||
end
|
||||
|
||||
# Set up service options for rackup.
|
||||
#
|
||||
# @param resource [PoiseService::Resource] Service resource.
|
||||
# @return [void]
|
||||
def service_options(resource)
|
||||
super
|
||||
resource.ruby_command("rackup --port #{new_resource.port}")
|
||||
resource.directory(::File.dirname(configru_path))
|
||||
# Older versions of rackup ignore all signals.
|
||||
resource.stop_signal('KILL')
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,260 @@
|
||||
#
|
||||
# Copyright 2015, Noah Kantrowitz
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
require 'chef/provider'
|
||||
require 'chef/resource'
|
||||
|
||||
require 'poise_application_ruby/app_mixin'
|
||||
|
||||
|
||||
module PoiseApplicationRuby
|
||||
module Resources
|
||||
# (see Rails::Resource)
|
||||
module Rails
|
||||
# An `application_rails` resource to configure Ruby on Rails applications.
|
||||
#
|
||||
# @since 4.0.0
|
||||
# @provides application_rails
|
||||
# @action deploy
|
||||
# @example
|
||||
# application '/srv/myapp' do
|
||||
# git '...'
|
||||
# bundle_install
|
||||
# rails do
|
||||
# database do
|
||||
# host node['rails_host']
|
||||
# end
|
||||
# end
|
||||
# unicorn do
|
||||
# port 8080
|
||||
# end
|
||||
# end
|
||||
class Resource < Chef::Resource
|
||||
include PoiseApplicationRuby::AppMixin
|
||||
provides(:application_rails)
|
||||
actions(:deploy)
|
||||
|
||||
# @!attribute database
|
||||
# Option collector attribute for Rails database configuration.
|
||||
# @return [Hash]
|
||||
# @example Setting via block
|
||||
# database do
|
||||
# adapter 'postgresql'
|
||||
# database 'blog'
|
||||
# end
|
||||
# @example Setting via URL
|
||||
# database 'postgresql://localhost/blog'
|
||||
attribute(:database, option_collector: true, parser: :parse_database_url)
|
||||
# @!attribute database_config
|
||||
# Template content attribute for the contents of database.yml.
|
||||
# @todo Redo this doc to cover the actual attributes created.
|
||||
# @return [Poise::Helpers::TemplateContent]
|
||||
attribute(:database_config, template: true, default_source: 'database.yml.erb', default_options: lazy { default_database_options })
|
||||
# @!attribute migrate
|
||||
# Run database migrations. This is a bad idea for real apps. Please
|
||||
# do not use it.
|
||||
# @return [Boolean]
|
||||
attribute(:migrate, equal_to: [true, false], default: false)
|
||||
# @!attribute precompile_assets
|
||||
# Set to true to run rake assets:precompile. By default will try to
|
||||
# auto-detect if Sprockets is in use by looking at config/initializers.
|
||||
# @see #default_precompile_assets
|
||||
# @return [Boolean]
|
||||
attribute(:precompile_assets, equal_to: [true, false], default: lazy { default_precompile_assets })
|
||||
# @!attribute rails_env
|
||||
# Rails environment name. Defaults to the Chef environment name or
|
||||
# `production` if none is set.
|
||||
# @see #default_rails_env
|
||||
# @return [String]
|
||||
attribute(:rails_env, kind_of: String, default: lazy { default_rails_env })
|
||||
# @!attribute secret_token
|
||||
# Secret token for Rails session verification and other purposes. On
|
||||
# Rails 4.2 this will be used for secret_key_base. If not set, no
|
||||
# secrets configuration is written.
|
||||
# @return [String]
|
||||
attribute(:secret_token, kind_of: [String, FalseClass])
|
||||
# @!attribute secrets_config
|
||||
# Template content attribute for the contents of secrets.yml. Only
|
||||
# used when secrets_mode is :yaml.
|
||||
# @todo Redo this doc to cover the actual attributes created.
|
||||
# @return [Poise::Helpers::TemplateContent]
|
||||
attribute(:secrets_config, template: true, default_source: 'secrets.yml.erb', default_options: lazy { default_secrets_options })
|
||||
# @!attribute secrets_mode
|
||||
# Secrets configuration mode. Set to `:yaml` to generate a Rails 4.2
|
||||
# secrets.yml. Set to `:initializer` to update
|
||||
# `config/initializers/secret_token.rb`. If unspecified this is
|
||||
# auto-detected based on what files exist.
|
||||
# @return [Symbol]
|
||||
attribute(:secrets_mode, equal_to: [:yaml, :initializer], default: lazy { default_secrets_mode })
|
||||
|
||||
private
|
||||
|
||||
# Check if we should run the precompile by default. Looks for the
|
||||
# assets initializer because that is not present with --skip-sprockets.
|
||||
#
|
||||
# @return [Boolean]
|
||||
def default_precompile_assets
|
||||
::File.exists?(::File.join(path, 'config', 'initializers', 'assets.rb'))
|
||||
end
|
||||
|
||||
# Check the default environment name.
|
||||
#
|
||||
# @return [String]
|
||||
def default_rails_env
|
||||
node.chef_environment == '_default' ? 'production' : node.chef_environment
|
||||
end
|
||||
|
||||
# Format a single URL for the database.yml
|
||||
#
|
||||
# @return [Hash]
|
||||
def parse_database_url(url)
|
||||
{'url' => url}
|
||||
end
|
||||
|
||||
# Default template variables for the database.yml.
|
||||
#
|
||||
# @return [Hash<Symbol, Object>]
|
||||
def default_database_options
|
||||
db_config = {'encoding' => 'utf8', 'reconnect' => true, 'pool' => 5}.merge(database)
|
||||
{
|
||||
config: {
|
||||
rails_env => db_config
|
||||
},
|
||||
}
|
||||
end
|
||||
|
||||
# Check which secrets configuration mode is in use based on files.
|
||||
#
|
||||
# @return [Symbol]
|
||||
def default_secrets_mode
|
||||
::File.exists?(::File.join(path, 'config', 'initializers', 'secret_token.rb')) ? :initialize : :yaml
|
||||
end
|
||||
|
||||
# Default template variables for the secrets.yml.
|
||||
#
|
||||
# @return [Hash<Symbol, Object>]
|
||||
def default_secrets_options
|
||||
{
|
||||
config: {
|
||||
rails_env => {
|
||||
'secret_key_base' => secret_token,
|
||||
}
|
||||
},
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
# Provider for `application_rails`.
|
||||
#
|
||||
# @since 4.0.0
|
||||
# @see Resource
|
||||
# @provides application_rails
|
||||
class Provider < Chef::Provider
|
||||
include PoiseApplicationRuby::AppMixin
|
||||
provides(:application_rails)
|
||||
|
||||
# `deploy` action for `application_rails`. Ensure all configuration
|
||||
# files are created and other deploy tasks resolved.
|
||||
#
|
||||
# @return [void]
|
||||
def action_deploy
|
||||
set_state
|
||||
notifying_block do
|
||||
write_database_yml unless new_resource.database.empty?
|
||||
write_secrets_config if new_resource.secret_token
|
||||
precompile_assets if new_resource.precompile_assets
|
||||
run_migrations if new_resource.migrate
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# Set app_state variables for future services et al.
|
||||
def set_state
|
||||
new_resource.app_state_environment[:RAILS_ENV] = new_resource.rails_env
|
||||
new_resource.app_state_environment[:DATABASE_URL] = new_resource.database['url'] if new_resource.database['url']
|
||||
end
|
||||
|
||||
# Create a database.yml config file.
|
||||
def write_database_yml
|
||||
file ::File.join(new_resource.path, 'config', 'database.yml') do
|
||||
user new_resource.parent.owner
|
||||
group new_resource.parent.group
|
||||
mode '640'
|
||||
content new_resource.database_config_content
|
||||
end
|
||||
end
|
||||
|
||||
# Dispatch to the correct config writer based on the mode.
|
||||
def write_secrets_config
|
||||
case new_resource.secrets_mode
|
||||
when :yaml
|
||||
write_secrets_yml
|
||||
when :initializer
|
||||
write_secrets_initializer
|
||||
end
|
||||
end
|
||||
|
||||
# Write a Rails 4.2-style secrets.yml.
|
||||
def write_secrets_yml
|
||||
file ::File.join(new_resource.path, 'config', 'secrets.yml') do
|
||||
user new_resource.parent.owner
|
||||
group new_resource.parent.group
|
||||
mode '640'
|
||||
content new_resource.secrets_config_content
|
||||
end
|
||||
end
|
||||
|
||||
# In-place update a config/initializers/secret_token.rb file.
|
||||
def write_secrets_initializer
|
||||
# @todo Implement initalizer-style secret support.
|
||||
raise NotImplementedError.new('Sorry, intializer-style secrets loading is not yet supported.')
|
||||
end
|
||||
|
||||
# Precompile assets using the rake task.
|
||||
def precompile_assets
|
||||
# Currently this will always run so the resource will always update :-/
|
||||
# Better fix would be to shell_out! and parse the output?
|
||||
ruby_execute 'rake assets:precompile' do
|
||||
command %w{rake assets:precompile}
|
||||
user new_resource.parent.owner
|
||||
group new_resource.parent.group
|
||||
cwd new_resource.parent.path
|
||||
environment new_resource.app_state_environment
|
||||
ruby_from_parent new_resource
|
||||
parent_bundle new_resource.parent_bundle if new_resource.parent_bundle
|
||||
end
|
||||
end
|
||||
|
||||
# Run database migrations using the rake task.
|
||||
def run_migrations
|
||||
# Currently this will always run so the resource will always update :-/
|
||||
# Better fix would be to shell_out! and parse the output?
|
||||
ruby_execute 'rake db:migrate' do
|
||||
command %w{rake db:migrate}
|
||||
user new_resource.parent.owner
|
||||
group new_resource.parent.group
|
||||
cwd new_resource.parent.path
|
||||
environment new_resource.app_state_environment
|
||||
ruby_from_parent new_resource
|
||||
parent_bundle new_resource.parent_bundle if new_resource.parent_bundle
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,63 @@
|
||||
#
|
||||
# Copyright 2015, Noah Kantrowitz
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
require 'poise_ruby/resources/ruby_runtime'
|
||||
|
||||
require 'poise_application_ruby/app_mixin'
|
||||
|
||||
|
||||
module PoiseApplicationRuby
|
||||
module Resources
|
||||
# (see Ruby::Resource)
|
||||
# @since 4.0.0
|
||||
module Ruby
|
||||
# An `application_ruby` resource to manage Ruby runtimes
|
||||
# inside an Application cookbook deployment.
|
||||
#
|
||||
# @provides application_ruby
|
||||
# @provides application_ruby_runtime
|
||||
# @action install
|
||||
# @action uninstall
|
||||
# @example
|
||||
# application '/app' do
|
||||
# ruby '2'
|
||||
# end
|
||||
class Resource < PoiseRuby::Resources::RubyRuntime::Resource
|
||||
include PoiseApplicationRuby::AppMixin
|
||||
provides(:application_ruby)
|
||||
provides(:application_ruby_runtime)
|
||||
container_default(false)
|
||||
subclass_providers!
|
||||
|
||||
# Rebind the parent class #gem_binary instead of the one from
|
||||
# RubyCommandMixin (by way of AppMixin)
|
||||
def gem_binary(*args, &block)
|
||||
self.class.superclass.instance_method(:gem_binary).bind(self).call(*args, &block)
|
||||
end
|
||||
|
||||
# Set this resource as the app_state's parent ruby.
|
||||
#
|
||||
# @api private
|
||||
def after_created
|
||||
super.tap do |val|
|
||||
app_state_ruby(self)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,89 @@
|
||||
#
|
||||
# Copyright 2015, Noah Kantrowitz
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
require 'poise_ruby/resources/ruby_execute'
|
||||
|
||||
require 'poise_application_ruby/app_mixin'
|
||||
|
||||
|
||||
module PoiseApplicationRuby
|
||||
module Resources
|
||||
# (see RubyExecute::Resource)
|
||||
# @since 4.0.0
|
||||
module RubyExecute
|
||||
# An `application_ruby_execute` resource to run Ruby commands inside an
|
||||
# Application cookbook deployment.
|
||||
#
|
||||
# @provides application_ruby_execute
|
||||
# @action run
|
||||
# @example
|
||||
# application '/srv/myapp' do
|
||||
# ruby_execute 'rake build'
|
||||
# end
|
||||
class Resource < PoiseRuby::Resources::RubyExecute::Resource
|
||||
include PoiseApplicationRuby::AppMixin
|
||||
provides(:application_ruby_execute)
|
||||
|
||||
def initialize(*args)
|
||||
super
|
||||
# Clear some instance variables so my defaults work.
|
||||
remove_instance_variable(:@cwd)
|
||||
remove_instance_variable(:@group)
|
||||
remove_instance_variable(:@user)
|
||||
end
|
||||
|
||||
# #!attribute cwd
|
||||
# Override the default directory to be the app path if unspecified.
|
||||
# @return [String]
|
||||
attribute(:cwd, kind_of: [String, NilClass, FalseClass], default: lazy { parent && parent.path })
|
||||
|
||||
# #!attribute group
|
||||
# Override the default group to be the app group if unspecified.
|
||||
# @return [String, Integer]
|
||||
attribute(:group, kind_of: [String, Integer, NilClass, FalseClass], default: lazy { parent && parent.group })
|
||||
|
||||
# #!attribute user
|
||||
# Override the default user to be the app owner if unspecified.
|
||||
# @return [String, Integer]
|
||||
attribute(:user, kind_of: [String, Integer, NilClass, FalseClass], default: lazy { parent && parent.owner })
|
||||
end
|
||||
|
||||
# The default provider for `application_ruby_execute`.
|
||||
#
|
||||
# @see Resource
|
||||
# @provides application_ruby_execute
|
||||
class Provider < PoiseRuby::Resources::RubyExecute::Provider
|
||||
provides(:application_ruby_execute)
|
||||
|
||||
private
|
||||
|
||||
# Override environment to add the application envivonrment instead.
|
||||
#
|
||||
# @return [Hash]
|
||||
def environment
|
||||
super.tap do |environment|
|
||||
# Don't use the app_state_environment_ruby because we already have
|
||||
# those values in place.
|
||||
environment.update(new_resource.app_state_environment)
|
||||
# Re-apply the resource environment for correct ordering.
|
||||
environment.update(new_resource.environment) if new_resource.environment
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,46 @@
|
||||
#
|
||||
# Copyright 2015, Noah Kantrowitz
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
require 'poise_ruby/resources/ruby_gem'
|
||||
|
||||
require 'poise_application_ruby/app_mixin'
|
||||
|
||||
|
||||
module PoiseApplicationRuby
|
||||
module Resources
|
||||
# (see RubyGem::Resource)
|
||||
# @since 4.0.0
|
||||
module RubyGem
|
||||
# An `application_ruby_gem` resource to install Ruby gems inside an
|
||||
# Application cookbook deployment.
|
||||
#
|
||||
# @provides application_ruby_gem
|
||||
# @action install
|
||||
# @action upgrade
|
||||
# @action remove
|
||||
# @example
|
||||
# application '/srv/myapp' do
|
||||
# ruby_gem 'rack'
|
||||
# end
|
||||
class Resource < PoiseRuby::Resources::RubyGem::Resource
|
||||
include PoiseApplicationRuby::AppMixin
|
||||
provides(:application_ruby_gem)
|
||||
subclass_providers!
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,64 @@
|
||||
#
|
||||
# Copyright 2015, Noah Kantrowitz
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
require 'chef/provider'
|
||||
require 'chef/resource'
|
||||
|
||||
require 'poise_application_ruby/service_mixin'
|
||||
|
||||
|
||||
module PoiseApplicationRuby
|
||||
module Resources
|
||||
# (see Thin::Resource)
|
||||
# @since 4.0.0
|
||||
module Thin
|
||||
class Resource < Chef::Resource
|
||||
include PoiseApplicationRuby::ServiceMixin
|
||||
provides(:application_thin)
|
||||
|
||||
attribute(:port, kind_of: [String, Integer], default: 80)
|
||||
attribute(:config_path, kind_of: String)
|
||||
end
|
||||
|
||||
class Provider < Chef::Provider
|
||||
include PoiseApplicationRuby::ServiceMixin
|
||||
provides(:application_thin)
|
||||
|
||||
private
|
||||
|
||||
# Find the path to the config.ru. If the resource path was to a
|
||||
# directory, apparent /config.ru.
|
||||
#
|
||||
# @return [String]
|
||||
def configru_path
|
||||
@configru_path ||= if ::File.directory?(new_resource.path)
|
||||
::File.join(new_resource.path, 'config.ru')
|
||||
else
|
||||
new_resource.path
|
||||
end
|
||||
end
|
||||
|
||||
# (see PoiseApplication::ServiceMixin#service_options)
|
||||
def service_options(resource)
|
||||
super
|
||||
cmd = "thin --rackup #{configru_path} --port #{new_resource.port}"
|
||||
cmd << " --config #{::File.expand_path(new_resource.config_path, new_resource.path)}" if new_resource.config_path
|
||||
resource.ruby_command(cmd)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,87 @@
|
||||
#
|
||||
# Copyright 2015, Noah Kantrowitz
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
require 'chef/provider'
|
||||
require 'chef/resource'
|
||||
|
||||
require 'poise_application_ruby/service_mixin'
|
||||
|
||||
|
||||
module PoiseApplicationRuby
|
||||
module Resources
|
||||
# (see Unicorn::Resource)
|
||||
# @since 4.0.0
|
||||
module Unicorn
|
||||
# An `application_unicorn` resource to manage a unicorn web application
|
||||
# server.
|
||||
#
|
||||
# @since 4.0.0
|
||||
# @provides application_unicorn
|
||||
# @action enable
|
||||
# @action disable
|
||||
# @action start
|
||||
# @action stop
|
||||
# @action restart
|
||||
# @action reload
|
||||
# @example
|
||||
# application '/srv/myapp' do
|
||||
# git '...'
|
||||
# bundle_install
|
||||
# unicorn do
|
||||
# port 8080
|
||||
# end
|
||||
# end
|
||||
class Resource < Chef::Resource
|
||||
include PoiseApplicationRuby::ServiceMixin
|
||||
provides(:application_unicorn)
|
||||
|
||||
# @!attribute port
|
||||
# Port to bind to.
|
||||
attribute(:port, kind_of: [String, Integer], default: 80)
|
||||
end
|
||||
|
||||
# Provider for `application_unicorn`.
|
||||
#
|
||||
# @since 4.0.0
|
||||
# @see Resource
|
||||
# @provides application_unicorn
|
||||
class Provider < Chef::Provider
|
||||
include PoiseApplicationRuby::ServiceMixin
|
||||
provides(:application_unicorn)
|
||||
|
||||
private
|
||||
|
||||
# Find the path to the config.ru. If the resource path was to a
|
||||
# directory, apparent /config.ru.
|
||||
#
|
||||
# @return [String]
|
||||
def configru_path
|
||||
@configru_path ||= if ::File.directory?(new_resource.path)
|
||||
::File.join(new_resource.path, 'config.ru')
|
||||
else
|
||||
new_resource.path
|
||||
end
|
||||
end
|
||||
|
||||
# Set service resource options.
|
||||
def service_options(resource)
|
||||
super
|
||||
resource.ruby_command("unicorn --port #{new_resource.port} #{configru_path}")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,66 @@
|
||||
#
|
||||
# Copyright 2015, Noah Kantrowitz
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
require 'poise/utils'
|
||||
require 'poise_application/service_mixin'
|
||||
require 'poise_languages/utils'
|
||||
require 'poise_ruby/bundler_mixin'
|
||||
|
||||
require 'poise_application_ruby/app_mixin'
|
||||
|
||||
|
||||
module PoiseApplicationRuby
|
||||
# A helper mixin for Ruby service resources and providers.
|
||||
#
|
||||
# @since 4.0.0
|
||||
module ServiceMixin
|
||||
include Poise::Utils::ResourceProviderMixin
|
||||
|
||||
# A helper mixin for Ruby service resources.
|
||||
module Resource
|
||||
include PoiseApplication::ServiceMixin::Resource
|
||||
include PoiseApplicationRuby::AppMixin::Resource
|
||||
end
|
||||
|
||||
# A helper mixin for Ruby service providers.
|
||||
module Provider
|
||||
include PoiseApplication::ServiceMixin::Provider
|
||||
include PoiseApplicationRuby::AppMixin::Provider
|
||||
include PoiseRuby::BundlerMixin
|
||||
|
||||
# Set up the service for running Ruby stuff.
|
||||
def service_options(resource)
|
||||
super
|
||||
# Closure scoping for #ruby_command below.
|
||||
self_ = self
|
||||
# Create a new singleton method that fills in Python for you.
|
||||
resource.define_singleton_method(:ruby_command) do |val|
|
||||
path = self_.new_resource.app_state_environment_ruby['PATH']
|
||||
cmd = if self_.new_resource.parent_bundle
|
||||
bundle_exec_command(val, path: path)
|
||||
else
|
||||
"#{self_.new_resource.ruby} #{PoiseLanguages::Utils.absolute_command(val, path: path)}"
|
||||
end
|
||||
resource.command(cmd)
|
||||
end
|
||||
# Include env vars as needed.
|
||||
resource.environment.update(new_resource.parent_ruby.ruby_environment) if new_resource.parent_ruby
|
||||
resource.environment['BUNDLE_GEMFILE'] = new_resource.parent_bundle.gemfile_path if new_resource.parent_bundle
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,19 @@
|
||||
#
|
||||
# Copyright 2015, Noah Kantrowitz
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
module PoiseApplicationRuby
|
||||
VERSION = '4.0.1'
|
||||
end
|
||||
19
cookbooks/application_ruby/libraries/default.rb
Normal file
19
cookbooks/application_ruby/libraries/default.rb
Normal file
@@ -0,0 +1,19 @@
|
||||
#
|
||||
# Copyright 2015, Noah Kantrowitz
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
raise 'Halite is not compatible with no_lazy_load false, please set no_lazy_load true in your Chef configuration file.' unless Chef::Config[:no_lazy_load]
|
||||
$LOAD_PATH << File.expand_path('../../files/halite_gem', __FILE__)
|
||||
require "poise_application_ruby/cheftie"
|
||||
1
cookbooks/application_ruby/metadata.json
Normal file
1
cookbooks/application_ruby/metadata.json
Normal file
File diff suppressed because one or more lines are too long
3
cookbooks/application_ruby/templates/database.yml.erb
Normal file
3
cookbooks/application_ruby/templates/database.yml.erb
Normal file
@@ -0,0 +1,3 @@
|
||||
# Generated by Chef for <%= @new_resource.to_s %>
|
||||
|
||||
<%= @config.to_yaml %>
|
||||
3
cookbooks/application_ruby/templates/secrets.yml.erb
Normal file
3
cookbooks/application_ruby/templates/secrets.yml.erb
Normal file
@@ -0,0 +1,3 @@
|
||||
# Generated by Chef for <%= @new_resource.to_s %>
|
||||
|
||||
<%= @config.to_yaml %>
|
||||
Reference in New Issue
Block a user