Skip to content
Permalink
Browse files

Reorganized appserver cookbooks, added bundle install to deploy

  • Loading branch information...
ajgon committed Apr 13, 2016
1 parent 0182e70 commit 2e9947b4913459655df70fe2974e9708996c097c
@@ -7,15 +7,16 @@
# appserver
## common

default['appserver']['worker_processes'] = 4
default['defaults']['appserver']['worker_processes'] = 4
default['defaults']['appserver']['adapter'] = 'unicorn'

## unicorn

default['appserver']['accept_filter'] = 'httpready'
default['appserver']['backlog'] = 1024
default['appserver']['delay'] = 0.5
default['appserver']['preload_app'] = true
default['appserver']['tcp_nodelay'] = true
default['appserver']['tcp_nopush'] = false
default['appserver']['tries'] = 5
default['appserver']['timeout'] = 60
default['defaults']['appserver']['accept_filter'] = 'httpready'
default['defaults']['appserver']['backlog'] = 1024
default['defaults']['appserver']['delay'] = 0.5
default['defaults']['appserver']['preload_app'] = true
default['defaults']['appserver']['tcp_nodelay'] = true
default['defaults']['appserver']['tcp_nopush'] = false
default['defaults']['appserver']['tries'] = 5
default['defaults']['appserver']['timeout'] = 60
@@ -10,17 +10,12 @@ def out
end

def raw_out
node_engine.symbolize_keys
node['defaults']['appserver'].merge(
node['deploy'][app['shortname']]['appserver'] || {}
).symbolize_keys
end

protected

def validate_app_engine
:node_engine
end

def node_engine
node['appserver']
end
end
end
@@ -8,9 +8,12 @@ def self.build(app, node, options = {})
engine.new(app, node, options)
end

def self.detect_engine(_app, node, _options)
def self.detect_engine(app, node, _options)
Drivers::Appserver::Base.descendants.detect do |appserver_driver|
appserver_driver.allowed_engines.include?(node['appserver']['adapter'].presence || 'unicorn')
appserver_driver.allowed_engines.include?(
node['deploy'][app['shortname']]['appserver'].try(:[], 'adapter') ||
node['defaults']['appserver']['adapter']
)
end
end
end
@@ -1,13 +1,15 @@
# frozen_string_literal: true
include_recipe 'opsworks_ruby::configure'

every_enabled_application do |application, _deploy|
scm = Drivers::Scm::Factory.build(application, node)
do_migrate = true

every_enabled_application do |app, _deploy|
scm = Drivers::Scm::Factory.build(app, node)
scm.before_deploy(self)
appserver = Drivers::Appserver::Factory.build(application, node)
appserver = Drivers::Appserver::Factory.build(app, node)

deploy application['shortname'] do
deploy_to deploy_dir(application)
deploy app['shortname'] do
deploy_to deploy_dir(app)
user node['deployer']['user'] || 'root'
group www_group

@@ -17,21 +19,43 @@

appserver.notifies.each do |config|
notifies config[:action],
config[:resource].respond_to?(:call) ? config[:resource].call(application) : config[:resource],
config[:resource].respond_to?(:call) ? config[:resource].call(app) : config[:resource],
config[:timer]
end

migration_command(
'bundle exec rake db:version > /dev/null 2>&1 && bundle exec rake db:migrate || bundle exec rake db:setup'
)
migrate do_migrate
before_migrate do
bundle_install File.join(release_path, 'Gemfile') do
deployment true
without %w(development test)
end

run_callback_from_file(File.join(release_path, 'deploy', 'before_migrate.rb'))
end

before_symlink do
bundle_install File.join(release_path, 'Gemfile') do
deployment true
without %w(development test)
end unless do_migrate

run_callback_from_file(File.join(release_path, 'deploy', 'before_symlink.rb'))
end
end

scm.after_deploy(self)
end

# every_enabled_application do |application, deploy|
# deploy application['shortname'] do
# every_enabled_app do |app, deploy|
# deploy app['shortname'] do
# deploy_to deploy_dir
# environment application['environment'] || {}
# environment app['environment'] || {}
# group www_group
# migrate false
# repository application['app_source']['url']
# repository app['app_source']['url']
# rollback_on_error true
# user node['deployer']['user']
# end
@@ -4,10 +4,14 @@
# Recipe:: setup
#

# Ruby and bundler
include_recipe 'deployer'
include_recipe 'ruby-ng::dev'

gem_package 'bundler'
link '/usr/local/bin/bundle' do
to '/usr/bin/bundle'
end

every_enabled_application do |application|
scm = Drivers::Scm::Factory.build(application, node)
@@ -26,6 +26,9 @@ def node(override = {})
ssh_wrapper: 'ssh-wrap',
submodules: false,
wrong_param: 'bad'
},
appserver: {
delay: 3
}
}
}
@@ -60,6 +60,9 @@
expect(chef_run)
.to render_file("/srv/www/#{aws_opsworks_app['shortname']}/shared/config/unicorn.conf")
.with_content('worker_processes 4')
expect(chef_run)
.to render_file("/srv/www/#{aws_opsworks_app['shortname']}/shared/config/unicorn.conf")
.with_content(':delay => 3')
end

it 'creates proper unicorn.service file' do
@@ -68,6 +68,7 @@
context 'Gems' do
it 'bundler' do
expect(chef_run).to install_gem_package(:bundler)
expect(chef_run).to create_link('/usr/local/bin/bundle')
end
end

@@ -37,7 +37,7 @@ def different_gemfile?
end

def start_unicorn
run_and_ignore_exitcode_and_print_command "cd #{ROOT_PATH}/current && /usr/local/bin/bundle exec unicorn_rails --env <%= @rails_env %> --daemonize -c #{ROOT_PATH}/shared/config/unicorn.conf"
run_and_ignore_exitcode_and_print_command "cd #{ROOT_PATH}/current && /usr/bin/bundle exec unicorn_rails --env <%= @rails_env %> --daemonize -c #{ROOT_PATH}/shared/config/unicorn.conf"
end

def stop_unicorn

0 comments on commit 2e9947b

Please sign in to comment.
You can’t perform that action at this time.