mirror of
https://github.com/capistrano/capistrano
synced 2023-03-27 23:21:18 -04:00
Allow configuration location to be configurable
This change allows both the `deploy_config_path` and `stage_config_path` to be moved from the default locations of `config/deploy.rb` and `config/deploy` respectively. These values __must__ be set in the `Capfile` prior to `capistrano/setup` being called, for example: set :deploy_config_path, 'app/config/deploy.rb' set :stage_config_path, 'app/config/deploy' # Load DSL and Setup Up Stages require 'capistrano/setup' Fixes #610
This commit is contained in:
parent
1c767c541e
commit
d8b9b695bb
10 changed files with 125 additions and 16 deletions
15
features/configuration.feature
Normal file
15
features/configuration.feature
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
Feature: The path to the configuration can be changed, removing the need to
|
||||||
|
follow Ruby/Rails conventions
|
||||||
|
|
||||||
|
Background:
|
||||||
|
Given a test app with the default configuration
|
||||||
|
And servers with the roles app and web
|
||||||
|
|
||||||
|
Scenario: Deploying with configuration in default location
|
||||||
|
When I run "cap test"
|
||||||
|
Then the task is successful
|
||||||
|
|
||||||
|
Scenario: Deploying with configuration in a custom location
|
||||||
|
But the configuration is in a custom location
|
||||||
|
When I run "cap test"
|
||||||
|
Then the task is successful
|
|
@ -88,3 +88,7 @@ end
|
||||||
Then(/^it will not recreate the file$/) do
|
Then(/^it will not recreate the file$/) do
|
||||||
#
|
#
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Then(/^the task is successful$/) do
|
||||||
|
expect(@success).to be_true
|
||||||
|
end
|
||||||
|
|
|
@ -1,8 +1,12 @@
|
||||||
When(/^I run cap "(.*?)"$/) do |task|
|
When(/^I run cap "(.*?)"$/) do |task|
|
||||||
TestApp.cap(task)
|
@success = TestApp.cap(task)
|
||||||
end
|
end
|
||||||
|
|
||||||
When(/^I run cap "(.*?)" as part of a release$/) do |task|
|
When(/^I run cap "(.*?)" as part of a release$/) do |task|
|
||||||
TestApp.cap("deploy:new_release_path #{task}")
|
TestApp.cap("deploy:new_release_path #{task}")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
When(/^I run "(.*?)"$/) do |command|
|
||||||
|
@success = TestApp.run(command)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
|
@ -23,3 +23,6 @@ Given(/^a custom task to generate a file$/) do
|
||||||
TestApp.copy_task_to_test_app('spec/support/tasks/database.cap')
|
TestApp.copy_task_to_test_app('spec/support/tasks/database.cap')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Given(/^the configuration is in a custom location$/) do
|
||||||
|
TestApp.move_configuration_to_custom_location('app')
|
||||||
|
end
|
||||||
|
|
|
@ -27,6 +27,14 @@ module Capistrano
|
||||||
set(:release_path, releases_path.join(timestamp))
|
set(:release_path, releases_path.join(timestamp))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def stage_config_path
|
||||||
|
Pathname.new fetch(:stage_config_path, 'config/deploy')
|
||||||
|
end
|
||||||
|
|
||||||
|
def deploy_config_path
|
||||||
|
Pathname.new fetch(:deploy_config_path, 'config/deploy.rb')
|
||||||
|
end
|
||||||
|
|
||||||
def repo_url
|
def repo_url
|
||||||
require 'cgi'
|
require 'cgi'
|
||||||
require 'uri'
|
require 'uri'
|
||||||
|
|
|
@ -3,7 +3,14 @@ module Capistrano
|
||||||
module Stages
|
module Stages
|
||||||
|
|
||||||
def stages
|
def stages
|
||||||
Dir['config/deploy/*.rb'].map { |f| File.basename(f, '.rb') }
|
Dir[stage_definitions].map { |f| File.basename(f, '.rb') }
|
||||||
|
end
|
||||||
|
|
||||||
|
def infer_stages_from_stage_files
|
||||||
|
end
|
||||||
|
|
||||||
|
def stage_definitions
|
||||||
|
stage_config_path.join('*.rb')
|
||||||
end
|
end
|
||||||
|
|
||||||
def stage_set?
|
def stage_set?
|
||||||
|
|
|
@ -9,8 +9,8 @@ end
|
||||||
stages.each do |stage|
|
stages.each do |stage|
|
||||||
Rake::Task.define_task(stage) do
|
Rake::Task.define_task(stage) do
|
||||||
invoke 'load:defaults'
|
invoke 'load:defaults'
|
||||||
load 'config/deploy.rb'
|
load deploy_config_path
|
||||||
load "config/deploy/#{stage}.rb"
|
load stage_config_path.join("#{stage}.rb")
|
||||||
load "capistrano/#{fetch(:scm)}.rb"
|
load "capistrano/#{fetch(:scm)}.rb"
|
||||||
set(:stage, stage.to_sym)
|
set(:stage, stage.to_sym)
|
||||||
I18n.locale = fetch(:locale, :en)
|
I18n.locale = fetch(:locale, :en)
|
||||||
|
|
|
@ -340,5 +340,53 @@ describe Capistrano::DSL do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe 'setting deploy configuration path' do
|
||||||
|
subject { dsl.deploy_config_path.to_s }
|
||||||
|
|
||||||
|
context 'where no config path is set' do
|
||||||
|
before do
|
||||||
|
dsl.delete(:deploy_config_path)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'returns "config/deploy.rb"' do
|
||||||
|
expect(subject).to eq 'config/deploy.rb'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'where a custom path is set' do
|
||||||
|
before do
|
||||||
|
dsl.set(:deploy_config_path, 'my/custom/path.rb')
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'returns the custom path' do
|
||||||
|
expect(subject).to eq 'my/custom/path.rb'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe 'setting stage configuration path' do
|
||||||
|
subject { dsl.stage_config_path.to_s }
|
||||||
|
|
||||||
|
context 'where no config path is set' do
|
||||||
|
|
||||||
|
before do
|
||||||
|
dsl.delete(:stage_config_path)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'returns "config/deploy"' do
|
||||||
|
expect(subject).to eq 'config/deploy'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'where a custom path is set' do
|
||||||
|
before do
|
||||||
|
dsl.set(:stage_config_path, 'my/custom/path')
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'returns the custom path' do
|
||||||
|
expect(subject).to eq 'my/custom/path'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -20,17 +20,6 @@ module Capistrano
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#stages' do
|
|
||||||
before do
|
|
||||||
Dir.expects(:[]).with('config/deploy/*.rb').
|
|
||||||
returns(['config/deploy/staging.rb', 'config/deploy/production.rb'])
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'returns a list of defined stages' do
|
|
||||||
expect(dsl.stages).to eq %w{staging production}
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
describe '#stage_set?' do
|
describe '#stage_set?' do
|
||||||
subject { dsl.stage_set? }
|
subject { dsl.stage_set? }
|
||||||
|
|
||||||
|
|
|
@ -58,6 +58,14 @@ module TestApp
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def prepend_to_capfile(config)
|
||||||
|
current_capfile = File.read(capfile)
|
||||||
|
File.open(capfile, 'w') do |file|
|
||||||
|
file.write config
|
||||||
|
file.write current_capfile
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def create_shared_directory(path)
|
def create_shared_directory(path)
|
||||||
FileUtils.mkdir_p(shared_path.join(path))
|
FileUtils.mkdir_p(shared_path.join(path))
|
||||||
end
|
end
|
||||||
|
@ -67,9 +75,14 @@ module TestApp
|
||||||
end
|
end
|
||||||
|
|
||||||
def cap(task)
|
def cap(task)
|
||||||
|
run "bundle exec cap #{stage} #{task}"
|
||||||
|
end
|
||||||
|
|
||||||
|
def run(command)
|
||||||
Dir.chdir(test_app_path) do
|
Dir.chdir(test_app_path) do
|
||||||
%x[bundle exec cap #{stage} #{task}]
|
%x[#{command}]
|
||||||
end
|
end
|
||||||
|
$?.success?
|
||||||
end
|
end
|
||||||
|
|
||||||
def stage
|
def stage
|
||||||
|
@ -135,4 +148,22 @@ module TestApp
|
||||||
def copy_task_to_test_app(source)
|
def copy_task_to_test_app(source)
|
||||||
FileUtils.cp(source, task_dir)
|
FileUtils.cp(source, task_dir)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def config_path
|
||||||
|
test_app_path.join('config')
|
||||||
|
end
|
||||||
|
|
||||||
|
def move_configuration_to_custom_location(location)
|
||||||
|
prepend_to_capfile(
|
||||||
|
%{
|
||||||
|
set :stage_config_path, "app/config/deploy"
|
||||||
|
set :deploy_config_path, "app/config/deploy.rb"
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
location = test_app_path.join(location)
|
||||||
|
FileUtils.mkdir_p(location)
|
||||||
|
FileUtils.mv(config_path, location)
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue