pulsar 0.3.5 → 1.0.0.pre
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.rspec +1 -0
- data/.rubocop.yml +150 -0
- data/.ruby-version +1 -1
- data/LICENSE.txt +1 -1
- data/README.md +4 -265
- data/bin/pulsar +1 -1
- data/circle.yml +22 -0
- data/lib/pulsar.rb +28 -7
- data/lib/pulsar/cli.rb +79 -0
- data/lib/pulsar/constants.rb +5 -0
- data/lib/pulsar/generators/initial_repo/Gemfile +3 -0
- data/lib/pulsar/generators/{init_repo → initial_repo}/README.md +1 -1
- data/lib/pulsar/generators/initial_repo/apps/Capfile +8 -0
- data/lib/pulsar/generators/initial_repo/apps/deploy.rb +35 -0
- data/lib/pulsar/generators/initial_repo/apps/your_app/Capfile +18 -0
- data/lib/pulsar/generators/initial_repo/apps/your_app/deploy.rb +4 -0
- data/lib/pulsar/generators/initial_repo/apps/your_app/production.rb +3 -0
- data/lib/pulsar/generators/initial_repo/apps/your_app/staging.rb +3 -0
- data/lib/pulsar/generators/initial_repo/recipes/generic/rake.rake +12 -0
- data/lib/pulsar/generators/{init_repo/apps/your_app/recipes/production → initial_repo/recipes/rails}/.gitkeep +0 -0
- data/lib/pulsar/interactors/add_applications.rb +48 -0
- data/lib/pulsar/interactors/cleanup.rb +9 -0
- data/lib/pulsar/interactors/clone_repository.rb +50 -0
- data/lib/pulsar/interactors/copy_environment_file.rb +30 -0
- data/lib/pulsar/interactors/copy_initial_repository.rb +22 -0
- data/lib/pulsar/interactors/create_capfile.rb +32 -0
- data/lib/pulsar/interactors/create_deploy_file.rb +32 -0
- data/lib/pulsar/interactors/create_run_dirs.rb +21 -0
- data/lib/pulsar/interactors/identify_repository_location.rb +23 -0
- data/lib/pulsar/interactors/identify_repository_type.rb +34 -0
- data/lib/pulsar/interactors/run_bundle_install.rb +28 -0
- data/lib/pulsar/interactors/run_capistrano.rb +30 -0
- data/lib/pulsar/organizers/deploy.rb +16 -0
- data/lib/pulsar/organizers/install.rb +7 -0
- data/lib/pulsar/organizers/list.rb +12 -0
- data/lib/pulsar/version.rb +1 -1
- data/pulsar.gemspec +13 -11
- data/spec/features/deploy_spec.rb +162 -0
- data/spec/features/install_spec.rb +66 -0
- data/spec/features/list_spec.rb +140 -0
- data/spec/spec_helper.rb +26 -14
- data/{lib/pulsar/generators/init_repo/apps/your_app/recipes/staging → spec/support/dummies}/.gitkeep +0 -0
- data/spec/support/dummies/conf/dir/Gemfile +3 -0
- data/spec/support/dummies/conf/dir/apps/Capfile +9 -0
- data/spec/support/dummies/conf/dir/apps/blog/Capfile +1 -0
- data/spec/support/dummies/conf/dir/apps/blog/deploy.rb +4 -0
- data/spec/support/dummies/conf/dir/apps/blog/production.rb +4 -0
- data/spec/support/dummies/conf/dir/apps/blog/staging.rb +4 -0
- data/spec/support/dummies/conf/dir/apps/deploy.rb +1 -0
- data/{lib/pulsar/generators/init_repo/recipes/rails/.gitkeep → spec/support/dummies/conf/dir/apps/ecommerce/staging.rb} +0 -0
- data/spec/support/dummies/conf/dir/recipes/.gitkeep +0 -0
- data/spec/support/dummies/conf/dotenv +1 -0
- data/spec/support/dummies/conf/empty/apps/.gitkeep +0 -0
- data/spec/support/dummies/conf/empty/recipes/.gitkeep +0 -0
- data/spec/support/dummies/conf/wrong_bundle/Gemfile +3 -0
- data/spec/support/dummies/conf/wrong_bundle/apps/Capfile +9 -0
- data/spec/support/dummies/conf/wrong_bundle/apps/blog/Capfile +1 -0
- data/spec/support/dummies/conf/wrong_bundle/apps/blog/deploy.rb +4 -0
- data/spec/support/dummies/conf/wrong_bundle/apps/blog/production.rb +4 -0
- data/spec/support/dummies/conf/wrong_bundle/apps/deploy.rb +1 -0
- data/spec/support/dummies/conf/wrong_bundle/recipes/.gitkeep +0 -0
- data/spec/support/dummies/conf/wrong_cap/Gemfile +3 -0
- data/spec/support/dummies/conf/wrong_cap/apps/Capfile +0 -0
- data/spec/support/dummies/conf/wrong_cap/apps/blog/deploy.rb +4 -0
- data/spec/support/dummies/conf/wrong_cap/apps/blog/production.rb +4 -0
- data/spec/support/dummies/conf/wrong_cap/apps/deploy.rb +1 -0
- data/spec/support/dummies/conf/wrong_cap/recipes/.gitkeep +0 -0
- data/spec/units/cli/deploy_spec.rb +116 -0
- data/spec/units/cli/install_spec.rb +44 -0
- data/spec/units/cli/list_spec.rb +107 -0
- data/spec/units/constants_spec.rb +21 -0
- data/spec/units/interactors/add_applications_spec.rb +46 -0
- data/spec/units/interactors/cleanup_spec.rb +21 -0
- data/spec/units/interactors/clone_initial_repository_spec.rb +41 -0
- data/spec/units/interactors/clone_repository_spec.rb +122 -0
- data/spec/units/interactors/copy_environment_file_spec.rb +80 -0
- data/spec/units/interactors/create_capfile_spec.rb +77 -0
- data/spec/units/interactors/create_deploy_file_spec.rb +70 -0
- data/spec/units/interactors/create_run_dirs_spec.rb +47 -0
- data/spec/units/interactors/identify_repository_location_spec.rb +49 -0
- data/spec/units/interactors/identify_repository_type_spec.rb +85 -0
- data/spec/units/interactors/run_bundle_install_spec.rb +60 -0
- data/spec/units/interactors/run_capistrano_spec.rb +92 -0
- data/spec/units/organizers/deploy_spec.rb +28 -0
- data/spec/units/organizers/install_spec.rb +13 -0
- data/spec/units/organizers/list_spec.rb +24 -0
- metadata +179 -106
- data/.ruby-gemset +0 -1
- data/.travis.yml +0 -17
- data/bin/pulsar-utils +0 -5
- data/lib/pulsar/commands/all.rb +0 -6
- data/lib/pulsar/commands/init.rb +0 -23
- data/lib/pulsar/commands/list.rb +0 -19
- data/lib/pulsar/commands/main.rb +0 -64
- data/lib/pulsar/commands/utils.rb +0 -14
- data/lib/pulsar/generators/init_repo/Gemfile +0 -7
- data/lib/pulsar/generators/init_repo/apps/base.rb +0 -41
- data/lib/pulsar/generators/init_repo/apps/your_app/defaults.rb +0 -9
- data/lib/pulsar/generators/init_repo/apps/your_app/production.rb +0 -12
- data/lib/pulsar/generators/init_repo/apps/your_app/recipes/custom_recipe.rb +0 -14
- data/lib/pulsar/generators/init_repo/apps/your_app/staging.rb +0 -12
- data/lib/pulsar/generators/init_repo/recipes/generic/cleanup.rb +0 -50
- data/lib/pulsar/generators/init_repo/recipes/generic/utils.rb +0 -9
- data/lib/pulsar/helpers/all.rb +0 -8
- data/lib/pulsar/helpers/capistrano.rb +0 -47
- data/lib/pulsar/helpers/clamp.rb +0 -223
- data/lib/pulsar/helpers/path.rb +0 -71
- data/lib/pulsar/helpers/shell.rb +0 -31
- data/lib/pulsar/options/all.rb +0 -6
- data/lib/pulsar/options/conf_repo.rb +0 -41
- data/lib/pulsar/options/shared.rb +0 -15
- data/spec/pulsar/commands/init_spec.rb +0 -10
- data/spec/pulsar/commands/list_spec.rb +0 -127
- data/spec/pulsar/commands/main_spec.rb +0 -360
- data/spec/pulsar/commands/utils_spec.rb +0 -33
- data/spec/pulsar/helpers/capistrano_spec.rb +0 -70
- data/spec/pulsar/helpers/clamp_spec.rb +0 -105
- data/spec/pulsar/helpers/shell_spec.rb +0 -11
- data/spec/support/dummies/dummy_app/config.ru +0 -3
- data/spec/support/dummies/dummy_conf/Gemfile +0 -4
- data/spec/support/dummies/dummy_conf/apps/base.rb +0 -46
- data/spec/support/dummies/dummy_conf/apps/dummy_app/custom_stage.rb +0 -5
- data/spec/support/dummies/dummy_conf/apps/dummy_app/defaults.rb +0 -7
- data/spec/support/dummies/dummy_conf/apps/dummy_app/production.rb +0 -5
- data/spec/support/dummies/dummy_conf/apps/dummy_app/recipes/custom_recipe.rb +0 -1
- data/spec/support/dummies/dummy_conf/apps/dummy_app/recipes/production/custom_recipe.rb +0 -1
- data/spec/support/dummies/dummy_conf/apps/dummy_app/recipes/staging/custom_recipe.rb +0 -1
- data/spec/support/dummies/dummy_conf/apps/dummy_app/staging.rb +0 -5
- data/spec/support/dummies/dummy_conf/apps/other_dummy_app/custom_stage.rb +0 -5
- data/spec/support/dummies/dummy_conf/apps/other_dummy_app/defaults.rb +0 -7
- data/spec/support/dummies/dummy_conf/apps/other_dummy_app/production.rb +0 -5
- data/spec/support/dummies/dummy_conf/apps/other_dummy_app/staging.rb +0 -5
- data/spec/support/dummies/dummy_conf/recipes/generic/recipe.rb +0 -3
- data/spec/support/modules/helpers.rb +0 -85
- data/spec/support/modules/output_capture.rb +0 -21
data/lib/pulsar/helpers/path.rb
DELETED
@@ -1,71 +0,0 @@
|
|
1
|
-
module Pulsar
|
2
|
-
module Helpers
|
3
|
-
module Path
|
4
|
-
def capfile_path
|
5
|
-
"#{tmp_path}/capfile-#{deploy_time}"
|
6
|
-
end
|
7
|
-
|
8
|
-
def config_path
|
9
|
-
"#{tmp_path}/conf-repo-#{setup_time}"
|
10
|
-
end
|
11
|
-
|
12
|
-
def config_app_path(app)
|
13
|
-
"#{config_apps_path}/#{app}"
|
14
|
-
end
|
15
|
-
|
16
|
-
def config_app_defaults_path(app)
|
17
|
-
"#{config_app_path(app)}/defaults.rb"
|
18
|
-
end
|
19
|
-
|
20
|
-
def config_app_recipes_path(app)
|
21
|
-
"#{config_app_path(app)}/recipes"
|
22
|
-
end
|
23
|
-
|
24
|
-
def config_app_stage_recipes_path(app, stage)
|
25
|
-
"#{config_app_recipes_path(app)}/#{stage}"
|
26
|
-
end
|
27
|
-
|
28
|
-
def config_apps_path
|
29
|
-
"#{config_path}/apps"
|
30
|
-
end
|
31
|
-
|
32
|
-
def config_base_path
|
33
|
-
"#{config_apps_path}/base.rb"
|
34
|
-
end
|
35
|
-
|
36
|
-
def config_stage_path(app, stage)
|
37
|
-
"#{config_app_path(app)}/#{stage}.rb"
|
38
|
-
end
|
39
|
-
|
40
|
-
def reset_capfile_path!
|
41
|
-
clear_deploy_time
|
42
|
-
end
|
43
|
-
|
44
|
-
def home_path
|
45
|
-
home_dir
|
46
|
-
end
|
47
|
-
|
48
|
-
def bundle_path
|
49
|
-
File.join(home_path, 'bundle')
|
50
|
-
end
|
51
|
-
|
52
|
-
def tmp_path
|
53
|
-
File.join(home_path, 'tmp')
|
54
|
-
end
|
55
|
-
|
56
|
-
private
|
57
|
-
|
58
|
-
def clear_deploy_time
|
59
|
-
@deploy = nil
|
60
|
-
end
|
61
|
-
|
62
|
-
def deploy_time
|
63
|
-
@deploy ||= Time.now.strftime("%Y-%m-%d-%H%M%S-s#{rand(9999)}")
|
64
|
-
end
|
65
|
-
|
66
|
-
def setup_time
|
67
|
-
@setup ||= Time.now.strftime("%Y-%m-%d-%H%M%S-s#{rand(9999)}")
|
68
|
-
end
|
69
|
-
end
|
70
|
-
end
|
71
|
-
end
|
data/lib/pulsar/helpers/shell.rb
DELETED
@@ -1,31 +0,0 @@
|
|
1
|
-
require 'fileutils'
|
2
|
-
|
3
|
-
module Pulsar
|
4
|
-
module Helpers
|
5
|
-
module Shell
|
6
|
-
include FileUtils
|
7
|
-
|
8
|
-
def cd(path, opts)
|
9
|
-
puts "Directory: #{path.white}".yellow if opts[:verbose]
|
10
|
-
FileUtils.cd(path) { yield }
|
11
|
-
end
|
12
|
-
|
13
|
-
def rm_rf(path, opts)
|
14
|
-
puts "Remove: #{path.white}".yellow if opts[:verbose]
|
15
|
-
FileUtils.rm_rf(path)
|
16
|
-
end
|
17
|
-
|
18
|
-
def run_cmd(cmd, opts)
|
19
|
-
puts "Command: #{cmd.white}".yellow if opts[:verbose]
|
20
|
-
system(cmd)
|
21
|
-
|
22
|
-
fail "Command #{cmd} Failed" if $? != 0
|
23
|
-
end
|
24
|
-
|
25
|
-
def touch(file, opts)
|
26
|
-
puts "Touch: #{file.white}".yellow if opts[:verbose]
|
27
|
-
FileUtils.touch(file)
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
data/lib/pulsar/options/all.rb
DELETED
@@ -1,41 +0,0 @@
|
|
1
|
-
module Pulsar
|
2
|
-
module Options
|
3
|
-
module ConfRepo
|
4
|
-
def self.included(base)
|
5
|
-
base.option ['-c', '--conf-repo'], 'REPO URL',
|
6
|
-
'a git repository with deploy configurations, mainly apps and recipes',
|
7
|
-
environment_variable: 'PULSAR_CONF_REPO',
|
8
|
-
required: true
|
9
|
-
|
10
|
-
base.option ['-k', '--keep-capfile'], :flag,
|
11
|
-
'don\'t remove the generated capfile in the TMP DIR directory',
|
12
|
-
default: false
|
13
|
-
|
14
|
-
base.option ['-r', '--keep-repo'], :flag,
|
15
|
-
'don\'t remove the downloaded configuration repository from the TMP DIR directory',
|
16
|
-
default: false
|
17
|
-
|
18
|
-
base.option ['-b', '--conf-branch'], 'REPO BRANCH',
|
19
|
-
'specify a branch for the configuration repository',
|
20
|
-
default: 'master'
|
21
|
-
|
22
|
-
base.option ['-h', '--home-dir'], 'HOME DIR',
|
23
|
-
'a directory to store per-user state',
|
24
|
-
environment_variable: 'PULSAR_HOME',
|
25
|
-
default: File.join(Dir.home, '.pulsar')
|
26
|
-
end
|
27
|
-
|
28
|
-
#
|
29
|
-
# TODO: find a way to fix this hack. This is made so that
|
30
|
-
# load_configuration() is called before Clamp parses command
|
31
|
-
# line arguments (and runs into errors because no conf repo
|
32
|
-
# is defined).
|
33
|
-
#
|
34
|
-
def parse(arguments)
|
35
|
-
self.class.send(:include, Pulsar::Helpers::Clamp)
|
36
|
-
load_configuration
|
37
|
-
super
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
@@ -1,15 +0,0 @@
|
|
1
|
-
module Pulsar
|
2
|
-
module Options
|
3
|
-
module Shared
|
4
|
-
def self.included(base)
|
5
|
-
base.option ['-V', '--version'], :flag, 'print out pulsar version' do
|
6
|
-
puts(VERSION)
|
7
|
-
exit(0)
|
8
|
-
end
|
9
|
-
|
10
|
-
base.option ['-v', '--verbose'], :flag,
|
11
|
-
'print out what pulsar is doing', default: false
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
@@ -1,10 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Pulsar::InitCommand do
|
4
|
-
let(:pulsar) { Pulsar::InitCommand.new('init') }
|
5
|
-
|
6
|
-
it 'copies over the configuration repo' do
|
7
|
-
expect { pulsar.run(["#{spec_tmp_path}/new-conf-repo"]) }
|
8
|
-
.to change { Dir.glob("#{spec_tmp_path}/new-conf-repo").length }.by(1)
|
9
|
-
end
|
10
|
-
end
|
@@ -1,127 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Pulsar::ListCommand do
|
4
|
-
let(:pulsar) { Pulsar::ListCommand.new('list') }
|
5
|
-
|
6
|
-
it 'copies a the repo over to temp directory' do
|
7
|
-
expect { pulsar.run(full_list_args + %w(--keep-repo)) }
|
8
|
-
.to change { Dir.glob("#{spec_tmp_path}/tmp/conf-repo*").length }.by(1)
|
9
|
-
end
|
10
|
-
|
11
|
-
it 'copies a the repo when there is a dir with same name' do
|
12
|
-
system("mkdir -p #{spec_tmp_path}/conf-repo")
|
13
|
-
|
14
|
-
expect { pulsar.run(full_list_args + %w(--keep-repo)) }
|
15
|
-
.to change { Dir.glob("#{spec_tmp_path}/tmp/conf-repo*").length }.by(1)
|
16
|
-
end
|
17
|
-
|
18
|
-
it 'removes the temp directory even if it\'s raised an error' do
|
19
|
-
allow_any_instance_of(Pulsar::ListCommand)
|
20
|
-
.to receive(:list_apps) { fail('error') }
|
21
|
-
|
22
|
-
begin
|
23
|
-
pulsar.run(full_list_args)
|
24
|
-
rescue
|
25
|
-
nil
|
26
|
-
end
|
27
|
-
|
28
|
-
expect(Dir.glob("#{spec_tmp_path}/tmp/conf-repo*")).to be_empty
|
29
|
-
end
|
30
|
-
|
31
|
-
it 'lists configured apps and stages' do
|
32
|
-
app_one = Regexp.escape('dummy_app'.cyan)
|
33
|
-
app_two = Regexp.escape('other_dummy_app'.cyan)
|
34
|
-
|
35
|
-
stages = ['custom_stage'.magenta, 'production'.magenta, 'staging'.magenta]
|
36
|
-
escaped_stages = Regexp.escape(stages.join(', '))
|
37
|
-
|
38
|
-
pulsar.run(full_list_args)
|
39
|
-
|
40
|
-
expect(stdout).to match(/#{app_one}: #{escaped_stages}/)
|
41
|
-
expect(stdout).to match(/#{app_two}: #{escaped_stages}/)
|
42
|
-
end
|
43
|
-
|
44
|
-
context 'dotfile options' do
|
45
|
-
it 'reads configuration variables from config file in home' do
|
46
|
-
stub_config(File.join(pulsar.home_path, 'config'), dummy_dotfile_options)
|
47
|
-
|
48
|
-
pulsar.run(full_list_args)
|
49
|
-
|
50
|
-
expect(ENV.to_hash).to include(dummy_dotfile_options)
|
51
|
-
end
|
52
|
-
|
53
|
-
it 'reads configurations from .pulsar file in rack app directory' do
|
54
|
-
stub_config(File.join(dummy_app_path, '.pulsar'), dummy_dotfile_options)
|
55
|
-
|
56
|
-
FileUtils.cd(dummy_app_path) do
|
57
|
-
reload_main_command
|
58
|
-
|
59
|
-
pulsar.run(full_list_args)
|
60
|
-
end
|
61
|
-
|
62
|
-
expect(ENV.to_hash).to include(dummy_dotfile_options)
|
63
|
-
end
|
64
|
-
|
65
|
-
it 'skips lines which cannot parse when reading .pulsar file' do
|
66
|
-
stub_config(
|
67
|
-
File.join(dummy_app_path, '.pulsar'), ['wrong_line', '# comment'])
|
68
|
-
|
69
|
-
FileUtils.cd(dummy_app_path) do
|
70
|
-
reload_main_command
|
71
|
-
|
72
|
-
expect { pulsar.run(full_list_args) }.not_to raise_error
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
it 'falls back to default config file if it\'s not in the app directory' do
|
77
|
-
stub_config(File.join(pulsar.home_path, 'config'), dummy_dotfile_options)
|
78
|
-
|
79
|
-
allow(File)
|
80
|
-
.to receive(:file?)
|
81
|
-
.with("#{File.expand_path(dummy_app_path)}/.pulsar").and_return(false)
|
82
|
-
|
83
|
-
FileUtils.cd(dummy_app_path) do
|
84
|
-
reload_main_command
|
85
|
-
|
86
|
-
pulsar.run(full_list_args)
|
87
|
-
end
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
|
-
context '--conf-repo option' do
|
92
|
-
it 'is required' do
|
93
|
-
expect { pulsar.parse([]) }.to raise_error(Clamp::UsageError)
|
94
|
-
end
|
95
|
-
|
96
|
-
it 'supports environment variable' do
|
97
|
-
ENV['PULSAR_CONF_REPO'] = dummy_conf_path
|
98
|
-
expect { pulsar.parse([]) }.not_to raise_error
|
99
|
-
end
|
100
|
-
|
101
|
-
it 'supports directories' do
|
102
|
-
expect { pulsar.run(full_list_args) }.not_to raise_error
|
103
|
-
end
|
104
|
-
end
|
105
|
-
|
106
|
-
context '--home-dir option' do
|
107
|
-
it 'is supported' do
|
108
|
-
expect { pulsar.parse(base_args + %w(--home-dir dummy_tmp)) }
|
109
|
-
.not_to raise_error
|
110
|
-
end
|
111
|
-
|
112
|
-
it 'creates the tmp directory if it doesn\'t exist' do
|
113
|
-
Dir.mktmpdir do |dir|
|
114
|
-
run_options = base_args + ['--home-dir', dir]
|
115
|
-
|
116
|
-
expect { pulsar.run(run_options) }.not_to raise_error
|
117
|
-
expect(File.directory?(pulsar.tmp_path)).to be(true)
|
118
|
-
end
|
119
|
-
end
|
120
|
-
end
|
121
|
-
|
122
|
-
context '--keep-capfile option' do
|
123
|
-
it 'is supported' do
|
124
|
-
expect { pulsar.parse(base_args + %w(--keep-capfile)) }.not_to raise_error
|
125
|
-
end
|
126
|
-
end
|
127
|
-
end
|
@@ -1,360 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Pulsar::MainCommand do
|
4
|
-
let(:pulsar) { Pulsar::MainCommand.new('') }
|
5
|
-
|
6
|
-
before(:each) { reload_main_command }
|
7
|
-
|
8
|
-
it 'builds a Capfile file in tmp dir' do
|
9
|
-
expect { pulsar.run(full_cap_args + dummy_app) }
|
10
|
-
.to change { capfile_count }.by(1)
|
11
|
-
end
|
12
|
-
|
13
|
-
it 'copies a the repo over to temp directory' do
|
14
|
-
expect { pulsar.run(full_cap_args + %w(--keep-repo) + dummy_app) }
|
15
|
-
.to change { capfile_count }.by(1)
|
16
|
-
end
|
17
|
-
|
18
|
-
it 'removes the temp directory even if it\'s raised an error' do
|
19
|
-
allow_any_instance_of(Pulsar::MainCommand)
|
20
|
-
.to receive(:run_capistrano) { fail('error') }
|
21
|
-
|
22
|
-
begin
|
23
|
-
pulsar.run(
|
24
|
-
base_args + ['--home-dir', spec_tmp_path, '--keep-capfile'] + dummy_app)
|
25
|
-
rescue
|
26
|
-
nil
|
27
|
-
end
|
28
|
-
|
29
|
-
expect(Dir.glob("#{spec_tmp_path}/tmp/conf-repo*")).to be_empty
|
30
|
-
end
|
31
|
-
|
32
|
-
it 'copies a the repo when there is a dir with same name' do
|
33
|
-
system("mkdir -p #{spec_tmp_path}/tmp/conf-repo")
|
34
|
-
|
35
|
-
expect { pulsar.run(full_cap_args + %w(--keep-repo) + dummy_app) }
|
36
|
-
.to change { Dir.glob("#{spec_tmp_path}/tmp/conf-repo*").length }.by(1)
|
37
|
-
end
|
38
|
-
|
39
|
-
it 'uses dirname when inside a rack app directory' do
|
40
|
-
FileUtils.cd(dummy_app_path) do
|
41
|
-
reload_main_command
|
42
|
-
|
43
|
-
expect { pulsar.run(full_cap_args + %w(production)) }
|
44
|
-
.to change { capfile_count }.by(1)
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
context 'Multiple applications' do
|
49
|
-
let :stage do
|
50
|
-
'production'
|
51
|
-
end
|
52
|
-
|
53
|
-
let :comma_separated_list do
|
54
|
-
['dummy_app,other_dummy_app', stage]
|
55
|
-
end
|
56
|
-
|
57
|
-
let :pattern_list do
|
58
|
-
['dummy*', stage]
|
59
|
-
end
|
60
|
-
|
61
|
-
let :pattern_match_all do
|
62
|
-
['*', stage]
|
63
|
-
end
|
64
|
-
|
65
|
-
let :double_pattern do
|
66
|
-
['dummy*,*app', stage]
|
67
|
-
end
|
68
|
-
|
69
|
-
it 'supports multiple apps via comma separated argument' do
|
70
|
-
expect { pulsar.run(full_cap_args + comma_separated_list) }
|
71
|
-
.to change { capfile_count }.by(2)
|
72
|
-
end
|
73
|
-
|
74
|
-
it 'supports pattern matching on app names' do
|
75
|
-
expect { pulsar.run(full_cap_args + pattern_list) }
|
76
|
-
.to change { capfile_count }.by(1)
|
77
|
-
end
|
78
|
-
|
79
|
-
it 'matches all apps with *' do
|
80
|
-
expect { pulsar.run(full_cap_args + pattern_match_all) }
|
81
|
-
.to change { capfile_count }.by(2)
|
82
|
-
end
|
83
|
-
|
84
|
-
it 'matches application only once' do
|
85
|
-
expect { pulsar.run(full_cap_args + double_pattern) }
|
86
|
-
.to change { capfile_count }.by(2)
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
context 'dotfile options' do
|
91
|
-
it 'reads configuration variables from config file in home' do
|
92
|
-
stub_config(File.join(pulsar.home_path, 'config'), dummy_dotfile_options)
|
93
|
-
|
94
|
-
pulsar.run(full_cap_args + dummy_app)
|
95
|
-
|
96
|
-
expect(ENV.to_hash).to include(dummy_dotfile_options)
|
97
|
-
end
|
98
|
-
|
99
|
-
it 'reads configurations from .pulsar file in rack app directory' do
|
100
|
-
stub_config(File.join(dummy_app_path, '.pulsar'), dummy_dotfile_options)
|
101
|
-
|
102
|
-
FileUtils.cd(dummy_app_path) do
|
103
|
-
reload_main_command
|
104
|
-
|
105
|
-
pulsar.run(full_cap_args + %w(production))
|
106
|
-
end
|
107
|
-
|
108
|
-
expect(ENV.to_hash).to include(dummy_dotfile_options)
|
109
|
-
end
|
110
|
-
|
111
|
-
it 'skips lines which cannot parse when reading .pulsar file' do
|
112
|
-
stub_config(
|
113
|
-
File.join(dummy_app_path, '.pulsar'), ['wrong_line', '# comment'])
|
114
|
-
|
115
|
-
FileUtils.cd(dummy_app_path) do
|
116
|
-
reload_main_command
|
117
|
-
|
118
|
-
expect { pulsar.run(full_cap_args + %w(production)) }.not_to raise_error
|
119
|
-
end
|
120
|
-
end
|
121
|
-
|
122
|
-
it 'falls back to default config file if it\'s not in the app directory' do
|
123
|
-
stub_config(File.join(spec_tmp_path, 'config'), dummy_dotfile_options)
|
124
|
-
|
125
|
-
allow(File)
|
126
|
-
.to receive(:file?)
|
127
|
-
.with("#{File.expand_path(dummy_app_path)}/.pulsar").and_return(false)
|
128
|
-
|
129
|
-
FileUtils.cd(dummy_app_path) do
|
130
|
-
reload_main_command
|
131
|
-
|
132
|
-
expect { pulsar.run(full_cap_args + %w(production)) }.not_to raise_error
|
133
|
-
end
|
134
|
-
end
|
135
|
-
end
|
136
|
-
|
137
|
-
it 'errors out if application does not exist in configuration repository' do
|
138
|
-
expect { pulsar.run(full_cap_args + %w(non_existent_app production)) }
|
139
|
-
.to raise_error(ArgumentError)
|
140
|
-
end
|
141
|
-
|
142
|
-
it 'errors out if stage does not exist in configuration repository' do
|
143
|
-
expect { pulsar.run(full_cap_args + dummy_app(:non_existent_stage)) }
|
144
|
-
.to raise_error(ArgumentError)
|
145
|
-
end
|
146
|
-
|
147
|
-
context 'Capfile' do
|
148
|
-
it 'uses base.rb in staging stage' do
|
149
|
-
pulsar.run(full_cap_args + dummy_app(:staging))
|
150
|
-
|
151
|
-
expect(latest_capfile).to include('# This is apps/base.rb')
|
152
|
-
end
|
153
|
-
|
154
|
-
it 'uses base.rb in production stage' do
|
155
|
-
pulsar.run(full_cap_args + dummy_app)
|
156
|
-
|
157
|
-
expect(latest_capfile).to include('# This is apps/base.rb')
|
158
|
-
end
|
159
|
-
|
160
|
-
it 'uses defaults.rb in staging stage' do
|
161
|
-
pulsar.run(full_cap_args + dummy_app(:staging))
|
162
|
-
|
163
|
-
expect(latest_capfile).to include('# This is apps/dummy_app/defaults.rb')
|
164
|
-
end
|
165
|
-
|
166
|
-
it 'uses defaults.rb in production stage' do
|
167
|
-
pulsar.run(full_cap_args + dummy_app)
|
168
|
-
|
169
|
-
expect(latest_capfile).to include('# This is apps/dummy_app/defaults.rb')
|
170
|
-
end
|
171
|
-
|
172
|
-
it 'uses defaults.rb in staging stage only' do
|
173
|
-
pulsar.run(full_cap_args + dummy_app(:staging))
|
174
|
-
|
175
|
-
expect(latest_capfile)
|
176
|
-
.to include('# This is apps/dummy_app/staging.rb')
|
177
|
-
expect(latest_capfile)
|
178
|
-
.not_to include('# This is apps/dummy_app/production.rb')
|
179
|
-
end
|
180
|
-
|
181
|
-
it 'uses defaults.rb in production stage only' do
|
182
|
-
pulsar.run(full_cap_args + dummy_app)
|
183
|
-
|
184
|
-
expect(latest_capfile)
|
185
|
-
.to include('# This is apps/dummy_app/production.rb')
|
186
|
-
expect(latest_capfile)
|
187
|
-
.not_to include('# This is apps/dummy_app/staging.rb')
|
188
|
-
end
|
189
|
-
|
190
|
-
it 'uses custom recipes in staging stage' do
|
191
|
-
pulsar.run(full_cap_args + dummy_app(:staging))
|
192
|
-
|
193
|
-
expect(latest_capfile)
|
194
|
-
.to include('# This is apps/dummy_app/recipes/custom_recipe.rb')
|
195
|
-
end
|
196
|
-
|
197
|
-
it 'uses custom recipes in production stage' do
|
198
|
-
pulsar.run(full_cap_args + dummy_app)
|
199
|
-
|
200
|
-
expect(latest_capfile)
|
201
|
-
.to include('# This is apps/dummy_app/recipes/custom_recipe.rb')
|
202
|
-
end
|
203
|
-
|
204
|
-
it 'uses custom staging recipes in staging stage only' do
|
205
|
-
pulsar.run(full_cap_args + dummy_app(:staging))
|
206
|
-
|
207
|
-
expect(latest_capfile)
|
208
|
-
.to include('# This is apps/dummy_app/recipes/staging/custom_recipe.rb')
|
209
|
-
expect(latest_capfile)
|
210
|
-
.not_to include(
|
211
|
-
'# This is apps/dummy_app/recipes/production/custom_recipe.rb')
|
212
|
-
end
|
213
|
-
|
214
|
-
it 'uses custom production recipes in production stage only' do
|
215
|
-
pulsar.run(full_cap_args + dummy_app)
|
216
|
-
|
217
|
-
expect(latest_capfile)
|
218
|
-
.to include(
|
219
|
-
'# This is apps/dummy_app/recipes/production/custom_recipe.rb')
|
220
|
-
expect(latest_capfile)
|
221
|
-
.not_to include(
|
222
|
-
'# This is apps/dummy_app/recipes/staging/custom_recipe.rb')
|
223
|
-
end
|
224
|
-
|
225
|
-
it 'uses dirname from PULSAR_APP_NAME when inside a rack app directory' do
|
226
|
-
ENV['PULSAR_APP_NAME'] = 'other_dummy_app'
|
227
|
-
|
228
|
-
FileUtils.cd(dummy_app_path) do
|
229
|
-
reload_main_command
|
230
|
-
pulsar.run(full_cap_args + %w(production))
|
231
|
-
end
|
232
|
-
|
233
|
-
expect(latest_capfile)
|
234
|
-
.to include('# This is apps/other_dummy_app/defaults.rb')
|
235
|
-
expect(latest_capfile)
|
236
|
-
.to include('# This is apps/other_dummy_app/production.rb')
|
237
|
-
end
|
238
|
-
end
|
239
|
-
|
240
|
-
context '--version option' do
|
241
|
-
before do
|
242
|
-
begin
|
243
|
-
pulsar.parse(['--version'])
|
244
|
-
rescue SystemExit => e
|
245
|
-
@system_exit = e
|
246
|
-
end
|
247
|
-
end
|
248
|
-
|
249
|
-
it 'shows version' do
|
250
|
-
expect(stdout).to include(Pulsar::VERSION)
|
251
|
-
end
|
252
|
-
|
253
|
-
it 'exits with a zero status' do
|
254
|
-
expect(@system_exit).not_to be_nil
|
255
|
-
expect(@system_exit.status).to be 0
|
256
|
-
end
|
257
|
-
end
|
258
|
-
|
259
|
-
context '--conf-repo option' do
|
260
|
-
it 'is required' do
|
261
|
-
expect { pulsar.parse([]) }.to raise_error(Clamp::UsageError)
|
262
|
-
end
|
263
|
-
|
264
|
-
it 'supports environment variable' do
|
265
|
-
ENV['PULSAR_CONF_REPO'] = dummy_conf_path
|
266
|
-
expect { pulsar.parse(dummy_app) }.not_to raise_error
|
267
|
-
end
|
268
|
-
|
269
|
-
it 'supports directories' do
|
270
|
-
expect { pulsar.run(full_cap_args + dummy_app) }.not_to raise_error
|
271
|
-
end
|
272
|
-
end
|
273
|
-
|
274
|
-
context '--home-dir option' do
|
275
|
-
it 'is supported' do
|
276
|
-
expect { pulsar.parse(base_args + %w(--home-dir dummy_tmp) + dummy_app) }
|
277
|
-
.not_to raise_error
|
278
|
-
end
|
279
|
-
|
280
|
-
it 'creates the tmp directory if it doesn\'t exist' do
|
281
|
-
Dir.mktmpdir do |dir|
|
282
|
-
run_options = base_args +
|
283
|
-
['--home-dir', dir, '--skip-cap-run'] +
|
284
|
-
dummy_app
|
285
|
-
|
286
|
-
expect { pulsar.run(run_options) }.not_to raise_error
|
287
|
-
expect(File.directory?(pulsar.tmp_path)).to be(true)
|
288
|
-
end
|
289
|
-
end
|
290
|
-
end
|
291
|
-
|
292
|
-
context '--keep-capfile option' do
|
293
|
-
it 'is supported' do
|
294
|
-
expect { pulsar.parse(base_args + %w(--keep-capfile) + dummy_app) }
|
295
|
-
.not_to raise_error
|
296
|
-
end
|
297
|
-
end
|
298
|
-
|
299
|
-
context '--skip-cap-run option' do
|
300
|
-
it 'is supported' do
|
301
|
-
expect { pulsar.parse(base_args + %w(--skip-cap-run) + dummy_app) }
|
302
|
-
.not_to raise_error
|
303
|
-
end
|
304
|
-
end
|
305
|
-
|
306
|
-
context '--keep-repo option' do
|
307
|
-
it 'is supported' do
|
308
|
-
expect { pulsar.parse(base_args + %w(--keep-repo) + dummy_app) }
|
309
|
-
.not_to raise_error
|
310
|
-
end
|
311
|
-
end
|
312
|
-
|
313
|
-
context '--log-level option' do
|
314
|
-
it 'is supported' do
|
315
|
-
expect { pulsar.parse(base_args + %w(--log-level debug) + dummy_app) }
|
316
|
-
.not_to raise_error
|
317
|
-
end
|
318
|
-
|
319
|
-
it 'supports Capistrano IMPORTANT' do
|
320
|
-
pulsar.run(full_cap_args + %w(--log-level important) + dummy_app)
|
321
|
-
|
322
|
-
expect(latest_capfile).to include(
|
323
|
-
'logger.level = logger.level = Capistrano::Logger::IMPORTANT')
|
324
|
-
end
|
325
|
-
|
326
|
-
it 'supports Capistrano INFO' do
|
327
|
-
pulsar.run(full_cap_args + %w(--log-level info) + dummy_app)
|
328
|
-
|
329
|
-
expect(latest_capfile)
|
330
|
-
.to include('logger.level = logger.level = Capistrano::Logger::INFO')
|
331
|
-
end
|
332
|
-
|
333
|
-
it 'supports Capistrano DEBUG' do
|
334
|
-
pulsar.run(full_cap_args + %w(--log-level debug) + dummy_app)
|
335
|
-
|
336
|
-
expect(latest_capfile)
|
337
|
-
.to include('logger.level = logger.level = Capistrano::Logger::DEBUG')
|
338
|
-
end
|
339
|
-
|
340
|
-
it 'supports Capistrano TRACE' do
|
341
|
-
pulsar.run(full_cap_args + %w(--log-level trace) + dummy_app)
|
342
|
-
|
343
|
-
expect(latest_capfile)
|
344
|
-
.to include('logger.level = logger.level = Capistrano::Logger::TRACE')
|
345
|
-
end
|
346
|
-
end
|
347
|
-
|
348
|
-
context 'TASKS parameter' do
|
349
|
-
it 'defaults to deploy' do
|
350
|
-
expect(pulsar.tasks_list).to eq 'deploy'
|
351
|
-
end
|
352
|
-
|
353
|
-
it 'supports environment variable' do
|
354
|
-
ENV['PULSAR_DEFAULT_TASK'] = 'custom:task'
|
355
|
-
pulsar.run(full_cap_args + dummy_app)
|
356
|
-
|
357
|
-
expect(pulsar.tasks_list).to eq ['custom:task']
|
358
|
-
end
|
359
|
-
end
|
360
|
-
end
|