Permalink
Browse files

Added multi-platform support

  • Loading branch information...
ajgon committed Apr 23, 2016
1 parent 72d4b9f commit 61181540864b058e2d6d4495c5e85c05b0e20117
View
@@ -9,7 +9,7 @@ A [chef](https://www.chef.io/) cookbook to deploy Ruby applications to Amazon Op
## Quick Start
This cookbook is design to "just work". So in base case scenario, all you have
This cookbook is designed to "just work". So in base case scenario, all you have
to do is create a layer and application with assigned RDS data source, then
[add recipes to the corresponding OpsWorks actions](#recipes).
@@ -41,8 +41,15 @@ to do is create a layer and application with assigned RDS data source, then
### Platform
Currenty this cookbook was tested only under Ubuntu 14.04, more platforms will
be added soon. However, other Debian family distributions are assumed to work.
This cookbook was tested on the following OpsWorks platforms:
* Amazon Linux 2016.03
* Amazon Linux 2015.09
* Amazon Linux 2015.03
* Ubuntu 14.04 LTS
* Ubuntu 12.04 LTS
In addition, all recent Debian family distrubutions are assumed to work.
## Attributes
View
@@ -66,9 +66,10 @@
default['defaults']['framework']['migrate'] = true
default['defaults']['framework']['migration_command'] =
'bundle exec rake db:version > /dev/null 2>&1 && bundle exec rake db:migrate || bundle exec rake db:setup'
'/usr/local/bin/bundle exec rake db:version > /dev/null 2>&1 ' \
'&& /usr/local/bin/bundle exec rake db:migrate || /usr/local/bin/bundle exec rake db:setup'
default['defaults']['framework']['assets_precompile'] = true
default['defaults']['framework']['assets_precompilation_command'] = 'bundle exec rake assets:precompile'
default['defaults']['framework']['assets_precompilation_command'] = '/usr/local/bin/bundle exec rake assets:precompile'
# worker
## common
@@ -4,7 +4,7 @@ module Db
class Postgresql < Base
adapter :postgresql
allowed_engines :postgres, :postgresql
packages 'libpq-dev'
packages debian: 'libpq-dev', rhel: 'postgresql94-devel'
end
end
end
@@ -5,8 +5,11 @@ module Packages
def self.included(klass)
klass.instance_eval do
def packages(*to_support)
@packages = to_support.map(&:to_s) if to_support.present?
@packages || []
@packages ||= []
(to_support || []).each do |pkg|
@packages.push((pkg.is_a?(Hash) ? pkg : { all: pkg.to_s }).stringify_keys)
end
@packages.uniq
end
end
end
@@ -17,7 +20,7 @@ def packages
def handle_packages(context)
packages.each do |pkg|
context.package pkg do
context.package(pkg.key?('all') ? pkg['all'] : pkg[node['platform_family']] || pkg[node['platform']]) do
action :install
end
end
@@ -3,6 +3,11 @@ module Drivers
module Framework
class Base < Drivers::Base
include Drivers::Dsl::Output
include Drivers::Dsl::Packages
def setup(context)
handle_packages(context)
end
def out
handle_output(raw_out)
@@ -7,6 +7,7 @@ class Rails < Drivers::Framework::Base
output filter: [
:migrate, :migration_command, :deploy_environment, :assets_precompile, :assets_precompilation_command
]
packages debian: 'zlib1g-dev', rhel: 'zlib-devel'
def raw_out
super.merge(deploy_environment: { 'RAILS_ENV' => 'production' })
View
@@ -13,5 +13,8 @@
depends 'nginx', '~> 2.7'
depends 'application_ruby'
supports 'amazon', '>= 2015.03'
supports 'ubuntu', '>= 12.04'
source_url 'https://github.com/ajgon/opsworks_ruby'
issues_url 'https://github.com/ajgon/opsworks_ruby/issues'
View
@@ -8,13 +8,25 @@
# Ruby and bundler
include_recipe 'deployer'
include_recipe 'ruby-ng::dev'
if node['platform_family'] == 'debian'
include_recipe 'ruby-ng::dev'
else
ruby_pkg_version = node['ruby-ng']['ruby_version'].split('.')[0..1]
package "ruby#{ruby_pkg_version.join('')}"
package "ruby#{ruby_pkg_version.join('')}-devel"
execute "/usr/sbin/alternatives --set ruby /usr/bin/ruby#{ruby_pkg_version.join('.')}"
end
gem_package 'bundler'
link '/usr/local/bin/bundle' do
to '/usr/bin/bundle'
if node['platform_family'] == 'debian'
link '/usr/local/bin/bundle' do
to '/usr/bin/bundle'
end
else
link '/usr/local/bin/bundle' do
to '/usr/local/bin/bundler'
end
end
every_enabled_application do |application, _deploy|
every_enabled_rds do |rds|
database = Drivers::Db::Factory.build(application, node, rds: rds)
@@ -9,7 +9,7 @@
describe 'opsworks_ruby::configure' do
let(:chef_run) do
ChefSpec::SoloRunner.new do |solo_node|
ChefSpec::SoloRunner.new(platform: 'ubuntu', version: '14.04') do |solo_node|
solo_node.set['deploy'] = node['deploy']
solo_node.set['nginx'] = node['nginx']
end.converge(described_recipe)
@@ -121,7 +121,7 @@
end
it 'enables ssl rules for legacy browsers in nginx config' do
chef_run = ChefSpec::SoloRunner.new do |solo_node|
chef_run = ChefSpec::SoloRunner.new(platform: 'ubuntu', version: '14.04') do |solo_node|
deploy = node['deploy']
deploy[aws_opsworks_app['shortname']]['webserver']['ssl_for_legacy_browsers'] = true
solo_node.set['deploy'] = deploy
@@ -234,7 +234,7 @@
end
it 'empty node[\'deploy\']' do
chef_run = ChefSpec::SoloRunner.new do |solo_node|
chef_run = ChefSpec::SoloRunner.new(platform: 'ubuntu', version: '14.04') do |solo_node|
solo_node.set['lsb'] = node['lsb']
end.converge(described_recipe)
@@ -9,7 +9,7 @@
describe 'opsworks_ruby::deploy' do
let(:chef_run) do
ChefSpec::SoloRunner.new do |solo_node|
ChefSpec::SoloRunner.new(platform: 'ubuntu', version: '14.04') do |solo_node|
deploy = node['deploy']
deploy['dummy_project']['scm'].delete('ssh_wrapper')
solo_node.set['deploy'] = deploy
@@ -59,7 +59,7 @@
expect(chef_run).to run_execute('stop unicorn')
expect(chef_run).to run_execute('start unicorn')
expect(chef_run).to run_execute('assets:precompile').with(
command: 'bundle exec rake assets:precompile',
command: '/usr/local/bin/bundle exec rake assets:precompile',
environment: { 'RAILS_ENV' => 'production' },
cwd: "/srv/www/#{aws_opsworks_app['shortname']}/current"
)
@@ -75,7 +75,7 @@
end
it 'empty node[\'deploy\']' do
chef_run = ChefSpec::SoloRunner.new do |solo_node|
chef_run = ChefSpec::SoloRunner.new(platform: 'ubuntu', version: '14.04') do |solo_node|
solo_node.set['lsb'] = node['lsb']
end.converge(described_recipe)
@@ -89,7 +89,7 @@
aws_opsworks_app.merge(shortname: 'a1'),
aws_opsworks_app.merge(shortname: 'a2')
])
chef_run = ChefSpec::SoloRunner.new do |solo_node|
chef_run = ChefSpec::SoloRunner.new(platform: 'ubuntu', version: '14.04') do |solo_node|
solo_node.set['lsb'] = node['lsb']
solo_node.set['deploy'] = { 'a1' => {}, 'a2' => {} }
solo_node.set['applications'] = ['a1']
@@ -9,11 +9,16 @@
describe 'opsworks_ruby::setup' do
let(:chef_run) do
ChefSpec::SoloRunner.new do |solo_node|
ChefSpec::SoloRunner.new(platform: 'ubuntu', version: '14.04') do |solo_node|
solo_node.set['deploy'] = node['deploy']
solo_node.set['lsb'] = node['lsb']
end.converge(described_recipe)
end
let(:chef_run_rhel) do
ChefSpec::SoloRunner.new(platform: 'amazon', version: '2015.03') do |solo_node|
solo_node.set['deploy'] = node['deploy']
end.converge(described_recipe)
end
before do
stub_search(:aws_opsworks_app, '*:*').and_return([aws_opsworks_app])
@@ -27,59 +32,118 @@
end
context 'Rubies' do
it 'installs ruby 2.0' do
chef_run = ChefSpec::SoloRunner.new do |solo_node|
solo_node.set['ruby'] = { 'version' => '2.0' }
solo_node.set['lsb'] = node['lsb']
solo_node.set['deploy'] = node['deploy']
end.converge(described_recipe)
expect(chef_run).to install_package('ruby2.0')
expect(chef_run).to install_package('ruby2.0-dev')
end
it 'installs ruby 2.1' do
chef_run = ChefSpec::SoloRunner.new do |solo_node|
solo_node.set['ruby'] = { 'version' => '2.1' }
solo_node.set['lsb'] = node['lsb']
solo_node.set['deploy'] = node['deploy']
end.converge(described_recipe)
expect(chef_run).to install_package('ruby2.1')
expect(chef_run).to install_package('ruby2.1-dev')
context 'Debian' do
it 'installs ruby 2.0' do
chef_run = ChefSpec::SoloRunner.new(platform: 'ubuntu', version: '14.04') do |solo_node|
solo_node.set['ruby'] = { 'version' => '2.0' }
solo_node.set['lsb'] = node['lsb']
solo_node.set['deploy'] = node['deploy']
end.converge(described_recipe)
expect(chef_run).to install_package('ruby2.0')
expect(chef_run).to install_package('ruby2.0-dev')
end
it 'installs ruby 2.1' do
chef_run = ChefSpec::SoloRunner.new(platform: 'ubuntu', version: '14.04') do |solo_node|
solo_node.set['ruby'] = { 'version' => '2.1' }
solo_node.set['lsb'] = node['lsb']
solo_node.set['deploy'] = node['deploy']
end.converge(described_recipe)
expect(chef_run).to install_package('ruby2.1')
expect(chef_run).to install_package('ruby2.1-dev')
end
it 'installs ruby 2.2' do
chef_run = ChefSpec::SoloRunner.new(platform: 'ubuntu', version: '14.04') do |solo_node|
solo_node.set['ruby'] = { 'version' => '2.2' }
solo_node.set['lsb'] = node['lsb']
solo_node.set['deploy'] = node['deploy']
end.converge(described_recipe)
expect(chef_run).to install_package('ruby2.2')
expect(chef_run).to install_package('ruby2.2-dev')
end
it 'installs ruby 2.3' do
expect(chef_run).to install_package('ruby2.3')
expect(chef_run).to install_package('ruby2.3-dev')
end
end
it 'installs ruby 2.2' do
chef_run = ChefSpec::SoloRunner.new do |solo_node|
solo_node.set['ruby'] = { 'version' => '2.2' }
solo_node.set['lsb'] = node['lsb']
solo_node.set['deploy'] = node['deploy']
end.converge(described_recipe)
expect(chef_run).to install_package('ruby2.2')
expect(chef_run).to install_package('ruby2.2-dev')
end
it 'installs ruby 2.3' do
expect(chef_run).to install_package('ruby2.3')
expect(chef_run).to install_package('ruby2.3-dev')
context 'rhel' do
it 'installs ruby 2.0' do
chef_run_rhel = ChefSpec::SoloRunner.new(platform: 'amazon', version: '2015.03') do |solo_node|
solo_node.set['ruby'] = { 'version' => '2.0' }
solo_node.set['lsb'] = node['lsb']
solo_node.set['deploy'] = node['deploy']
end.converge(described_recipe)
expect(chef_run_rhel).to install_package('ruby20')
expect(chef_run_rhel).to install_package('ruby20-devel')
expect(chef_run_rhel).to run_execute('/usr/sbin/alternatives --set ruby /usr/bin/ruby2.0')
end
it 'installs ruby 2.1' do
chef_run_rhel = ChefSpec::SoloRunner.new(platform: 'amazon', version: '2015.03') do |solo_node|
solo_node.set['ruby'] = { 'version' => '2.1' }
solo_node.set['lsb'] = node['lsb']
solo_node.set['deploy'] = node['deploy']
end.converge(described_recipe)
expect(chef_run_rhel).to install_package('ruby21')
expect(chef_run_rhel).to install_package('ruby21-devel')
expect(chef_run_rhel).to run_execute('/usr/sbin/alternatives --set ruby /usr/bin/ruby2.1')
end
it 'installs ruby 2.2' do
chef_run_rhel = ChefSpec::SoloRunner.new(platform: 'amazon', version: '2015.03') do |solo_node|
solo_node.set['ruby'] = { 'version' => '2.2' }
solo_node.set['lsb'] = node['lsb']
solo_node.set['deploy'] = node['deploy']
end.converge(described_recipe)
expect(chef_run_rhel).to install_package('ruby22')
expect(chef_run_rhel).to install_package('ruby22-devel')
expect(chef_run_rhel).to run_execute('/usr/sbin/alternatives --set ruby /usr/bin/ruby2.2')
end
it 'installs ruby 2.3' do
expect(chef_run_rhel).to install_package('ruby23')
expect(chef_run_rhel).to install_package('ruby23-devel')
expect(chef_run_rhel).to run_execute('/usr/sbin/alternatives --set ruby /usr/bin/ruby2.3')
end
end
end
context 'Gems' do
it 'bundler' do
it 'debian bundler' do
expect(chef_run).to install_gem_package(:bundler)
expect(chef_run).to create_link('/usr/local/bin/bundle')
expect(chef_run).to create_link('/usr/local/bin/bundle').with(to: '/usr/bin/bundle')
end
it 'rhel bundler' do
expect(chef_run_rhel).to install_gem_package(:bundler)
expect(chef_run_rhel).to create_link('/usr/local/bin/bundle').with(to: '/usr/local/bin/bundler')
end
end
context 'Postgresql + git + nginx' do
it 'installs required packages' do
it 'installs required packages for debian' do
expect(chef_run).to install_package('nginx')
expect(chef_run).to install_package('zlib1g-dev')
expect(chef_run).to install_package('git')
expect(chef_run).to install_package('libpq-dev')
end
it 'installs required packages for rhel' do
expect(chef_run_rhel).to install_package('nginx')
expect(chef_run_rhel).to install_package('zlib-devel')
expect(chef_run_rhel).to install_package('git')
expect(chef_run_rhel).to install_package('postgresql94-devel')
end
it 'defines service which starts nginx' do
expect(chef_run).to start_service('nginx')
end
@@ -90,13 +154,17 @@
stub_search(:aws_opsworks_rds_db_instance, '*:*').and_return([aws_opsworks_rds_db_instance(engine: 'mysql')])
end
it 'installs required packages' do
it 'installs required packages for debian' do
expect(chef_run).to install_package('libmysqlclient-dev')
end
it 'installs required packages for rhel' do
expect(chef_run_rhel).to install_package('mysql-devel')
end
end
it 'empty node[\'deploy\']' do
chef_run = ChefSpec::SoloRunner.new do |solo_node|
chef_run = ChefSpec::SoloRunner.new(platform: 'ubuntu', version: '14.04') do |solo_node|
solo_node.set['lsb'] = node['lsb']
end.converge(described_recipe)
Oops, something went wrong.

0 comments on commit 6118154

Please sign in to comment.