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/bin/pulsar CHANGED
@@ -2,4 +2,4 @@
2
2
 
3
3
  require 'pulsar'
4
4
 
5
- Pulsar::MainCommand.run
5
+ Pulsar::CLI.start(ARGV)
data/circle.yml ADDED
@@ -0,0 +1,22 @@
1
+ dependencies:
2
+ pre:
3
+ - rvm install 2.0.0
4
+ - rvm install 2.1.10
5
+ - rvm install 2.2.6
6
+ - rvm install 2.3.3
7
+ - rvm install 2.4.0
8
+ override:
9
+ - rvm-exec 2.0.0 bash -c "bundle check --path=vendor/bundle || bundle install --path=vendor/bundle"
10
+ - rvm-exec 2.1.10 bash -c "bundle check --path=vendor/bundle || bundle install --path=vendor/bundle"
11
+ - rvm-exec 2.2.6 bash -c "bundle check --path=vendor/bundle || bundle install --path=vendor/bundle"
12
+ - rvm-exec 2.3.3 bash -c "bundle check --path=vendor/bundle || bundle install --path=vendor/bundle"
13
+ - rvm-exec 2.4.0 bash -c "bundle check --path=vendor/bundle || bundle install --path=vendor/bundle"
14
+ test:
15
+ pre:
16
+ - git config --global user.email "circleci@nebulab.it" && git config --global user.name "Circle CI"
17
+ override:
18
+ - rvm-exec 2.0.0 bash -c "bundle exec rspec --color --format documentation spec"
19
+ - rvm-exec 2.1.10 bash -c "bundle exec rspec --color --format documentation spec"
20
+ - rvm-exec 2.2.6 bash -c "bundle exec rspec --color --format documentation spec"
21
+ - rvm-exec 2.3.3 bash -c "bundle exec rspec --color --format documentation spec"
22
+ - rvm-exec 2.4.0 bash -c "bundle exec rspec --color --format documentation spec"
data/lib/pulsar.rb CHANGED
@@ -1,12 +1,33 @@
1
1
  require 'pulsar/version'
2
2
 
3
3
  module Pulsar
4
- require 'clamp'
5
4
  require 'bundler'
6
- require 'colored'
7
- require 'shellwords'
8
- require 'tmpdir'
9
- require 'pulsar/helpers/all'
10
- require 'pulsar/options/all'
11
- require 'pulsar/commands/all'
5
+ require 'thor'
6
+ require 'rake'
7
+ require 'dotenv'
8
+ require 'interactor'
9
+ require 'fileutils'
10
+
11
+ require 'pulsar/interactors/cleanup'
12
+ require 'pulsar/interactors/create_run_dirs'
13
+ require 'pulsar/interactors/add_applications'
14
+ require 'pulsar/interactors/clone_repository'
15
+ require 'pulsar/interactors/copy_initial_repository'
16
+ require 'pulsar/interactors/identify_repository_type'
17
+ require 'pulsar/interactors/identify_repository_location'
18
+ require 'pulsar/interactors/create_capfile'
19
+ require 'pulsar/interactors/create_deploy_file'
20
+ require 'pulsar/interactors/copy_environment_file'
21
+ require 'pulsar/interactors/run_bundle_install'
22
+ require 'pulsar/interactors/run_capistrano'
23
+
24
+ require 'pulsar/organizers/list'
25
+ require 'pulsar/organizers/install'
26
+ require 'pulsar/organizers/deploy'
27
+
28
+ require 'pulsar/constants'
29
+ require 'pulsar/cli'
30
+
31
+ # Silence Rake output
32
+ Rake::FileUtilsExt.verbose_flag = false
12
33
  end
