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.
Files changed (137) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.rspec +1 -0
  4. data/.rubocop.yml +150 -0
  5. data/.ruby-version +1 -1
  6. data/LICENSE.txt +1 -1
  7. data/README.md +4 -265
  8. data/bin/pulsar +1 -1
  9. data/circle.yml +22 -0
  10. data/lib/pulsar.rb +28 -7
  11. data/lib/pulsar/cli.rb +79 -0
  12. data/lib/pulsar/constants.rb +5 -0
  13. data/lib/pulsar/generators/initial_repo/Gemfile +3 -0
  14. data/lib/pulsar/generators/{init_repo → initial_repo}/README.md +1 -1
  15. data/lib/pulsar/generators/initial_repo/apps/Capfile +8 -0
  16. data/lib/pulsar/generators/initial_repo/apps/deploy.rb +35 -0
  17. data/lib/pulsar/generators/initial_repo/apps/your_app/Capfile +18 -0
  18. data/lib/pulsar/generators/initial_repo/apps/your_app/deploy.rb +4 -0
  19. data/lib/pulsar/generators/initial_repo/apps/your_app/production.rb +3 -0
  20. data/lib/pulsar/generators/initial_repo/apps/your_app/staging.rb +3 -0
  21. data/lib/pulsar/generators/initial_repo/recipes/generic/rake.rake +12 -0
  22. data/lib/pulsar/generators/{init_repo/apps/your_app/recipes/production → initial_repo/recipes/rails}/.gitkeep +0 -0
  23. data/lib/pulsar/interactors/add_applications.rb +48 -0
  24. data/lib/pulsar/interactors/cleanup.rb +9 -0
  25. data/lib/pulsar/interactors/clone_repository.rb +50 -0
  26. data/lib/pulsar/interactors/copy_environment_file.rb +30 -0
  27. data/lib/pulsar/interactors/copy_initial_repository.rb +22 -0
  28. data/lib/pulsar/interactors/create_capfile.rb +32 -0
  29. data/lib/pulsar/interactors/create_deploy_file.rb +32 -0
  30. data/lib/pulsar/interactors/create_run_dirs.rb +21 -0
  31. data/lib/pulsar/interactors/identify_repository_location.rb +23 -0
  32. data/lib/pulsar/interactors/identify_repository_type.rb +34 -0
  33. data/lib/pulsar/interactors/run_bundle_install.rb +28 -0
  34. data/lib/pulsar/interactors/run_capistrano.rb +30 -0
  35. data/lib/pulsar/organizers/deploy.rb +16 -0
  36. data/lib/pulsar/organizers/install.rb +7 -0
  37. data/lib/pulsar/organizers/list.rb +12 -0
  38. data/lib/pulsar/version.rb +1 -1
  39. data/pulsar.gemspec +13 -11
  40. data/spec/features/deploy_spec.rb +162 -0
  41. data/spec/features/install_spec.rb +66 -0
  42. data/spec/features/list_spec.rb +140 -0
  43. data/spec/spec_helper.rb +26 -14
  44. data/{lib/pulsar/generators/init_repo/apps/your_app/recipes/staging → spec/support/dummies}/.gitkeep +0 -0
  45. data/spec/support/dummies/conf/dir/Gemfile +3 -0
  46. data/spec/support/dummies/conf/dir/apps/Capfile +9 -0
  47. data/spec/support/dummies/conf/dir/apps/blog/Capfile +1 -0
  48. data/spec/support/dummies/conf/dir/apps/blog/deploy.rb +4 -0
  49. data/spec/support/dummies/conf/dir/apps/blog/production.rb +4 -0
  50. data/spec/support/dummies/conf/dir/apps/blog/staging.rb +4 -0
  51. data/spec/support/dummies/conf/dir/apps/deploy.rb +1 -0
  52. data/{lib/pulsar/generators/init_repo/recipes/rails/.gitkeep → spec/support/dummies/conf/dir/apps/ecommerce/staging.rb} +0 -0
  53. data/spec/support/dummies/conf/dir/recipes/.gitkeep +0 -0
  54. data/spec/support/dummies/conf/dotenv +1 -0
  55. data/spec/support/dummies/conf/empty/apps/.gitkeep +0 -0
  56. data/spec/support/dummies/conf/empty/recipes/.gitkeep +0 -0
  57. data/spec/support/dummies/conf/wrong_bundle/Gemfile +3 -0
  58. data/spec/support/dummies/conf/wrong_bundle/apps/Capfile +9 -0
  59. data/spec/support/dummies/conf/wrong_bundle/apps/blog/Capfile +1 -0
  60. data/spec/support/dummies/conf/wrong_bundle/apps/blog/deploy.rb +4 -0
  61. data/spec/support/dummies/conf/wrong_bundle/apps/blog/production.rb +4 -0
  62. data/spec/support/dummies/conf/wrong_bundle/apps/deploy.rb +1 -0
  63. data/spec/support/dummies/conf/wrong_bundle/recipes/.gitkeep +0 -0
  64. data/spec/support/dummies/conf/wrong_cap/Gemfile +3 -0
  65. data/spec/support/dummies/conf/wrong_cap/apps/Capfile +0 -0
  66. data/spec/support/dummies/conf/wrong_cap/apps/blog/deploy.rb +4 -0
  67. data/spec/support/dummies/conf/wrong_cap/apps/blog/production.rb +4 -0
  68. data/spec/support/dummies/conf/wrong_cap/apps/deploy.rb +1 -0
  69. data/spec/support/dummies/conf/wrong_cap/recipes/.gitkeep +0 -0
  70. data/spec/units/cli/deploy_spec.rb +116 -0
  71. data/spec/units/cli/install_spec.rb +44 -0
  72. data/spec/units/cli/list_spec.rb +107 -0
  73. data/spec/units/constants_spec.rb +21 -0
  74. data/spec/units/interactors/add_applications_spec.rb +46 -0
  75. data/spec/units/interactors/cleanup_spec.rb +21 -0
  76. data/spec/units/interactors/clone_initial_repository_spec.rb +41 -0
  77. data/spec/units/interactors/clone_repository_spec.rb +122 -0
  78. data/spec/units/interactors/copy_environment_file_spec.rb +80 -0
  79. data/spec/units/interactors/create_capfile_spec.rb +77 -0
  80. data/spec/units/interactors/create_deploy_file_spec.rb +70 -0
  81. data/spec/units/interactors/create_run_dirs_spec.rb +47 -0
  82. data/spec/units/interactors/identify_repository_location_spec.rb +49 -0
  83. data/spec/units/interactors/identify_repository_type_spec.rb +85 -0
  84. data/spec/units/interactors/run_bundle_install_spec.rb +60 -0
  85. data/spec/units/interactors/run_capistrano_spec.rb +92 -0
  86. data/spec/units/organizers/deploy_spec.rb +28 -0
  87. data/spec/units/organizers/install_spec.rb +13 -0
  88. data/spec/units/organizers/list_spec.rb +24 -0
  89. metadata +179 -106
  90. data/.ruby-gemset +0 -1
  91. data/.travis.yml +0 -17
  92. data/bin/pulsar-utils +0 -5
  93. data/lib/pulsar/commands/all.rb +0 -6
  94. data/lib/pulsar/commands/init.rb +0 -23
  95. data/lib/pulsar/commands/list.rb +0 -19
  96. data/lib/pulsar/commands/main.rb +0 -64
  97. data/lib/pulsar/commands/utils.rb +0 -14
  98. data/lib/pulsar/generators/init_repo/Gemfile +0 -7
  99. data/lib/pulsar/generators/init_repo/apps/base.rb +0 -41
  100. data/lib/pulsar/generators/init_repo/apps/your_app/defaults.rb +0 -9
  101. data/lib/pulsar/generators/init_repo/apps/your_app/production.rb +0 -12
  102. data/lib/pulsar/generators/init_repo/apps/your_app/recipes/custom_recipe.rb +0 -14
  103. data/lib/pulsar/generators/init_repo/apps/your_app/staging.rb +0 -12
  104. data/lib/pulsar/generators/init_repo/recipes/generic/cleanup.rb +0 -50
  105. data/lib/pulsar/generators/init_repo/recipes/generic/utils.rb +0 -9
  106. data/lib/pulsar/helpers/all.rb +0 -8
  107. data/lib/pulsar/helpers/capistrano.rb +0 -47
  108. data/lib/pulsar/helpers/clamp.rb +0 -223
  109. data/lib/pulsar/helpers/path.rb +0 -71
  110. data/lib/pulsar/helpers/shell.rb +0 -31
  111. data/lib/pulsar/options/all.rb +0 -6
  112. data/lib/pulsar/options/conf_repo.rb +0 -41
  113. data/lib/pulsar/options/shared.rb +0 -15
  114. data/spec/pulsar/commands/init_spec.rb +0 -10
  115. data/spec/pulsar/commands/list_spec.rb +0 -127
  116. data/spec/pulsar/commands/main_spec.rb +0 -360
  117. data/spec/pulsar/commands/utils_spec.rb +0 -33
  118. data/spec/pulsar/helpers/capistrano_spec.rb +0 -70
  119. data/spec/pulsar/helpers/clamp_spec.rb +0 -105
  120. data/spec/pulsar/helpers/shell_spec.rb +0 -11
  121. data/spec/support/dummies/dummy_app/config.ru +0 -3
  122. data/spec/support/dummies/dummy_conf/Gemfile +0 -4
  123. data/spec/support/dummies/dummy_conf/apps/base.rb +0 -46
  124. data/spec/support/dummies/dummy_conf/apps/dummy_app/custom_stage.rb +0 -5
  125. data/spec/support/dummies/dummy_conf/apps/dummy_app/defaults.rb +0 -7
  126. data/spec/support/dummies/dummy_conf/apps/dummy_app/production.rb +0 -5
  127. data/spec/support/dummies/dummy_conf/apps/dummy_app/recipes/custom_recipe.rb +0 -1
  128. data/spec/support/dummies/dummy_conf/apps/dummy_app/recipes/production/custom_recipe.rb +0 -1
  129. data/spec/support/dummies/dummy_conf/apps/dummy_app/recipes/staging/custom_recipe.rb +0 -1
  130. data/spec/support/dummies/dummy_conf/apps/dummy_app/staging.rb +0 -5
  131. data/spec/support/dummies/dummy_conf/apps/other_dummy_app/custom_stage.rb +0 -5
  132. data/spec/support/dummies/dummy_conf/apps/other_dummy_app/defaults.rb +0 -7
  133. data/spec/support/dummies/dummy_conf/apps/other_dummy_app/production.rb +0 -5
  134. data/spec/support/dummies/dummy_conf/apps/other_dummy_app/staging.rb +0 -5
  135. data/spec/support/dummies/dummy_conf/recipes/generic/recipe.rb +0 -3
  136. data/spec/support/modules/helpers.rb +0 -85
  137. data/spec/support/modules/output_capture.rb +0 -21
