deploy-context 2.13.24 → 2.13.25

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data/bin/deploy-context +15 -1
  4. data/home/jimboadmin/deploy-context/habitat/plan.sh/x86_64-linux/lib/context-knife-context.rb +26 -0
  5. data/home/jimboadmin/deploy-context/habitat/plan.sh/x86_64-linux/lib/context-manager.rb +100 -0
  6. data/home/jimboadmin/deploy-context/habitat/plan.sh/x86_64-linux/lib/deploy-context/cookbook-studio.rb +72 -0
  7. data/home/jimboadmin/deploy-context/habitat/plan.sh/x86_64-linux/lib/deploy-context/cucumber-studio.rb +45 -0
  8. data/home/jimboadmin/deploy-context/habitat/plan.sh/x86_64-linux/lib/deploy-context/cucumber-suite.rb +201 -0
  9. data/home/jimboadmin/deploy-context/habitat/plan.sh/x86_64-linux/lib/deploy-context/default-studio.rb +172 -0
  10. data/home/jimboadmin/deploy-context/habitat/plan.sh/x86_64-linux/lib/deploy-context/deploy/chef.rb +57 -0
  11. data/home/jimboadmin/deploy-context/habitat/plan.sh/x86_64-linux/lib/deploy-context/deploy/context.rb +42 -0
  12. data/home/jimboadmin/deploy-context/habitat/plan.sh/x86_64-linux/lib/deploy-context/deploy/cookbook.rb +121 -0
  13. data/home/jimboadmin/deploy-context/habitat/plan.sh/x86_64-linux/lib/deploy-context/deploy/cucumber.rb +42 -0
  14. data/home/jimboadmin/deploy-context/habitat/plan.sh/x86_64-linux/lib/deploy-context/deploy/deployer.rb +83 -0
  15. data/home/jimboadmin/deploy-context/habitat/plan.sh/x86_64-linux/lib/deploy-context/deploy/git.rb +62 -0
  16. data/home/jimboadmin/deploy-context/habitat/plan.sh/x86_64-linux/lib/deploy-context/deploy/habitat.rb +112 -0
  17. data/home/jimboadmin/deploy-context/habitat/plan.sh/x86_64-linux/lib/deploy-context/deploy/ruby.rb +138 -0
  18. data/home/jimboadmin/deploy-context/habitat/plan.sh/x86_64-linux/lib/deploy-context/deploy/vagrant.rb +7 -0
  19. data/home/jimboadmin/deploy-context/habitat/plan.sh/x86_64-linux/lib/deploy-context/habitat-studio.rb +50 -0
  20. data/home/jimboadmin/deploy-context/habitat/plan.sh/x86_64-linux/lib/deploy-context/helpers/command.rb +91 -0
  21. data/home/jimboadmin/deploy-context/habitat/plan.sh/x86_64-linux/lib/deploy-context/helpers/gemspec.rb +93 -0
  22. data/home/jimboadmin/deploy-context/habitat/plan.sh/x86_64-linux/lib/deploy-context/helpers/rake_tasks.rb +150 -0
  23. data/home/jimboadmin/deploy-context/habitat/plan.sh/x86_64-linux/lib/deploy-context/knife/default_knife_context.rb +35 -0
  24. data/home/jimboadmin/deploy-context/habitat/plan.sh/x86_64-linux/lib/deploy-context/knife/dummy_knife.rb +43 -0
  25. data/home/jimboadmin/deploy-context/habitat/plan.sh/x86_64-linux/lib/deploy-context/ruby-studio.rb +56 -0
  26. data/home/jimboadmin/deploy-context/habitat/plan.sh/x86_64-linux/lib/deploy-context/steps/cucumber.rb +22 -0
  27. data/home/jimboadmin/deploy-context/habitat/plan.sh/x86_64-linux/lib/deploy-context/steps/deploy.rb +61 -0
  28. data/home/jimboadmin/deploy-context/habitat/plan.sh/x86_64-linux/lib/deploy-context/steps/git.rb +54 -0
  29. data/home/jimboadmin/deploy-context/habitat/plan.sh/x86_64-linux/lib/deploy-context/steps/habitat.rb +67 -0
  30. data/home/jimboadmin/deploy-context/habitat/plan.sh/x86_64-linux/lib/deploy-context/steps/inspec.rb +26 -0
  31. data/home/jimboadmin/deploy-context/habitat/plan.sh/x86_64-linux/lib/deploy-context/steps/kitchen.rb +59 -0
  32. data/home/jimboadmin/deploy-context/habitat/plan.sh/x86_64-linux/lib/deploy-context/steps/knife.rb +43 -0
  33. data/home/jimboadmin/deploy-context/habitat/plan.sh/x86_64-linux/lib/deploy-context/steps/rake.rb +18 -0
  34. data/home/jimboadmin/deploy-context/habitat/plan.sh/x86_64-linux/lib/deploy-context/steps/ruby.rb +14 -0
  35. data/home/jimboadmin/deploy-context/habitat/plan.sh/x86_64-linux/lib/deploy-context/steps/supermarket.rb +14 -0
  36. data/home/jimboadmin/deploy-context/habitat/plan.sh/x86_64-linux/lib/deploy-context/studio/base.rb +167 -0
  37. data/home/jimboadmin/deploy-context/habitat/plan.sh/x86_64-linux/lib/deploy-context/studio/default.rb +38 -0
  38. data/home/jimboadmin/deploy-context/habitat/plan.sh/x86_64-linux/lib/deploy-context/studio/deployer.rb +24 -0
  39. data/home/jimboadmin/deploy-context/habitat/plan.sh/x86_64-linux/lib/deploy-context.rb +65 -0
  40. data/home/jimboadmin/deploy-context/habitat/plan.sh/x86_64-linux/lib/deploy-definitions/deploy-context-cucumber.rb +18 -0
  41. data/home/jimboadmin/deploy-context/habitat/plan.sh/x86_64-linux/lib/deploy-definitions/deploy-context-git.rb +53 -0
  42. data/home/jimboadmin/deploy-context/habitat/plan.sh/x86_64-linux/lib/deploy-definitions/deploy-context-habitat.rb +74 -0
  43. data/home/jimboadmin/deploy-context/habitat/plan.sh/x86_64-linux/lib/deploy-definitions/deploy-context-inspec.rb +29 -0
  44. data/home/jimboadmin/deploy-context/habitat/plan.sh/x86_64-linux/lib/deploy-definitions/deploy-context-kitchen.rb +59 -0
  45. data/home/jimboadmin/deploy-context/habitat/plan.sh/x86_64-linux/lib/deploy-definitions/deploy-context-knife.rb +45 -0
  46. data/home/jimboadmin/deploy-context/habitat/plan.sh/x86_64-linux/lib/deploy-definitions/deploy-context-rake.rb +12 -0
  47. data/home/jimboadmin/deploy-context/habitat/plan.sh/x86_64-linux/lib/deploy-definitions/deploy-context-ruby.rb +10 -0
  48. data/home/jimboadmin/deploy-context/habitat/plan.sh/x86_64-linux/lib/deploy-definitions/deploy-context-supermarket.rb +10 -0
  49. data.tar.gz.sig +0 -0
  50. metadata +47 -2
  51. metadata.gz.sig +0 -0
@@ -0,0 +1,57 @@
1
+ module Context
2
+ module DeployHelpers
3
+ module ChefHelper
4
+ def prepare_workplan
5
+ FileUtils.mkdir 'workstation-space' unless Dir.exist?('workstation-space')
6
+ prepare_chef
7
+ prepare_gem
8
+ prepare_ssh
9
+ prepare_git
10
+ end
11
+
12
+ def prepare_chef
13
+ FileUtils.cp_r '/etc/chef', 'workstation-space/chef-client'
14
+
15
+ chef_user_keys_folder = 'workstation-space/chef_user_keys'
16
+
17
+ FileUtils.mkdir chef_user_keys_folder unless Dir.exist?(chef_user_keys_folder)
18
+
19
+ FileUtils.cp File.join(ENV['HOME'],'.chef/credentials'), 'workstation-space/chef_credentials'
20
+ client_keys = File.read('workstation-space/chef_credentials').split("\n").select do |line_str|
21
+ line_str.include?('client_key')
22
+ end
23
+ client_keys.each do |key_line|
24
+ key_file = key_line.split('=')[1].strip.split("'")[1]
25
+ debug_context_log 'Knife keys', "Copy file #{key_file} to #{chef_user_keys_folder}"
26
+ FileUtils.cp key_file, File.join(chef_user_keys_folder, File.basename(key_file))
27
+ end
28
+ end
29
+
30
+ def prepare_gem
31
+ FileUtils.cp File.join(ENV['HOME'],'.local/share/gem/credentials'), 'workstation-space/gem_credentials'
32
+ end
33
+
34
+ def prepare_ssh
35
+ FileUtils.cp_r File.join(ENV['HOME'],'.ssh'), 'workstation-space/ssh'
36
+ end
37
+
38
+ def prepare_git
39
+ FileUtils.cp File.join(ENV['HOME'],'.gitconfig'), 'workstation-space/gitconfig'
40
+ end
41
+
42
+ def generate_user_json
43
+ warning_context_log 'Habitat origin secrets', JSON.pretty_generate({
44
+ HAB_STUDIO_SECRET_CHEF_SERVER_URL: 'https://api.chef.io/organizations/jimbodragon',
45
+ HAB_STUDIO_SECRET_CHEFVALIDATORKEY: File.read('workstation-space/chef-client/validation.pem'),
46
+ HAB_STUDIO_SECRET_SSHPRIVATEKEY: File.read('workstation-space/ssh/id_rsa'),
47
+ HAB_STUDIO_SECRET_SSHPUBLICKEY: File.read('workstation-space/ssh/id_rsa.pub'),
48
+ HAB_STUDIO_SECRET_CLIENT_NAME: 'jprovencher',
49
+ HAB_STUDIO_SECRET_CLIENT_KEY: File.read('workstation-space/chef_user_keys/jprovencher.pem'),
50
+ HAB_STUDIO_SECRET_GEMAPI: File.read('workstation-space/gem_credentials'),
51
+ HAB_STUDIO_SECRET_EMAIL: 'jimmy.provencher@hotmail.ca',
52
+ HAB_STUDIO_SECRET_FULLNAME: 'Jimmy Provencher'
53
+ })
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,42 @@
1
+ module Context
2
+ module DeployHelpers
3
+ module ContextHelper
4
+ def present_localy?
5
+ Dir.exist?(context_folder)
6
+ end
7
+
8
+ def shorten_version(context)
9
+ context. debug_context_log "Shorten Version", "Getting shorten version #{context.version}"
10
+ context.version.canonical_segments[0..2].join('.')
11
+ end
12
+
13
+ def actual_working_directory?
14
+ Dir.pwd == context_folder
15
+ end
16
+
17
+ def move_folder(folder)
18
+ @context_folder = folder.include?(context_name) ? folder : File.join(folder, context_name)
19
+ end
20
+
21
+ def check_folder(folder)
22
+ FileUtils.mkdir_p(context_folder) unless present_localy?
23
+ end
24
+
25
+ def show_new_version(level)
26
+ context_log "#{level} bump #{context_name} at newer version #{version}"
27
+ end
28
+
29
+ def is_present_publicly?
30
+ ruby_check_if_available_public(self)
31
+ end
32
+
33
+ def new_update_available?
34
+ git_update_available?(self)
35
+ end
36
+
37
+ def ready_for_major_update?
38
+ false
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,121 @@
1
+
2
+ module Context
3
+ module DeployHelpers
4
+ module CookbookHelper
5
+ def bundle_chef(context, commands, command_type = :system)
6
+ context.debug_context_log context.context_name, "Executing chef command #{commands}"
7
+ context.execute_command(%w(chef) + commands, command_type)
8
+ end
9
+
10
+ def chef_exec(context, commands, command_type = :system)
11
+ context.bundle_chef(context, %w(exec) + commands, command_type)
12
+ end
13
+
14
+ def knife(context, commands, command_type = :system)
15
+ context.chef_exec(context, %w(knife) + commands, command_type)
16
+ end
17
+
18
+ def kitchen(context, commands = %w(test), command_type = :system)
19
+ context.execute_command(%w(kitchen) + commands, command_type)
20
+ end
21
+
22
+ def cookbook_path(context)
23
+ File.dirname(context.context_folder)
24
+ end
25
+
26
+ def chef_generate(context, commands)
27
+ context.debug_context_log(context.context_name, "\n\nGenerating Chef components with command #{commands}")
28
+ context.bundle_chef(context, %w(generate) + commands)
29
+ end
30
+
31
+ def generate_cookbook(context, cookbookname)
32
+ context.chef_generate(context, %w(cookbook) + cookbookname)
33
+ end
34
+
35
+ def cookbook_build(context)
36
+ context.debug_context_log(context.context_name, "\n\nBuilding cookbook #{context.context_name}\n\n")
37
+ context.git_build(context)
38
+
39
+ Dir.chdir File.dirname(context.context_folder)
40
+ # context.generate_cookbook(context, [context.context_name]) unless Dir.exist?(context.get_context_file(context, 'recipes'))
41
+
42
+ Dir.chdir context.context_folder
43
+ context.debug_context_log(context.context_name, "\n\nBuilding cookbook #{context.context_name} in path #{Dir.pwd} for folder #{context.context_folder}\n\n")
44
+ context.set_cookbook_version(context)
45
+ end
46
+
47
+ def cookbook_test(context)
48
+ context.cookbook_build(context)
49
+ context.debug_context_log context.context_name, "\n\nExecuting kitchen in folder #{Dir.pwd}\nAnd context #{context.context_name} is created in folder #{context.context_folder} at version #{context.version}"
50
+ context.kitchen(context)
51
+ end
52
+
53
+ def cookbook_test_successful?(context)
54
+ result = cookbook_test(context)
55
+ context.debug_context_log context.context_name, "\n\nCookbook test result: #{result}"
56
+ result
57
+ end
58
+
59
+ def cookbook_install(context)
60
+ cookbook_build(context)
61
+ context.debug_context_log context.context_name, "\n\nInstalling cookbook in folder #{Dir.pwd}\nAnd context #{context.context_name} is created in folder #{context.context_folder} at version #{context.version}"
62
+ context.bundle_chef(context, %w(install))
63
+ end
64
+
65
+ def knife_push(context)
66
+ cookbook_build(context)
67
+ context.debug_context_log context.context_name, "\n\nKnife pushing cookbook in folder #{Dir.pwd}\nAnd context #{context.context_name} is created in folder #{context.context_folder} at version #{context.version}"
68
+ context.knife context, ['cookbook', 'upload', context.context_name, '--cookbook-path', context.cookbook_path(context)]
69
+ end
70
+
71
+ def cookbook_push(context)
72
+ cookbook_build(context)
73
+ context.debug_context_log context.context_name, "\n\nChef pushing cookbook in folder #{Dir.pwd}\nAnd context #{context.context_name} is created in folder #{context.context_folder} at version #{context.version}"
74
+ context.bundle_chef(context, ['push', context.context_name, 'Policyfile.lock.json'])
75
+ end
76
+
77
+ def supermarket_push(context)
78
+ cookbook_build(context)
79
+ context.debug_context_log context.context_name, "\n\nPushing cookbook in folder #{Dir.pwd}\nAnd context #{context.context_name} is created in folder #{context.context_folder} at version #{context.version}"
80
+ context.bundle_chef(context, ['supermarket', 'share', context.context_name, '--cookbook-path', context.cookbook_path(context)])
81
+ end
82
+
83
+ def clean_file(context, file)
84
+ clean_file = context.get_context_file(context, file)
85
+ context.debug_context_log context.context_name, "Clean file #{clean_file}"
86
+ FileUtils.rm(clean_file) if File.exist?(clean_file)
87
+ end
88
+
89
+ def cookbook_clean(context)
90
+ context.cookbook_build(context)
91
+ context.debug_context_log context.context_name, "\n\nCleaning cookbook in folder #{Dir.pwd}\nAnd context #{context.context_name} is created in folder #{context.context_folder} at version #{context.version}"
92
+ context.clean_file(context, 'Policyfile.lock.json')
93
+ end
94
+
95
+ def mix_run_list(context, run_list)
96
+ context.bundle_exec(context, ['chef-client', '-o', run_list])
97
+ end
98
+
99
+ def cookbook_version(context)
100
+ context_version_file = context.get_context_file(context, 'VERSION')
101
+ context_version_file = if File.exist? context_version_file
102
+ context_version_file
103
+ else
104
+ File.join(__dir__, '../../../VERSION')
105
+ end
106
+ context.context_log "context_version_file = #{context_version_file}"
107
+ File.read(context_version_file)
108
+ end
109
+
110
+ def set_cookbook_version(context)
111
+ context.git_build(context)
112
+ if(defined?(GVB))
113
+ File.write(context.get_context_file(context, 'VERSION'), context.shorten_version(context).strip)
114
+ File.write(context.get_context_file(context, 'DATE'), GVB.date)
115
+ else
116
+ context.warning_context_log(context.context_name, "Unable to set the cookbook version as GVB is not defined")
117
+ end
118
+ end
119
+ end
120
+ end
121
+ end
@@ -0,0 +1,42 @@
1
+ module Context
2
+ module DeployHelpers
3
+ module CucumberHelper
4
+ def cucumber_configuration(context, commands)
5
+ context.existing_cucumber_configuration = Cucumber::Cli::Main.new(commands.dup).configuration unless context.existing_cucumber_configuration
6
+ context.existing_cucumber_configuration
7
+ end
8
+
9
+ def cucumber_runtime(context, commands)
10
+ return Cucumber::Runtime.new(context.cucumber_configuration(context, commands)) unless context.existing_cucumber_runtime
11
+
12
+ context.existing_cucumber_runtime.configure(context.cucumber_configuration(context, commands))
13
+ context.existing_cucumber_runtime
14
+ end
15
+
16
+ def cucumber(context, commands = [])
17
+ # begin
18
+ # require 'cucumber'
19
+ # context.existing_cucumber_runtime = context.cucumber_runtime(context, commands)
20
+ # context.cucumber_runtime(context, commands).run!
21
+ # rescue Exception => e
22
+ # context.warning_context_log context.context_name, "Cucumber library not available", "Unable to use internal cucumber, using external application instead for command #{commands}"
23
+ # context.execute_command(%w(chef exec cucumber) + commands)
24
+ # end
25
+ # # context.bundle_exec(context,['cucumber'] + commands)
26
+ context.execute_command(%w(chef exec cucumber) + commands)
27
+ end
28
+
29
+ def cucumber_test(context)
30
+ context.git_build(context)
31
+ context.debug_context_log context.context_name, "Working in folder #{Dir.pwd}\nAnd context #{context.context_name} is created in folder #{context.context_folder} at version #{context.version}"
32
+ context.cucumber(context)
33
+ end
34
+
35
+ def cucumber_test_successful?(context)
36
+ result = cucumber_test(context)
37
+ context.debug_context_log context.context_name, "\n\nCucumber test result: #{result}"
38
+ result
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,83 @@
1
+ module Context
2
+ module DeployHelpers
3
+ module DeployerHelper
4
+ def load_public_dependencies
5
+ require 'rubygems'
6
+ require 'bundler'
7
+ # require 'bundler/setup'
8
+ # require 'bundler/installer'
9
+
10
+ require 'rdoc/task'
11
+
12
+ require 'git-version-bump'
13
+ require 'git-version-bump/rake-tasks'
14
+
15
+ require 'cucumber'
16
+ require 'cucumber/rake/task'
17
+
18
+ require_relative '../../deploy-context'
19
+ end
20
+
21
+ def get_context_file(context, file)
22
+ File.join(context.context_folder, file)
23
+ end
24
+
25
+ def build_folder(context)
26
+ context.get_context_file(context, 'build')
27
+ end
28
+
29
+ def contexts_container(context)
30
+ context.get_context_file(context, 'contexts')
31
+ end
32
+
33
+ def show_help(context)
34
+ help_message = <<MESSAGE_END
35
+ #{
36
+ context.actions_permitted.each do |action|
37
+ puts "Available action '#{action}'"
38
+ end
39
+ }
40
+ Use not option or the option 'cycle' to cycle through the deployer once
41
+ Use the option 'agent' to made a continual loop of the cycle
42
+ Use the option 'bump' to bump the patch version
43
+ Use the option 'release' to bump the minor version
44
+ Use the option 'upgrade' to bump the major version
45
+ Use the option 'test' to test the context
46
+ Use the option 'reset' to execute the local cycle once
47
+ Use the option 'help' to show this message
48
+ MESSAGE_END
49
+ context.warning_context_log(context.context_name, help_message)
50
+ end
51
+
52
+ def actions_permitted?(action)
53
+ context_log "Is Default action '#{action}' permitted?"
54
+ action_is_permit = actions_permitted.include?(action)
55
+
56
+ context_log "The answer is #{action_is_permit} through '#{actions_permitted}'"
57
+ action_is_permit
58
+ end
59
+
60
+ def execute_action(context, action)
61
+ state_action = if action.nil?
62
+ show_help(context)
63
+ false
64
+ else
65
+ if context.respond_to?(action)
66
+ context.debug_context_log(context.context_name, "\n\nStarting Action '#{action}'")
67
+ context.send(action)
68
+ else
69
+ context.error_context_log(context, "Action '#{action}' is unavailable")
70
+ false
71
+ end
72
+ end
73
+ # context.commit
74
+ if state_action || ! state_action.kind_of?(Integer)
75
+ context.debug_context_log context.context_name, "\n\nAction #{action} executed correctly in context #{context}.context_name"
76
+ state_action.perform unless state_action.kind_of?(TrueClass)
77
+ else
78
+ context.error_context_log(context.context_name, "Failed to execute action #{action} in context #{context.context_name} resulting to a #{state_action}")
79
+ end
80
+ end
81
+ end
82
+ end
83
+ end
@@ -0,0 +1,62 @@
1
+ module Context
2
+ module DeployHelpers
3
+ module GitHelper
4
+ def bundle_git(context, commands, command_type = :system)
5
+ context.execute_command(%w(git) + commands, command_type)
6
+ end
7
+
8
+ def git_build(context)
9
+ if context.present_localy?
10
+ Dir.chdir(context.context_folder)
11
+ context.git_pull(context)
12
+ true
13
+ else
14
+ context.error_context_log context.context_name, "Cloning from source in #{Dir.pwd}"
15
+ local_dir = File.join(Dir.pwd, context.context_name)
16
+ context.bundle_git context, ["clone git@github.com:JimboDragonGit/#{context.context_name}.git"] unless ::Dir.exist?(local_dir)
17
+ context.move_folder(local_dir)
18
+ true
19
+ end
20
+ end
21
+
22
+ def git_pull(context)
23
+ context.git_build(context) unless context.actual_working_directory?
24
+ context.debug_context_log context.context_name, "Git pull result: #{context.bundle_git context, %w(pull origin master)}"
25
+ end
26
+
27
+ def git_commit(context)
28
+ context.git_build(context)
29
+ context.bundle_git context, ['add .']
30
+ context.bundle_git context, ["commit -m 'Create #{context.context_name} automatic commit'"]
31
+ end
32
+
33
+ # def git_release(context)
34
+ # context.git_build(context)
35
+ # context.git context, ['push', '--follow-tags']
36
+ # end
37
+
38
+ # def git_bump(context, level)
39
+ # context.git_build(context)
40
+ # context.git context, ['version-bump', level]
41
+ # context.git_commit(context)
42
+ # end
43
+
44
+ # def patch_reset(context)
45
+ # context.git_build(context)
46
+ # context.git_bump(context, 'minor')
47
+ # end
48
+
49
+ def git_update_available?(context)
50
+ context.git_build(context)
51
+ # context.git ['log', "v#{context.version}"]
52
+ context.bundle_git(context, ['ls-remote origin', "v#{context.version}"], :get_data)
53
+ end
54
+
55
+ def git_dirty_state?(context)
56
+ context.git_build(context)
57
+ # context.git ['log', "v#{context.version}"]
58
+ context.bundle_git(context, ["status --porcelain"], :get_data).split('\n').count > 0
59
+ end
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,112 @@
1
+ module Context
2
+ module DeployHelpers
3
+ module HabitatHelper
4
+ def habitat_organisation_name(context)
5
+ context.organisation_name
6
+ end
7
+
8
+ def habitat(context, commands = [], command_type = :system)
9
+ context.bundle_exec(context, ['hab'] + commands, command_type)
10
+ end
11
+
12
+ def intialize_habitat(context, commands = [], command_type = :system)
13
+ context.habitat(context, ['plan', 'init'] + commands, command_type)
14
+ end
15
+
16
+ def render_habitat(context, commands = [], command_type = :system)
17
+ context.habitat(context, ['plan', 'render'] + commands, command_type)
18
+ end
19
+
20
+ def build_habitat(context, commands = [], command_type = :system)
21
+ context.habitat(context, ['studio', 'build', 'habitat/plan.sh'] + commands, command_type)
22
+ end
23
+
24
+ def start_habitat_job(context, commands = [], command_type = :system)
25
+ context.debug_context_log(context.context_name, "Starting an Habitat job #{context.get_shell_data(['hab', 'bldr', 'job', 'start', 'habitat/plan.sh'])}", command_type)
26
+ true
27
+ end
28
+
29
+ def promote_habitat(context, job_id = File.read(get_context_file(context, 'HAB_BUILD_ID')), channel = 'unstable')
30
+ if ! context.already_promoted?(context) && context.latest_hab_build_succeed?(context)
31
+ context.set_hab_build_id(context, context.hab_latest_build_status(context).id)
32
+ context.habitat(context, ['bldr', 'job', 'promote', job_id, channel])
33
+ else
34
+ context.error_context_log(context.context_name, "Promote context #{context.context_name} impossible")
35
+ end
36
+ end
37
+
38
+ def load_habitat(context, commands = [], command_type = :system)
39
+ supervisor_command = %w(hab svc load) + ["#{habitat_organisation_name(context)}/#{context.context_name}", '--strategy at-once']
40
+ if context.is_admin?
41
+ context.habitat(context, supervisor_command + commands, command_type)
42
+ else
43
+ context.execute_command(%w(sudo hab) + supervisor_command + commands, command_type) unless Gem.win_platform?
44
+ end
45
+ end
46
+
47
+ def run_habitat_supervisor(context, commands = [], command_type = :system)
48
+ supervisor_command = %w(sup run)
49
+ if context.is_admin?
50
+ context.habitat(context, supervisor_command + commands, command_type)
51
+ else
52
+ context.execute_command(%w(sudo hab) + supervisor_command + commands, command_type) unless Gem.win_platform?
53
+ end
54
+ end
55
+
56
+ def install_habitat_supervisor(context, commands = [], command_type = :system)
57
+ supervisor_command = %w(sup run)
58
+ if context.is_admin?
59
+ context.habitat(context, supervisor_command + commands, command_type)
60
+ else
61
+ context.execute_command(%w(sudo hab) + supervisor_command + commands, command_type) unless Gem.win_platform?
62
+ end
63
+ end
64
+
65
+ def hab_latest_build_status(context)
66
+ build_result = OpenStruct.new
67
+ build_result.command = [
68
+ 'hab bldr job status',
69
+ '--showjobs -l 25 --origin',
70
+ context.organisation_name,
71
+ "| grep '#{context.context_name}' | head -n 1",
72
+ ]
73
+ # build_result.result_file = File.join(context.temp_dir, 'raw_return.txt')
74
+ # context.debug_context_log context.context_name, "Getting data from command #{build_result.command} and result at #{build_result.result_file}"
75
+ # File.write(build_result.result_file, context.get_shell_data(build_result.command))
76
+ # build_result.build_id_raw = "#{File.read(build_result.result_file)}"
77
+ # context.debug_context_log context.context_name, "And raw return from file is #{build_result.build_id_raw}"
78
+ # build_result.return_arr = build_result.build_id_raw.split("\n")
79
+ # context.debug_context_log context.context_name, "And return array is #{build_result.return_arr}"
80
+ # build_result.return_str = build_result.return_arr[3]
81
+ # context.debug_context_log context.context_name, "And return string is #{build_result.return_str}"
82
+ # build_result.result_arr = build_result.return_str.split(' ')
83
+ # context.debug_context_log context.context_name, "And result array is #{build_result.result_arr}"
84
+
85
+ result_array = context.get_shell_data(build_result.command).split("\n")[0].split(' ')
86
+ build_result.id = result_array[1]
87
+ build_result.status = result_array[2]
88
+ build_result
89
+ end
90
+
91
+ def hab_build_id(context)
92
+ File.read(context.get_context_file(context, 'HAB_BUILD_ID'))
93
+ end
94
+
95
+ def already_promoted?(context)
96
+ context.hab_latest_build_status(context).id == context.hab_build_id(context)
97
+ end
98
+
99
+ def latest_hab_build_succeed?(context)
100
+ context.hab_latest_build_status(context).status == 'Complete'
101
+ end
102
+
103
+ def set_hab_build_id(context, new_build_id)
104
+ context.git_build(context)
105
+ # , "#{organisation_name}/#{context_name}"
106
+ context.debug_context_log context.context_name, "Setting the build ID from #{context.hab_build_id(context)} to #{new_build_id}"
107
+
108
+ File.write(context.get_context_file(context, 'HAB_BUILD_ID'), new_build_id)
109
+ end
110
+ end
111
+ end
112
+ end
@@ -0,0 +1,138 @@
1
+ module Context
2
+ module DeployHelpers
3
+ module RubyHelper
4
+ def bundle(context, commands, command_type = :system)
5
+ context.debug_context_log context.context_name, "Executing chef command #{commands}"
6
+ context.execute_command(%w(bundle) + commands, command_type)
7
+ end
8
+
9
+ def bundle_exec(context, commands, command_type = :system)
10
+ context.bundle(context, %w(exec) + commands, command_type)
11
+ end
12
+
13
+ def bundle_install(context, commands, command_type = :system)
14
+ context.bundle(context, %w(install) + commands, command_type)
15
+ end
16
+
17
+ def bundle_gem(context, commands, command_type = :system)
18
+ context.execute_command(%w(gem) + commands, command_type)
19
+ end
20
+
21
+ def bundle_rake(context, commands = [], command_type = :system)
22
+ context.execute_command(%w(rake) + commands, command_type)
23
+ end
24
+
25
+ def ruby_build(context)
26
+ context.git_build(context)
27
+ context.debug_context_log context.context_name, "Working in folder #{Dir.pwd}\nAnd context #{context.context_name} is created"
28
+ check_folder get_context_file(context, 'build')
29
+ end
30
+
31
+ def ruby_release(context)
32
+ context.git_build(context)
33
+ # gem ["push #{context.context_name}-#{GVB.version}.gem"]
34
+ # context.patch_bump if gem_installed?(context, context.context_name)
35
+ context.bundle_rake context, ['release']
36
+ # context.commit
37
+ end
38
+
39
+ def ruby_install(context)
40
+ context.bundle_gem context, ['install', context.context_name]
41
+ end
42
+
43
+ def clean_folder(context, folder)
44
+ clean_folder = context.get_context_file(context, folder)
45
+ puts "Clean folder #{clean_folder}"
46
+ FileUtils.remove_dir(clean_folder) if Dir.exist?(clean_folder)
47
+ end
48
+
49
+ def ruby_clean(context)
50
+ context.bundle_gem('cleanup')
51
+ context.clean_folder(context, 'pkg')
52
+ end
53
+
54
+ def ruby_remove_gem(context)
55
+ context.bundle_gem(['remove', context.context_name])
56
+ end
57
+
58
+ def ruby_check_if_available_public(context)
59
+ context.context_log "Waiting a minute before installing #{context.context_name} in folder #{context.context_folder}"
60
+ `chef gem list #{context.context_name}`
61
+ # sleep(60)
62
+ end
63
+
64
+ def gem_available?(context, gemname, compare_version = nil)
65
+ begin
66
+ available_version = Gem::Specification.find_by_name(gemname)
67
+ rescue Gem::MissingSpecError => e
68
+ context.error_context_log(context, "The gem '#{gemname}' is missing")
69
+ # sleep(5)
70
+ available_version = nil
71
+ rescue Exception => e
72
+ context.error_context_log(context, "The gem '#{gemname}' got issue with #{e}")
73
+ sleep(5)
74
+ available_version = nil
75
+ end
76
+ # context.debug_context_log(context.context_name, "Compare #{context.context_name} available_version #{available_version} with #{context.version} in folder #{context.context_folder}")
77
+ available = if compare_version.nil? || available_version.nil?
78
+ not available_version.nil?
79
+ else
80
+ available_version.version == context.version
81
+ end
82
+ puts "available = #{available}"
83
+ available
84
+ end
85
+
86
+ def gem_installed?(context, gemname, compare_version = nil)
87
+ gem_list = context.bundle_gem(context, ['list', gemname, "| grep #{gemname}"], :get_data)
88
+ context.debug_context_log context.context_name, "gemlist = #{gem_list}"
89
+ is_installed = gem_list.include?(gemname)
90
+ is_correct_version = gem_list.split(',').detect do |gem_app|
91
+ gem_app.include?(gemname)
92
+ end
93
+ context.debug_context_log context.context_name, "is_correct_version = #{is_correct_version}"
94
+ is_correct_version.include?(gemname)
95
+ end
96
+
97
+ def load_dependency(context, gemname, require_file)
98
+ context.gem(context, ['install', gemname]) unless context.gem_installed?(context, gemname)
99
+ context.debug_context_log(context.context_name, "Loading file #{require_file} for gem #{gemname}")
100
+ sleep 3
101
+ require require_file
102
+ end
103
+
104
+ def load_all_dependencies(context)
105
+ context.load_dependencies
106
+ end
107
+
108
+ def ruby_cycle(context)
109
+ context.debug_context_log context.context_name, "\n\nBuilding Ruby application for #{context.context_name}"
110
+ if context.new_update_available?
111
+ context.debug_context_log context.context_name, "\n\nNew update available for #{context.context_name}\nCleaning the building space"
112
+ context.clean
113
+ # if git_dirty_state?(context)
114
+ # context.patch_bump
115
+ # context.commit
116
+ # end
117
+ context.debug_context_log context.context_name, "\n\nBuilding project #{context.context_name} now ..."
118
+ context.build
119
+ # context.commit
120
+ context.debug_context_log context.context_name, "\n\nReleasing project #{context.context_name}"
121
+ context.release
122
+ context.wait_until_release_available
123
+ context.debug_context_log context.context_name, "\n\nInstalling project #{context.context_name}"
124
+ context.install
125
+ if context.test_context_successful?
126
+ context.debug_context_log context.context_name, "newer version installed successfully for #{context.context_name} on version #{context.version}"
127
+ # context.patch_bump
128
+ # patch_reset(context)
129
+ else
130
+ context.debug_context_log context.context_name, "newer version not installed for #{context.context_name} on version #{context.version}"
131
+ end
132
+ else
133
+ context.debug_context_log context.context_name, "No update available"
134
+ end
135
+ end
136
+ end
137
+ end
138
+ end
@@ -0,0 +1,7 @@
1
+ module Context
2
+ module VagrantHelper
3
+ def delete_vagrant_box(context, box_name, command_type = :system)
4
+ context.execute_command(%w(vagrant box remove ) + [box_name], command_type)
5
+ end
6
+ end
7
+ end