Skip to content
This repository has been archived by the owner on Dec 31, 2022. It is now read-only.

Commit

Permalink
feat: app['rollback_on_error'] implemented
Browse files Browse the repository at this point in the history
Resolves #54
  • Loading branch information
ajgon committed Oct 26, 2016
1 parent 5fc42c3 commit e6934a7
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 11 deletions.
1 change: 1 addition & 0 deletions attributes/default.rb
Expand Up @@ -11,6 +11,7 @@
default['defaults']['deploy']['create_dirs_before_symlink'] =
%w(tmp public config ../../shared/cache ../../shared/assets)
default['defaults']['deploy']['purge_before_symlink'] = %w(log tmp/cache tmp/pids public/system public/assets)
default['defaults']['deploy']['rollback_on_error'] = true

# ruby

Expand Down
2 changes: 1 addition & 1 deletion recipes/configure.rb
Expand Up @@ -6,7 +6,7 @@

prepare_recipe

every_enabled_application do |application, _deploy|
every_enabled_application do |application, _app_data|
create_deploy_dir(application, File.join('shared'))
create_deploy_dir(application, File.join('shared', 'config'))
create_deploy_dir(application, File.join('shared', 'log'))
Expand Down
21 changes: 14 additions & 7 deletions recipes/deploy.rb
Expand Up @@ -5,7 +5,7 @@
include_recipe 'opsworks_ruby::configure'

# rubocop:disable Metrics/BlockLength
every_enabled_application do |application, deploy|
every_enabled_application do |application, app_data|
databases = []
every_enabled_rds(self, application) do |rds|
databases.push(Drivers::Db::Factory.build(self, application, rds: rds))
Expand All @@ -24,18 +24,25 @@
deploy_to deploy_dir(application)
user node['deployer']['user'] || 'root'
group www_group
rollback_on_error true
environment application['environment'].merge(framework.out[:deploy_environment] || {})

keep_releases deploy[:keep_releases]
if app_data[:rollback_on_error].nil?
rollback_on_error node['defaults']['deploy']['rollback_on_error']
else
rollback_on_error app_data[:rollback_on_error]
end

keep_releases app_data[:keep_releases]
create_dirs_before_symlink(
(node['defaults']['deploy']['create_dirs_before_symlink'] + Array.wrap(deploy[:create_dirs_before_symlink])).uniq
(
node['defaults']['deploy']['create_dirs_before_symlink'] + Array.wrap(app_data[:create_dirs_before_symlink])
).uniq
)
purge_before_symlink(
(node['defaults']['deploy']['purge_before_symlink'] + Array.wrap(deploy[:purge_before_symlink])).uniq
(node['defaults']['deploy']['purge_before_symlink'] + Array.wrap(app_data[:purge_before_symlink])).uniq
)
symlink_before_migrate deploy[:symlink_before_migrate]
symlinks(node['defaults']['deploy']['symlinks'].merge(deploy[:symlinks] || {}))
symlink_before_migrate app_data[:symlink_before_migrate]
symlinks(node['defaults']['deploy']['symlinks'].merge(app_data[:symlinks] || {}))

scm.out.each do |scm_key, scm_value|
send(scm_key, scm_value) if respond_to?(scm_key)
Expand Down
2 changes: 1 addition & 1 deletion recipes/setup.rb
Expand Up @@ -39,7 +39,7 @@

execute 'yum-config-manager --enable epel' if node['platform_family'] == 'rhel'

every_enabled_application do |application, _deploy|
every_enabled_application do |application, _app_data|
databases = []
every_enabled_rds(self, application) do |rds|
databases.push(Drivers::Db::Factory.build(self, application, rds: rds))
Expand Down
2 changes: 1 addition & 1 deletion recipes/shutdown.rb
Expand Up @@ -6,7 +6,7 @@

prepare_recipe

every_enabled_application do |application, _deploy|
every_enabled_application do |application, _app_data|
databases = []
every_enabled_rds(self, application) do |rds|
databases.push(Drivers::Db::Factory.build(self, application, rds: rds))
Expand Down
2 changes: 1 addition & 1 deletion recipes/undeploy.rb
Expand Up @@ -2,7 +2,7 @@

prepare_recipe

every_enabled_application do |application, _deploy|
every_enabled_application do |application, _app_data|
databases = []
every_enabled_rds(self, application) do |rds|
databases.push(Drivers::Db::Factory.build(self, application, rds: rds))
Expand Down
1 change: 1 addition & 0 deletions spec/unit/recipes/deploy_spec.rb
Expand Up @@ -43,6 +43,7 @@
revision: 'master',
scm_provider: Chef::Provider::Git,
enable_submodules: false,
rollback_on_error: true,
environment: aws_opsworks_app['environment'].merge('RAILS_ENV' => 'staging'),
ssh_wrapper: '/tmp/ssh-git-wrapper.sh',
symlinks: {
Expand Down
6 changes: 6 additions & 0 deletions spec/unit/recipes/setup_spec.rb
Expand Up @@ -135,6 +135,12 @@
end
end

context 'apt_repository' do
it 'debian' do
expect(chef_run).to add_apt_repository('apache2')
end
end

context 'Postgresql + git + nginx + sidekiq' do
it 'installs required packages for debian' do
expect(chef_run).to install_package('nginx')
Expand Down

0 comments on commit e6934a7

Please sign in to comment.