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

Use revision-based deploy provider. #245

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions attributes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
default['defaults']['global']['logrotate_options'] = %w[
missingok compress delaycompress notifempty copytruncate sharedscripts
]
default['defaults']['global']['deploy_revision'] = false
default['defaults']['global']['use_nodejs'] = false

if node['use-nodejs']
Expand Down
10 changes: 10 additions & 0 deletions docs/source/attributes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,15 @@ Global parameters apply to the whole application, and can be used by any section
will result in the ``logrotate_app`` resource being invoked with the resource value ``cookbook 'my_cookbook'``.
- See Logrotate Attributes for more information on logrotate attribute precedence.

- ``app['global']['deploy_revision']``

- **Type:** boolean
- **Default:** ``false``
- When set to true, deployments will use the ``deploy_revision`` provider.
The name of a release sub-directory will use a revision identifier rather
than a timestamp.
- See `the deploy_revision documentation`_ for more information.


database
~~~~~~~~
Expand Down Expand Up @@ -893,6 +902,7 @@ shoryuken
.. _app['appserver']['after_worker_fork']: https://github.com/puma/puma/blob/e4255d03fb57021c96f7d03a3784b21b6e85b35b/examples/config.rb#L150
.. _Read more here.: https://weakdh.org/sysadmin.html
.. _covered in this article: https://cipherli.st/
.. _the deploy_revision documentation: https://docs-archive.chef.io/release/12-13/resource_deploy.html#deploy-revision
.. |app['webserver']['limit_request_body']| replace:: ``app['webserver']['limit_request_body']``
.. _app['webserver']['limit_request_body']: https://httpd.apache.org/docs/2.4/mod/core.html#limitrequestbody
.. |app['webserver']['log_level']| replace:: ``app['webserver']['log_level']``
Expand Down
4 changes: 4 additions & 0 deletions recipes/deploy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@
group www_group
environment env_vars

if globals(:deploy_revision, application['shortname'])
provider Chef::Provider::Deploy::Revision
end

if globals(:rollback_on_error, application['shortname']).nil?
rollback_on_error node['defaults']['global']['rollback_on_error']
else
Expand Down
4 changes: 4 additions & 0 deletions recipes/undeploy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
user node['deployer']['user'] || 'root'
group www_group

if globals(:deploy_revision, application['shortname'])
provider Chef::Provider::Deploy::Revision
end

[appserver, webserver].each do |server|
server.notifies[:undeploy].each do |config|
notifies config[:action],
Expand Down
2 changes: 1 addition & 1 deletion spec/fixtures/aws_opsworks_app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ def aws_opsworks_app(override = {})
app_id: '3aef37c1-7e2b-4255-bbf1-03e06f07701a',
app_source: {
password: '3aa161d358a167204502',
revision: 'master',
revision: 'dbfbd8dbc989e3a4465504d83fafc5ec7f204e7f',
ssh_key: '--- SSH KEY ---',
type: 'git',
url: 'git@git.example.com:repo/project.git',
Expand Down
9 changes: 9 additions & 0 deletions spec/unit/recipes/deploy_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,7 @@
solo_node.set['lsb'] = node['lsb']
solo_node.set['deploy'] = { 'a1' => {} }
solo_node.set['deploy']['a1']['global']['deploy_dir'] = deploy_dir if deploy_dir
solo_node.set['deploy']['a1']['global']['deploy_revision'] = deploy_revision if deploy_revision
end
end

Expand All @@ -407,6 +408,14 @@
end
end

context 'when deploy_revision is true' do
let(:deploy_revision) { true }

it 'deploys a1 using a release subdirectory named by revision' do
expect(chef_run).to create_directory("/srv/www/a1/releases/dbfbd8dbc989e3a4465504d83fafc5ec7f204e7f")
end
end

context 'when a deploy_dir is specified' do
let(:deploy_dir) { '/some/other/path/to/a1' }

Expand Down
3 changes: 2 additions & 1 deletion templates/default/appserver.service.erb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ def different_gemfile?
current_gemfile = "#{ROOT_PATH}/current/Gemfile.lock"
if File.exists?(current_gemfile)
dir = Dir["#{ROOT_PATH}/releases/*"]
previous_release_path = dir.sort[dir.size-2]
previous_release_path = dir.sort_by { |d| ::File.ctime(d) }[-2]

if !previous_release_path.nil? && File.exists?("#{previous_release_path}/Gemfile.lock")
return Digest::MD5.hexdigest(File.read(current_gemfile)) != Digest::MD5.hexdigest(File.read("#{previous_release_path}/Gemfile.lock"))
end
Expand Down