diff --git a/attributes/default.rb b/attributes/default.rb index 64bdd479..d3383d30 100644 --- a/attributes/default.rb +++ b/attributes/default.rb @@ -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 diff --git a/recipes/configure.rb b/recipes/configure.rb index dbbb1766..11560541 100644 --- a/recipes/configure.rb +++ b/recipes/configure.rb @@ -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')) diff --git a/recipes/deploy.rb b/recipes/deploy.rb index b898325e..beccc790 100644 --- a/recipes/deploy.rb +++ b/recipes/deploy.rb @@ -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)) @@ -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) diff --git a/recipes/setup.rb b/recipes/setup.rb index 773d4682..b15c3758 100644 --- a/recipes/setup.rb +++ b/recipes/setup.rb @@ -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)) diff --git a/recipes/shutdown.rb b/recipes/shutdown.rb index edec6ff8..73c36044 100644 --- a/recipes/shutdown.rb +++ b/recipes/shutdown.rb @@ -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)) diff --git a/recipes/undeploy.rb b/recipes/undeploy.rb index 6a1a6bb8..a4679a67 100644 --- a/recipes/undeploy.rb +++ b/recipes/undeploy.rb @@ -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)) diff --git a/spec/unit/recipes/deploy_spec.rb b/spec/unit/recipes/deploy_spec.rb index 8f5e7e8d..a6eb0567 100644 --- a/spec/unit/recipes/deploy_spec.rb +++ b/spec/unit/recipes/deploy_spec.rb @@ -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: { diff --git a/spec/unit/recipes/setup_spec.rb b/spec/unit/recipes/setup_spec.rb index a902e145..e8833844 100644 --- a/spec/unit/recipes/setup_spec.rb +++ b/spec/unit/recipes/setup_spec.rb @@ -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')