data/lib/pulsar/cli.rb ADDED
@@ -0,0 +1,79 @@
1
+ module Pulsar
2
+ class CLI < Thor
3
+ desc 'install [DIRECTORY]', 'Install initial repository in DIRECTORY'
4
+ long_desc <<-LONGDESC
5
+ `pulsar install` will install the initial pulsar repository in the
6
+ current working directory.
7
+
8
+ You can optionally specify a second parameter, which will be the
9
+ destination directory in which to install the repository.
10
+ LONGDESC
11
+ def install(directory = './pulsar-conf')
12
+ result = Pulsar::Install.call(directory: directory)
13
+
14
+ if result.success?
15
+ puts 'Successfully created intial repo!'
16
+ else
17
+ puts 'Failed to create intial repo.'
18
+ end
19
+ end
20
+
21
+ desc 'list', 'List available applications and environments'
22
+ long_desc <<-LONGDESC
23
+ `pulsar list` will list the applications and environments available in
24
+ the configured pulsar repository.
25
+ LONGDESC
26
+ option :conf_repo, aliases: '-c'
27
+ def list
28
+ load_config
29
+ result = Pulsar::List.call(repository: load_option_or_env!(:conf_repo))
30
+
31
+ if result.success?
32
+ puts result.applications
33
+ else
34
+ puts 'Failed to list application and environments.'
35
+ end
36
+ end
37
+
38
+ desc 'deploy APPLICATION ENVIRONMENT', 'Run Capistrano to deploy APPLICATION on ENVIRONMENT'
39
+ long_desc <<-LONGDESC
40
+ `pulsar deploy APPLICATION ENVIRONMENT` will generate the configuration for the
41
+ specified APPLICATION on ENVIRONMENT from the configuration repo and run
42
+ Capistrano on it.
43
+ LONGDESC
44
+ option :conf_repo, aliases: '-c'
45
+ def deploy(application, environment)
46
+ load_config
47
+ result = Pulsar::Deploy.call(
48
+ repository: load_option_or_env!(:conf_repo),
49
+ application: application, environment: environment
50
+ )
51
+
52
+ if result.success?
53
+ puts "Deployed #{application} on #{environment}!"
54
+ else
55
+ puts "Failed to deploy #{application} on #{environment}."
56
+ end
57
+ end
58
+
59
+ private
60
+
61
+ def load_config
62
+ Dotenv.load(PULSAR_CONF) # Load configurations for Pulsar
63
+ end
64
+
65
+ def load_option_or_env!(option)
66
+ option_name = "--#{option.to_s.tr!('_', '-')}"
67
+ env_option = "PULSAR_#{option.upcase}"
68
+ exception_text = "No value provided for required options '#{option_name}'"
69
+ option_value = options[option] || ENV[env_option]
70
+
71
+ if option_value.nil? || option_value.empty?
72
+ fail RequiredArgumentMissingError,
73
+ exception_text
74
+ end
75
+
76
+ option_value
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,5 @@
1
+ module Pulsar
2
+ PULSAR_HOME = File.expand_path('~/.pulsar')
3
+ PULSAR_TMP = "#{PULSAR_HOME}/tmp".freeze
4
+ PULSAR_CONF = "#{PULSAR_HOME}/config".freeze
5
+ end
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'capistrano', '3.8.0'
@@ -1,4 +1,4 @@
1
1
  Pulsar Configuration
2
2
  ====================
3
3
 
