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

Commit

Permalink
feat(global): support per-application deploy directory
Browse files Browse the repository at this point in the history
Some Opsworks users deploy their apps on custom AMIs with strict
partitioning schemes and disk space limitations. For these users
the default deploy directory /srv/www is not always a good choice.

This patch allows users to override the deploy directory at the
application level by specifying the attribute

`node['deploy'][shortname]['global']['deploy_dir']`

The default value for the app-specific deploy directory continues to be
/srv/www/shortname.

Fixes #95
  • Loading branch information
nickmarden committed Aug 24, 2017
1 parent 7752706 commit 28cb797
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 1 deletion.
9 changes: 9 additions & 0 deletions docs/source/attributes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,15 @@ Global parameters apply to the whole application, and can be used by any section
- Sets the “deploy environment” for all the app-related (for example ``RAILS_ENV``
in Rails) actions in the project (server, worker, etc.)

- ``app['global']['deploy_dir']``

- **Type:** string
- **Default:** ``/srv/www/app_name``
- Determines where the application will be deployed.
- Note that if you override this setting, you'll typically want to include the short_name
in the setting. In other words, this setting doesn't override the ``/srv/www`` base
directory defafult; it overrides the application-specific ``/srv/www/app_name`` default.

- ``app['global']['symlinks']``

- **Type:** key-value
Expand Down
2 changes: 1 addition & 1 deletion libraries/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def create_deploy_dir(application, subdir = '/')
end

def deploy_dir(application)
File.join('/', 'srv', 'www', application['shortname'])
globals('deploy_dir', application['shortname']) || ::File.join('/', 'srv', 'www', application['shortname'])
end

def every_enabled_application
Expand Down
52 changes: 52 additions & 0 deletions spec/unit/recipes/deploy_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -228,4 +228,56 @@
expect(chef_run).to deploy_deploy('a1')
expect(chef_run).not_to deploy_deploy('a2')
end

describe 'per-application deploy_dir' do
before do
stub_search(:aws_opsworks_app, '*:*').and_return([
aws_opsworks_app.merge(shortname: 'a1', deploy: true)
])
end

let(:chef_run) do
ChefSpec::SoloRunner.new(platform: 'ubuntu', version: '14.04') do |solo_node|
solo_node.set['lsb'] = node['lsb']
solo_node.set['deploy'] = { 'a1' => {} }
if deploy_dir
solo_node.set['deploy']['a1']['global']['deploy_dir'] = deploy_dir
end
end.converge(described_recipe)
end

context 'when deploy_dir is not specified' do
let(:deploy_dir) { nil }

it 'deploys a1 using the default deploy directory of /srv/www' do
expect(chef_run).to create_directory('/srv/www/a1/shared')
expect(chef_run).to create_directory('/srv/www/a1/shared/config')
expect(chef_run).to create_directory('/srv/www/a1/shared/log')
expect(chef_run).to create_directory('/srv/www/a1/shared/pids')
expect(chef_run).to create_directory('/srv/www/a1/shared/scripts')
expect(chef_run).to create_directory('/srv/www/a1/shared/sockets')
expect(chef_run).to create_directory('/srv/www/a1/shared/vendor/bundle')
expect(chef_run).to create_template('/srv/www/a1/shared/config/database.yml')
expect(chef_run).to create_template('/srv/www/a1/shared/config/puma.rb')
expect(chef_run).to create_template('/srv/www/a1/shared/scripts/puma.service')
end
end

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

it 'deploys a1 using the provided deploy directory instead' do
expect(chef_run).to create_directory('/some/other/path/to/a1/shared')
expect(chef_run).to create_directory('/some/other/path/to/a1/shared/config')
expect(chef_run).to create_directory('/some/other/path/to/a1/shared/log')
expect(chef_run).to create_directory('/some/other/path/to/a1/shared/pids')
expect(chef_run).to create_directory('/some/other/path/to/a1/shared/scripts')
expect(chef_run).to create_directory('/some/other/path/to/a1/shared/sockets')
expect(chef_run).to create_directory('/some/other/path/to/a1/shared/vendor/bundle')
expect(chef_run).to create_template('/some/other/path/to/a1/shared/config/database.yml')
expect(chef_run).to create_template('/some/other/path/to/a1/shared/config/puma.rb')
expect(chef_run).to create_template('/some/other/path/to/a1/shared/scripts/puma.service')
end
end
end
end

0 comments on commit 28cb797

Please sign in to comment.