data/.ruby-gemset DELETED
@@ -1 +0,0 @@
1
- pulsar
data/.travis.yml DELETED
@@ -1,17 +0,0 @@
1
- language: ruby
2
- before_install: gem install bundler --pre
3
- script: "DISPLAY=:99.0 bundle exec rspec spec"
4
- notifications:
5
- email:
6
- - kennyadsl@gmail.com
7
- - mtylty@gmail.com
8
- branches:
9
- only:
10
- - master
11
- env:
12
- - CODECLIMATE_REPO_TOKEN=e2ce951cfe49257f658e6bd61d1cabe61648328c87a3f1a0908c4e4b3d9b2e7e
13
- rvm:
14
- - 1.9.3
15
- - 2.0.0
16
- - 2.1.3
17
- - 2.2.0
data/bin/pulsar-utils DELETED
@@ -1,5 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'pulsar'
4
-
5
- Pulsar::UtilsCommand.run
@@ -1,6 +0,0 @@
1
- module Pulsar
2
- autoload :MainCommand, 'pulsar/commands/main'
3
- autoload :UtilsCommand, 'pulsar/commands/utils'
4
- autoload :ListCommand, 'pulsar/commands/list'
5
- autoload :InitCommand, 'pulsar/commands/init'
6
- end
@@ -1,23 +0,0 @@
1
- module Pulsar
2
- class InitCommand < UtilsCommand
3
- parameter 'CONFIGURATION_PATH',
4
- 'where to generate your configuration repository'
5
-
6
- def execute
7
- with_clean_env_and_supported_vars do
8
- destination_path = File.expand_path(configuration_path)
9
-
10
- pulsar_cmd_path = File.expand_path(File.dirname(__FILE__))
11
- init_repo_path = "#{pulsar_cmd_path}/../generators/init_repo"
12
-
13
- init_repo_path += '/*' if File.directory?(destination_path)
14
-
15
- run_cmd(
16
- "cp -r #{init_repo_path} #{destination_path}", verbose: verbose?)
17
-
18
- puts 'Your starter configuration repo is in #{destination_path.yellow}.'
19
- puts "Remember to run #{'bundle install'.red} to add a Gemfile.lock."
20
- end
21
- end
22
- end
23
- end
@@ -1,19 +0,0 @@
1
- module Pulsar
2
- class ListCommand < UtilsCommand
3
- include Pulsar::Options::ConfRepo
4
-
5
- def execute
6
- with_clean_env_and_supported_vars do
7
- begin
8
- create_tmp_dir
9
- fetch_repo
10
-
11
- list_apps
12
- ensure
13
- remove_capfile unless keep_capfile?
14
- remove_repo unless keep_repo?
15
- end
16
- end
17
- end
18
- end
19
- end
@@ -1,64 +0,0 @@
1
- module Pulsar
2
- class MainCommand < Clamp::Command
3
- include Pulsar::Helpers::Clamp
4
- include Pulsar::Options::Shared
5
- include Pulsar::Options::ConfRepo
6
-
7
- option ['-l', '--log-level'], 'LOG LEVEL',
8
- 'how much output will Capistrano print out. Can be any of: important, info, debug, trace',
9
- default: 'important'
10
-
11
- option ['-s', '--skip-cap-run'], :flag,
12
- 'do everything pulsar does (build a Capfile) but don\'t run the cap command',
13
- default: false
14
-
15
- unless from_application_path?
16
- parameter 'APPLICATIONS', 'the applications which you would like to deploy. You can pass just one or a comma separated list to deploy multiple applications at once. It supports globbing too.'
17
- end
18
-
19
- parameter 'STAGE', 'the stage on which you would like to deploy'
20
-
21
- parameter '[TASKS] ...',
22
- 'the arguments and/or options that will be passed to capistrano',
23
- environment_variable: 'PULSAR_DEFAULT_TASK',
24
- default: 'deploy'
25
-
26
- def execute
27
- with_clean_env_and_supported_vars do
28
- begin
29
- fetch_repo_and_bundle
30
- expand_applications.each { |app| validate_and_run_capistrano(app) }
31
- ensure
32
- cleanup
33
- end
34
- end
35
- end
36
-
37
- private
38
-
39
- def cleanup(opts = { full: true })
40
- remove_capfile unless keep_capfile?
41
- reset_capfile_path!
42
- remove_repo if opts[:full] && !keep_repo?
43
- end
44
-
45
- def fetch_repo_and_bundle
46
- create_tmp_dir
47
- fetch_repo
48
- bundle_install
49
- end
50
-
51
- def validate_and_run_capistrano(app)
52
- validate(app, stage)
53
- create_capfile
54
- build_capfile(app, stage)
55
-
56
- unless skip_cap_run?
57
- cap_args = [tasks_list].flatten.shelljoin
58
- run_capistrano(cap_args)
59
- end
60
-
61
- cleanup(full: false)
62
- end
63
- end
64
- end
@@ -1,14 +0,0 @@
1
- module Pulsar
2
- class UtilsCommand < Clamp::Command
3
- include Pulsar::Helpers::Clamp
4
- include Pulsar::Options::Shared
5
-
6
- subcommand 'list',
7
- 'list all available apps and stages which you can deploy',
8
- ListCommand
9
-
10
- subcommand 'init',
11
- 'generate a new configuration repo with some basic recipes to use with pulsar',
12
- InitCommand
13
- end
14
- end
@@ -1,7 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- gem 'pulsar'
4
- gem 'capistrano', '~>2'
5
-
6
- gem 'colored'
7
- gem 'spinning_cursor'
@@ -1,41 +0,0 @@
1
- #
2
- # Require everything and extend with additional modules
3
- #
4
- Bundler.require
5
-
6
- extend Pulsar::Helpers::Capistrano
7
-
8
- #
9
- # Load deploy capistrano recipe
10
- #
11
- load 'deploy'
12
-
13
- #
14
- # Configure libraries/recipes from Gemfile
15
- #
16
- require 'bundler/capistrano'
17
-
18
- #
19
- # Load default recipes
20
- #
21
- load_recipes do
22
- generic :cleanup, :utils
23
- end
24
-
25
- #
26
- # Put here shared configuration that should be a default
27
- # for all your apps
28
- #
29
-
30
- # set :scm, :git
31
- # set :repository, defer { "git@github.com:your_gh_user/#{application}.git" }
32
- # set :branch, "master"
33
- # set :port, 22
34
- # set :ssh_options, { :forward_agent => true }
35
- # set :default_run_options, { :pty => true }
36
- # set :deploy_to, defer { "/var/www/#{application}" }
37
- # set :deploy_via, :remote_cache
38
- # set :user, "www-data"
39
- # set :use_sudo, false
40
- # set :rake, "bundle exec rake"
41
- # set :rails_env, defer { "#{stage}" }
@@ -1,9 +0,0 @@
1
- set :application, 'your_app'
2
-
3
- load_recipes do
4
- #
5
- # Recipes you wish to include as defaults for both stages
6
- # for example:
7
- #
8
- # rails :assets
9
- end
@@ -1,12 +0,0 @@
1
- server 'your_app.com', :db, :web, :app, primary: true
2
-
3
- set :stage, 'production'
4
-
5
- load_recipes do
6
- #
7
- # Recipes you wish to include for production stage only
8
- # for example:
9
- #
10
- # rails :fix_permissions, :symlink_db
11
- # server :unicorn
12
- end
@@ -1,14 +0,0 @@
1
- #
2
- # Use this directory to include any file you whish to
3
- # include whenever you run this app.
4
- #
5
- # You don't need to run the include_recipe method.
6
- #
7
- # The filename can be whatever you want it to be.
8
- #
9
- # These recipes are considered custom and always appended
10
- # to the Capfile of this application.
11
- #
12
- # production/ and staging/ directories will have recipes
13
- # which are automatically included only in such stages.
14
- #
@@ -1,12 +0,0 @@
1
- server 'staging.your_app.com', :db, :web, :app, primary: true
2
-
3
- set :stage, 'staging'
4
-
5
- load_recipes do
6
- #
7
- # Recipes you wish to include for staging stage only
8
- # for example:
9
- #
10
- # server :passenger
11
- # notify :campfire
12
- end
@@ -1,50 +0,0 @@
1
- if logger.level == Capistrano::Logger::IMPORTANT
2
- arrow = '→'.yellow.bold
3
- ok = '✓'.green
4
-
5
- before 'deploy:update_code' do
6
- SpinningCursor.start do
7
- banner "#{arrow} Updating Code"
8
- message "#{arrow} Updating Code #{ok}"
9
- end
10
- end
11
-
12
- before 'bundle:install' do
13
- SpinningCursor.start do
14
- banner "#{arrow} Installing Gems"
15
- message "#{arrow} Installing Gems #{ok}"
16
- end
17
- end
18
-
19
- before 'deploy:assets:symlink' do
20
- SpinningCursor.start do
21
- banner "#{arrow} Symlinking Assets"
22
- message "#{arrow} Symlinking Assets #{ok}"
23
- end
24
- end
25
-
26
- before 'deploy:assets:precompile' do
27
- SpinningCursor.start do
28
- banner "#{arrow} Compiling Assets"
29
- message "#{arrow} Compiling Assets #{ok}"
30
- end
31
- end
32
-
33
- before 'deploy:create_symlink' do
34
- SpinningCursor.start do
35
- banner "#{arrow} Symlinking Application"
36
- message "#{arrow} Symlinking Application #{ok}"
37
- end
38
- end
39
-
40
- before 'deploy:restart' do
41
- SpinningCursor.start do
42
- banner "#{arrow} Restarting Webserver"
43
- message "#{arrow} Restarting Webserver #{ok}"
44
- end
45
- end
46
-
47
- after 'deploy' do
48
- SpinningCursor.stop
49
- end
50
- end
@@ -1,9 +0,0 @@
1
- namespace :utils do
2
- desc 'Invoke your awesome rake tasks!'
3
- task :invoke_rake, roles: :web do
4
- cd = "cd #{deploy_to}/current"
5
- cmd = "RAILS_ENV=#{rails_env} #{rake} #{ENV['ARGS']}"
6
-
7
- run("#{cd} && #{cmd}")
8
- end
9
- end
@@ -1,8 +0,0 @@
1
- module Pulsar
2
- module Helpers
3
- autoload :Capistrano, 'pulsar/helpers/capistrano'
4
- autoload :Clamp, 'pulsar/helpers/clamp'
5
- autoload :Path, 'pulsar/helpers/path'
6
- autoload :Shell, 'pulsar/helpers/shell'
7
- end
8
- end
@@ -1,47 +0,0 @@
1
- module Pulsar
2
- module Helpers
3
- module Capistrano
4
- class DSL
5
- include Pulsar::Helpers::Clamp
6
-
7
- def initialize(capistrano, opts, &dsl_code)
8
- @capistrano = capistrano
9
- @options = opts
10
- instance_eval(&dsl_code)
11
- end
12
-
13
- def method_missing(meth, *args)
14
- return if !@capistrano.from_application_path? && @options[:app_only]
15
-
16
- recipes = "#{ENV['CONFIG_PATH']}/recipes/#{meth}"
17
-
18
- File.directory?(recipes) || fail("There are no recipes of type #{meth}")
19
-
20
- args.each do |arg|
21
- recipe = "#{recipes}/#{arg}.rb"
22
- File.exist?(recipe) || fail("There is no #{arg} recipe")
23
-
24
- @capistrano.send(:load, recipe)
25
- end
26
- end
27
- end
28
-
29
- #
30
- # This method can be called directly inside
31
- # capistrano configurations but needs:
32
- #
33
- # defer { from_application_path? }
34
- #
35
- # otherwise capistrano will interpret it
36
- # as a variable and error out
37
- #
38
- def from_application_path?
39
- ENV.key?('APP_PATH')
40
- end
41
-
42
- def load_recipes(opts = {}, &block)
43
- DSL.new(self, opts, &block)
44
- end
45
- end
46
- end
47
- end
@@ -1,223 +0,0 @@
1
- module Pulsar
2
- module Helpers
3
- module Clamp
4
- include Pulsar::Helpers::Shell
5
- include Pulsar::Helpers::Path
6
-
7
- def self.included(base)
8
- base.extend(InstanceAndClassMethods)
9
- base.send(:include, InstanceMethods)
10
- end
11
-
12
- module InstanceAndClassMethods
13
- def from_application_path?
14
- File.exist?("#{Dir.pwd}/config.ru")
15
- end
16
- end
17
-
18
- module InstanceMethods
19
- include InstanceAndClassMethods
20
-
21
- def application_path
22
- Dir.pwd if from_application_path?
23
- end
24
-
25
- def build_capfile(app, stage)
26
- # Variables
27
- set_log_level
28
- include_base_conf
29
- include_app(app, stage) if app
30
-
31
- # Recipes
32
- include_app_recipes(app, stage) if app
33
- end
34
-
35
- def bundle_install
36
- cd(config_path, verbose: verbose?) do
37
- run_cmd("bundle install --quiet --path=#{bundle_path.shellescape}", verbose: verbose?)
38
- end
39
- end
40
-
41
- def create_capfile
42
- touch(capfile_path, verbose: verbose?)
43
- end
44
-
45
- def create_tmp_dir
46
- run_cmd("mkdir -p #{tmp_path.shellescape}", verbose: verbose?)
47
- end
48
-
49
- def each_app
50
- Dir["#{config_apps_path}/*"].each do |path|
51
- yield(File.basename(path)) if File.directory?(path)
52
- end
53
- end
54
-
55
- def expand_applications
56
- if from_application_path?
57
- [ENV['PULSAR_APP_NAME'] || File.basename(application_path)]
58
- else
59
- #
60
- # Given following applications:
61
- # pulsar_repo/
62
- # apps/
63
- # app1
64
- # app2
65
- # app3-web
66
- # app3-worker
67
- # app4
68
- # it turns app1,app2,app3* into
69
- #
70
- # [ app1, app2, app3-web, app3-worker ]
71
- #
72
- applications.split(',').flat_map { |glob| find_apps_from_pattern(glob) }.uniq
73
- end
74
- end
75
-
76
- def fetch_repo
77
- if File.directory?(conf_repo)
78
- fetch_directory_repo(conf_repo)
79
- else
80
- if conf_repo =~ /\A[a-zA-Z-]+\/[a-zA-Z-]+\Z/
81
- fetch_git_repo("git@github.com:#{conf_repo}.git")
82
- else
83
- fetch_git_repo(conf_repo)
84
- end
85
- end
86
- end
87
-
88
- def fetch_directory_repo(repo)
89
- run_cmd("cp -rp #{repo} #{config_path}", verbose: verbose?)
90
- end
91
-
92
- def fetch_git_repo(repo, local = false)
93
- git_options = "--quiet --branch #{conf_branch}"
94
- git_options = "#{git_options} --depth=1" unless local
95
-
96
- run_cmd("git clone #{git_options} #{repo} #{config_path}", verbose: verbose?)
97
- end
98
-
99
- def find_apps_from_pattern(glob)
100
- found_apps = []
101
-
102
- Dir.glob(config_app_path("#{glob}/")).each do |path|
103
- found_apps << File.basename(path)
104
- end
105
-
106
- found_apps << glob if found_apps.empty?
107
- found_apps
108
- end
109
-
110
- def include_app(app, stage)
111
- app_file = config_app_defaults_path(app)
112
- stage_file = config_stage_path(app, stage)
113
-
114
- if File.exist?(app_file)
115
- run_cmd("cat #{app_file} >> #{capfile_path}", verbose: verbose?)
116
- end
117
-
118
- if File.exist?(stage_file)
119
- run_cmd("cat #{stage_file} >> #{capfile_path}", verbose: verbose?)
120
- end
121
- end
122
-
123
- def include_app_recipes(app, stage)
124
- recipes_dir = config_app_recipes_path(app)
125
- stage_recipes_dir = config_app_stage_recipes_path(app, stage)
126
-
127
- Dir["#{recipes_dir}/*.rb", "#{stage_recipes_dir}/*.rb"].each do |recipe|
128
- run_cmd("cat #{recipe} >> #{capfile_path}", verbose: verbose?)
129
- end
130
- end
131
-
132
- def include_base_conf
133
- run_cmd("cat #{config_base_path} >> #{capfile_path}", verbose: verbose?)
134
- end
135
-
136
- def list_apps
137
- each_app do |name|
138
- puts "#{name.cyan}: #{stages_for(name).map(&:magenta).join(', ')}"
139
- end
140
- end
141
-
142
- def load_configuration
143
- return if pulsar_configuration.nil?
144
-
145
- File.readlines(pulsar_configuration).each do |line|
146
- conf, value = line.split('=')
147
-
148
- ENV[conf] = value.chomp.gsub('"', '') if !conf.nil? && !value.nil?
149
- end
150
- end
151
-
152
- def pulsar_configuration
153
- path_list = []
154
- path_list << File.join(application_path, '.pulsar') unless application_path.nil?
155
- path_list << File.join(home_path, 'config')
156
-
157
- path_list.find { |path| File.file?(path) }
158
- end
159
-
160
- def remove_capfile
161
- rm_rf(capfile_path, verbose: verbose?)
162
- end
163
-
164
- def remove_repo
165
- rm_rf(config_path, verbose: verbose?)
166
- end
167
-
168
- def run_capistrano(args)
169
- cmd = 'bundle exec cap'
170
- env = "CONFIG_PATH=#{config_path}"
171
- opts = "--file #{capfile_path}"
172
-
173
- env += " APP_PATH=#{application_path}" unless application_path.nil?
174
-
175
- cd(config_path, verbose: verbose?) do
176
- run_cmd("#{cmd} #{env} #{opts} #{args}", verbose: verbose?)
177
- end
178
- end
179
-
180
- def set_log_level
181
- level = log_level.upcase
182
- levels = %w(IMPORTANT INFO DEBUG TRACE)
183
-
184
- level = levels.first unless levels.include?(level)
185
-
186
- cmd = "echo 'logger.level = logger.level = Capistrano::Logger::#{level}' >> #{capfile_path}"
187
-
188
- run_cmd(cmd, verbose: verbose?)
189
- end
190
-
191
- def supported_env_vars
192
- %w(PULSAR_APP_NAME PULSAR_CONF_REPO PULSAR_DEFAULT_TASK)
193
- end
194
-
195
- def stages_for(app)
196
- exclude = %w(defaults recipes)
197
-
198
- Dir["#{config_app_path(app)}/*"].sort.map do |env|
199
- env_name = File.basename(env, '.rb')
200
-
201
- env_name unless exclude.include?(env_name)
202
- end.compact
203
- end
204
-
205
- def validate(app, stage)
206
- app_path = config_app_path(app)
207
- stage_path = config_stage_path(app, stage)
208
- valid_paths = File.exist?(app_path) && File.exist?(stage_path)
209
- fail(ArgumentError, "no pulsar config available for app=#{app}, stage=#{stage}") unless valid_paths
210
- end
211
-
212
- def with_clean_env_and_supported_vars
213
- vars_from_original_env = ENV.select { |var| supported_env_vars.include?(var) }
214
-
215
- Bundler.with_clean_env do
216
- vars_from_original_env.each { |var, val| ENV[var] = val }
217
- yield
218
- end
219
- end
220
- end
221
- end
222
- end
223
- end