4
- Pulsar deploy configurations
4
+ Your Pulsar deploy configuration repo.
@@ -0,0 +1,8 @@
1
+ # Load DSL and set up stages
2
+ require "capistrano/setup"
3
+
4
+ # Include default deployment tasks
5
+ require "capistrano/deploy"
6
+
7
+ require "capistrano/scm/git"
8
+ install_plugin Capistrano::SCM::Git
@@ -0,0 +1,35 @@
1
+ # deploy.rb file shared between all the apps
2
+
3
+ # config valid only for current version of Capistrano
4
+ lock '3.8.0'
5
+
6
+ # Default branch is :master
7
+ # ask :branch, `git rev-parse --abbrev-ref HEAD`.chomp
8
+
9
+ # Default deploy_to directory is /var/www/my_app_name
10
+ # set :deploy_to, '/var/www/my_app_name'
11
+
12
+ # Default value for :scm is :git
13
+ # set :scm, :git
14
+
15
+ # Default value for :format is :airbrussh.
16
+ # set :format, :airbrussh
17
+
18
+ # You can configure the Airbrussh format using :format_options.
19
+ # These are the defaults.
20
+ # set :format_options, command_output: true, log_file: 'log/capistrano.log', color: :auto, truncate: :auto
21
+
22
+ # Default value for :pty is false
23
+ # set :pty, true
24
+
25
+ # Default value for :linked_files is []
26
+ # append :linked_files, 'config/database.yml', 'config/secrets.yml'
27
+
28
+ # Default value for linked_dirs is []
29
+ # append :linked_dirs, 'log', 'tmp/pids', 'tmp/cache', 'tmp/sockets', 'public/system'
30
+
31
+ # Default value for default_env is {}
32
+ # set :default_env, { path: "/opt/ruby/bin:$PATH" }
33
+
34
+ # Default value for keep_releases is 5
35
+ # set :keep_releases, 5
@@ -0,0 +1,18 @@
1
+ # Include tasks from other gems included in your Gemfile
2
+ #
3
+ # For documentation on these, see for example:
4
+ #
5
+ # https://github.com/capistrano/rvm
6
+ # https://github.com/capistrano/rbenv
7
+ # https://github.com/capistrano/chruby
8
+ # https://github.com/capistrano/bundler
9
+ # https://github.com/capistrano/rails
10
+ # https://github.com/capistrano/passenger
11
+ #
12
+ # require 'capistrano/rvm'
13
+ # require 'capistrano/rbenv'
14
+ # require 'capistrano/chruby'
15
+ # require 'capistrano/bundler'
16
+ # require 'capistrano/rails/assets'
17
+ # require 'capistrano/rails/migrations'
18
+ # require 'capistrano/passenger'
@@ -0,0 +1,4 @@
1
+ # deploy.rb file shared between all the stages of a certain app
2
+
3
+ set :application, 'my_app_name'
4
+ set :repo_url, 'git@example.com:me/my_repo.git'
@@ -0,0 +1,3 @@
1
+ server 'your_app.com', user: 'deploy', roles: %w{web app db}, primary: true
2
+
3
+ set :stage, :production
@@ -0,0 +1,3 @@
1
+ server 'staging.your_app.com', user: 'deploy', roles: %w{web app db}, primary: true
2
+
3
+ set :stage, :staging
@@ -0,0 +1,12 @@
1
+ namespace :rake do
2
+ desc "Invoke your awesome rake tasks!"
3
+ task :invoke do
4
+ on roles(:app) do
5
+ within current_path do
6
+ with rails_env: fetch(:stage) do
7
+ execute :rake, ENV['ARGS']
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,48 @@
1
+ module Pulsar
2
+ class AddApplications
3
+ include Interactor
4
+
5
+ before :validate_input!, :prepare_context
6
+ after :validate_output!
7
+
8
+ def call
9
+ each_application_path do |app|
10
+ context.applications << "#{File.basename(app)}: #{stages_for(app)}"
11
+ end
12
+ rescue
13
+ context.fail!
14
+ end
15
+
16
+ private
17
+
18
+ def prepare_context
19
+ context.applications = []
20
+ end
21
+
22
+ def validate_input!
23
+ context.fail! if context.config_path.nil?
24
+ end
25
+
26
+ def validate_output!
27
+ context.fail! if context.applications.empty?
28
+ end
29
+
30
+ def each_application_path
31
+ Dir["#{context.config_path}/apps/*"].sort.each do |app|
32
+ next if File.basename(app, '.rb') == 'deploy' ||
33
+ File.basename(app) == 'Capfile'
34
+
35
+ yield(app)
36
+ end
37
+ end
38
+
39
+ def stages_for(app)
40
+ stage_files = Dir["#{app}/*.rb"].sort.map do |file|
41
+ File.basename(file, '.rb')
42
+ end
43
+ stage_files.reject do |stage|
44
+ %w(deploy Capfile).include?(stage)
45
+ end.join(', ')
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,9 @@
1
+ module Pulsar
2
+ class Cleanup
3
+ include Interactor
4
+
5
+ def call
6
+ FileUtils.rm_rf(context.run_path)
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,50 @@
1
+ module Pulsar
2
+ class CloneRepository
3
+ include Interactor
4
+
5
+ before :validate_input!
6
+
7
+ def call
8
+ case context.repository_type
9
+ when :git then clone_git_repository
10
+ when :github then clone_github_repository
11
+ when :folder then copy_local_folder
12
+ end
13
+ rescue
14
+ context.fail!
15
+ end
16
+
17
+ private
18
+
19
+ def validate_input!
20
+ context.fail! if context.config_path.nil? ||
21
+ context.repository.nil? ||
22
+ context.repository_type.nil?
23
+ end
24
+
25
+ def clone_git_repository
26
+ cmd = 'git clone'
27
+ opts = '--quiet --depth 1'
28
+ quiet = '>/dev/null 2>&1'
29
+
30
+ Rake.sh(
31
+ "#{cmd} #{opts} #{context.repository} #{context.config_path} #{quiet}"
32
+ )
33
+ end
34
+
35
+ def clone_github_repository
36
+ cmd = 'git clone'
37
+ opts = '--quiet --depth 1'
38
+ quiet = '>/dev/null 2>&1'
39
+ repo = "git@github.com:#{context.repository}.git"
40
+
41
+ Rake.sh(
42
+ "#{cmd} #{opts} #{repo} #{context.config_path} #{quiet}"
43
+ )
44
+ end
45
+
46
+ def copy_local_folder
47
+ FileUtils.cp_r("#{context.repository}/.", context.config_path)
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,30 @@
1
+ module Pulsar
2
+ class CopyEnvironmentFile
3
+ include Interactor
4
+
5
+ before :validate_input!, :prepare_context
6
+
7
+ def call
8
+ env_file = "#{context.config_path}/apps/#{context.application}/#{context.environment}.rb"
9
+
10
+ FileUtils.mkdir_p(context.cap_deploy_path)
11
+ FileUtils.cp(env_file, context.environment_file_path)
12
+ rescue
13
+ context.fail!
14
+ end
15
+
16
+ private
17
+
18
+ def prepare_context
19
+ context.cap_deploy_path = "#{context.cap_path}/config/deploy"
20
+ context.environment_file_path = "#{context.cap_deploy_path}/#{context.environment}.rb"
21
+ end
22
+
23
+ def validate_input!
24
+ context.fail! if context.config_path.nil? ||
25
+ context.cap_path.nil? ||
26
+ context.application.nil? ||
27
+ context.environment.nil?
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,22 @@
1
+ module Pulsar
2
+ class CopyInitialRepository
3
+ include Interactor
4
+
5
+ before :validate_input!
6
+
7
+ def call
8
+ current_path = File.dirname(__FILE__)
9
+ initial_repo = "#{current_path}/../generators/initial_repo"
10
+
11
+ FileUtils.cp_r(File.expand_path(initial_repo), context.directory)
12
+ rescue
13
+ context.fail!
14
+ end
15
+
16
+ private
17
+
18
+ def validate_input!
19
+ context.fail! if context.directory.nil?
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,32 @@
1
+ module Pulsar
2
+ class CreateCapfile
3
+ include Interactor
4
+
5
+ before :validate_input!, :prepare_context
6
+
7
+ def call
8
+ default_capfile = "#{context.config_path}/apps/Capfile"
9
+ app_capfile = "#{context.config_path}/apps/#{context.application}/Capfile"
10
+ import_tasks = "Dir.glob(\"#{context.config_path}/recipes/**/*.rake\").each { |r| import r }"
11
+
12
+ FileUtils.touch(context.capfile_path)
13
+ Rake.sh("cat #{default_capfile} >> #{context.capfile_path}") if File.exist?(default_capfile)
14
+ Rake.sh("cat #{app_capfile} >> #{context.capfile_path}") if File.exist?(app_capfile)
15
+ Rake.sh("echo '#{import_tasks}' >> #{context.capfile_path}")
16
+ rescue
17
+ context.fail!
18
+ end
19
+
20
+ private
21
+
22
+ def prepare_context
23
+ context.capfile_path = "#{context.cap_path}/Capfile"
24
+ end
25
+
26
+ def validate_input!
27
+ context.fail! if context.config_path.nil? ||
28
+ context.cap_path.nil? ||
29
+ context.application.nil?
30
+ end
31
+ end
32
+ end