deploy-context 2.2.0.3.gec16643.4.g20d2d42.4.g17e8559.12.g831d0a8.4.gbb2ab14.12.g0bc028d → 2.13.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/bin/deploy-context +3 -1
- data/libraries/context-manager.rb +103 -6
- data/libraries/deploy-context/cookbook-studio.rb +43 -0
- data/libraries/deploy-context/cucumber-studio.rb +9 -0
- data/libraries/deploy-context/default-studio.rb +58 -0
- data/libraries/deploy-context/deploy/context.rb +0 -70
- data/libraries/deploy-context/deploy/cookbook.rb +20 -4
- data/libraries/deploy-context/deploy/cucumber.rb +7 -3
- data/libraries/deploy-context/deploy/deployer.rb +20 -38
- data/libraries/deploy-context/deploy/git.rb +16 -14
- data/libraries/deploy-context/deploy/habitat.rb +112 -0
- data/libraries/deploy-context/deploy/ruby.rb +34 -9
- data/libraries/deploy-context/habitat-studio.rb +38 -0
- data/libraries/deploy-context/helpers/command.rb +7 -4
- data/libraries/deploy-context/helpers/rake_tasks.rb +143 -39
- data/libraries/deploy-context/ruby-studio.rb +24 -0
- data/libraries/deploy-context/steps/deploy.rb +53 -0
- data/libraries/deploy-context/studio/base.rb +155 -0
- data/libraries/deploy-context/studio/default.rb +65 -0
- data/libraries/deploy-context/studio/deployer.rb +20 -0
- data/libraries/deploy-context.rb +9 -13
- data.tar.gz.sig +0 -0
- metadata +184 -29
- metadata.gz.sig +0 -0
- data/.gitignore +0 -25
- data/.kitchen/logs/kitchen.log +0 -149
- data/CHANGELOG.md +0 -10
- data/Gemfile +0 -3
- data/Policyfile.rb +0 -16
- data/Rakefile +0 -3
- data/VERSION +0 -1
- data/chefignore +0 -115
- data/compliance/README.md +0 -25
- data/config/cucumber.yml +0 -5
- data/deploy-context.gemspec +0 -69
- data/features/code_update.feature +0 -13
- data/features/step_definitions/deploy-context.rb +0 -2
- data/features/support/env.rb +0 -6
- data/features/update_deployer.feature +0 -10
- data/features/updated_git.feature +0 -10
- data/kitchen.yml +0 -31
- data/libraries/deploy-context/deploy.rb +0 -36
- data/libraries/deploy-context/helpers/binary.rb +0 -7
- data/libraries/deploy-context/step_definitions/deploy-context.rb +0 -39
- data/metadata.rb +0 -23
- data/recipes/default.rb +0 -8
- data/test/integration/default/default_test.rb +0 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '08c8c739173724f9a7dda28787085273acb385fd70d56968f3f026920e5f03ea'
|
4
|
+
data.tar.gz: 49b9d0954862b99645578d67a35a67a5308f19905249ef9775755b495bd8ffd2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9d81e5c113c71186b685e2e220fe5986b89666eeadcc24f0c2d79fa8bad2e5f3e98902f64e8a5806ac415277b5188d5931486e390edaa88fbb040aabed35d5ef
|
7
|
+
data.tar.gz: b003f2b7fee9374c14f8898646b4eba2e10968bb4bc3ea41a0035a5efb2f1f4281ab81cc8d50b7f600e7c52c52c852bcb0d29323546bcaf587811e01a69f5438
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/bin/deploy-context
CHANGED
@@ -1,11 +1,108 @@
|
|
1
|
+
|
2
|
+
require_relative 'deploy-context/habitat-studio'
|
3
|
+
|
1
4
|
module Context
|
2
|
-
class Manager
|
3
|
-
attr_reader :
|
5
|
+
class Manager < HabitatStudio
|
6
|
+
attr_reader :contexts
|
7
|
+
|
8
|
+
def initialize(organisation_name, context_name, deploycontext_folder)
|
9
|
+
super(organisation_name, context_name, deploycontext_folder)
|
10
|
+
|
11
|
+
@contexts = Array.new
|
4
12
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
13
|
+
abort("No context_name :(") if context_name.nil? || context_name.empty?
|
14
|
+
end
|
15
|
+
|
16
|
+
# 2
|
17
|
+
def do_download
|
18
|
+
super
|
19
|
+
contexts.each do |context|
|
20
|
+
context.do_download
|
21
|
+
end
|
22
|
+
true
|
23
|
+
end
|
24
|
+
|
25
|
+
# 3
|
26
|
+
def do_verify
|
27
|
+
super
|
28
|
+
contexts.each do |context|
|
29
|
+
context.do_verify
|
30
|
+
end
|
31
|
+
true
|
32
|
+
end
|
33
|
+
|
34
|
+
# 4
|
35
|
+
def do_clean
|
36
|
+
super
|
37
|
+
contexts.each do |context|
|
38
|
+
context.do_clean
|
39
|
+
end
|
40
|
+
true
|
41
|
+
end
|
42
|
+
|
43
|
+
# 5
|
44
|
+
def do_unpack
|
45
|
+
super
|
46
|
+
contexts.each do |context|
|
47
|
+
context.do_unpack
|
48
|
+
end
|
49
|
+
true
|
50
|
+
end
|
51
|
+
|
52
|
+
# 6
|
53
|
+
def do_prepare
|
54
|
+
super
|
55
|
+
contexts.each do |context|
|
56
|
+
context.do_prepare
|
57
|
+
end
|
58
|
+
true
|
59
|
+
end
|
60
|
+
|
61
|
+
# 7
|
62
|
+
def do_build
|
63
|
+
super
|
64
|
+
contexts.each do |context|
|
65
|
+
context.do_build
|
66
|
+
end
|
67
|
+
true
|
68
|
+
end
|
69
|
+
|
70
|
+
# 8
|
71
|
+
def do_check
|
72
|
+
super
|
73
|
+
contexts.each do |context|
|
74
|
+
context.do_check
|
75
|
+
end
|
76
|
+
true
|
77
|
+
end
|
78
|
+
|
79
|
+
# 9
|
80
|
+
def do_install
|
81
|
+
super
|
82
|
+
contexts.each do |context|
|
83
|
+
context.do_install
|
84
|
+
end
|
85
|
+
true
|
86
|
+
end
|
87
|
+
|
88
|
+
# 10
|
89
|
+
def do_strip
|
90
|
+
super
|
91
|
+
def do_install
|
92
|
+
contexts.each do |context|
|
93
|
+
context.do_strip
|
94
|
+
end
|
95
|
+
true
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
# 11
|
100
|
+
def do_end
|
101
|
+
super
|
102
|
+
contexts.each do |context|
|
103
|
+
context.do_end
|
104
|
+
end
|
105
|
+
true
|
9
106
|
end
|
10
107
|
end
|
11
108
|
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require_relative 'cucumber-studio'
|
2
|
+
|
3
|
+
module Context
|
4
|
+
class CookbookStudio < CucumberStudio
|
5
|
+
def initialize(organisation_name, context_name, deploycontext_folder)
|
6
|
+
super(organisation_name, context_name, deploycontext_folder)
|
7
|
+
end
|
8
|
+
|
9
|
+
# 7
|
10
|
+
def do_build
|
11
|
+
super
|
12
|
+
cookbook_build(self)
|
13
|
+
true
|
14
|
+
end
|
15
|
+
|
16
|
+
# 8
|
17
|
+
def do_check
|
18
|
+
super
|
19
|
+
cookbook_test(self)
|
20
|
+
true
|
21
|
+
end
|
22
|
+
|
23
|
+
# 9
|
24
|
+
def do_install
|
25
|
+
super
|
26
|
+
cookbook_install(self)
|
27
|
+
true
|
28
|
+
end
|
29
|
+
|
30
|
+
def do_strip
|
31
|
+
super
|
32
|
+
cookbook_push(self)
|
33
|
+
true
|
34
|
+
end
|
35
|
+
|
36
|
+
def do_end
|
37
|
+
super
|
38
|
+
cookbook_result = do_mix_cookbook
|
39
|
+
log "Mix the cookbook #{context_name}: #{cookbook_result.class}"
|
40
|
+
true
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require_relative 'helpers/command'
|
2
|
+
require_relative 'helpers/rake_tasks'
|
3
|
+
|
4
|
+
require_relative 'deploy/context'
|
5
|
+
require_relative 'deploy/cookbook'
|
6
|
+
require_relative 'deploy/cucumber'
|
7
|
+
require_relative 'deploy/deployer'
|
8
|
+
require_relative 'deploy/git'
|
9
|
+
require 'rubygems'
|
10
|
+
require 'bundler'
|
11
|
+
require 'fileutils'
|
12
|
+
require 'json'
|
13
|
+
|
14
|
+
require_relative 'deploy/context'
|
15
|
+
require_relative 'deploy/cookbook'
|
16
|
+
require_relative 'deploy/cucumber'
|
17
|
+
require_relative 'deploy/deployer'
|
18
|
+
require_relative 'deploy/git'
|
19
|
+
require_relative 'deploy/habitat'
|
20
|
+
require_relative 'deploy/ruby'
|
21
|
+
require_relative 'deploy/vagrant'
|
22
|
+
|
23
|
+
require_relative 'studio/default'
|
24
|
+
require_relative 'studio/deployer'
|
25
|
+
|
26
|
+
require_relative 'helpers/command'
|
27
|
+
require_relative 'helpers/rake_tasks'
|
28
|
+
|
29
|
+
require_relative 'steps/deploy'
|
30
|
+
|
31
|
+
module Context
|
32
|
+
class DefaultStudio
|
33
|
+
include CommandHelper
|
34
|
+
include DeployHelpers::DeployerHelper
|
35
|
+
include DeployHelpers::GitHelper
|
36
|
+
include DeployHelpers::RubyHelper
|
37
|
+
include DeployHelpers::ContextHelper
|
38
|
+
include DeployHelpers::CookbookHelper
|
39
|
+
include DeployHelpers::HabitatHelper
|
40
|
+
include Studio::Base
|
41
|
+
include Studio::Default
|
42
|
+
include Steps::Deploy
|
43
|
+
|
44
|
+
attr_reader :context_name
|
45
|
+
attr_reader :context_folder
|
46
|
+
|
47
|
+
attr_accessor :existing_cucumber_runtime
|
48
|
+
attr_accessor :existing_cucumber_configuration
|
49
|
+
|
50
|
+
attr_reader :organisation_name
|
51
|
+
|
52
|
+
def initialize(organisation_name, context_name, deploycontext_folder)
|
53
|
+
@context_name = context_name
|
54
|
+
@context_folder = deploycontext_folder # move_folder(deploycontext_folder)
|
55
|
+
@organisation_name = organisation_name
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -21,80 +21,10 @@ module Context
|
|
21
21
|
FileUtils.mkdir_p(context_folder) unless present_localy?
|
22
22
|
end
|
23
23
|
|
24
|
-
def version
|
25
|
-
git_build(self)
|
26
|
-
log "Getting version info for #{context_folder} and version should be #{GitVersionBump.version(true)}"
|
27
|
-
Gem::Version.new(GitVersionBump.version(true))
|
28
|
-
end
|
29
|
-
|
30
|
-
def cycle
|
31
|
-
ruby_cycle(self)
|
32
|
-
end
|
33
|
-
|
34
|
-
def test_context_successful?
|
35
|
-
log "Check if #{context_name} is install #{version}"
|
36
|
-
if gem_installed?(self)
|
37
|
-
log "Test context #{context_name} was successfully install on version #{version}"
|
38
|
-
true
|
39
|
-
else
|
40
|
-
log "Test context #{context_name} has failed to install #{version}"
|
41
|
-
false
|
42
|
-
end
|
43
|
-
cookbook_test(self)
|
44
|
-
cucumber_test(self)
|
45
|
-
end
|
46
|
-
|
47
|
-
def build
|
48
|
-
ruby_build(self)
|
49
|
-
cookbook_build(self)
|
50
|
-
check_folder get_context_file(self, 'contexts')
|
51
|
-
end
|
52
|
-
|
53
|
-
def commit
|
54
|
-
git_commit(self)
|
55
|
-
cookbook_install(self)
|
56
|
-
end
|
57
|
-
|
58
|
-
def release
|
59
|
-
log "\n\nRelease #{context_name} at version #{version}"
|
60
|
-
cookbook_push(self)
|
61
|
-
ruby_release(self)
|
62
|
-
git_release(self)
|
63
|
-
end
|
64
|
-
|
65
|
-
def install
|
66
|
-
ruby_install(self)
|
67
|
-
end
|
68
|
-
|
69
|
-
def clean
|
70
|
-
clean_folder(self, 'contexts')
|
71
|
-
ruby_clean(self)
|
72
|
-
cookbook_clean(self)
|
73
|
-
end
|
74
|
-
|
75
24
|
def show_new_version(level)
|
76
25
|
log "#{level} bump #{context_name} at newer version #{version}"
|
77
26
|
end
|
78
27
|
|
79
|
-
def patch_bump
|
80
|
-
GitVersionBump.tag_version("#{GitVersionBump.major_version(true)}.#{GitVersionBump.minor_version(true)}.#{GitVersionBump.patch_version(true) + 1}")
|
81
|
-
show_new_version('Patch')
|
82
|
-
end
|
83
|
-
|
84
|
-
def minor_bump
|
85
|
-
GitVersionBump.tag_version("#{GitVersionBump.major_version(true)}.#{GitVersionBump.minor_version(true) + 1}.0")
|
86
|
-
show_new_version('Minor')
|
87
|
-
end
|
88
|
-
|
89
|
-
def major_bump
|
90
|
-
GitVersionBump.tag_version("#{GitVersionBump.major_version(true) + 1}.0.0")
|
91
|
-
show_new_version('Major')
|
92
|
-
end
|
93
|
-
|
94
|
-
def wait_until_release_available
|
95
|
-
wait_until_release_available unless is_present_publicly?
|
96
|
-
end
|
97
|
-
|
98
28
|
def is_present_publicly?
|
99
29
|
ruby_check_if_available_public(self)
|
100
30
|
end
|
@@ -2,6 +2,7 @@ module Context
|
|
2
2
|
module DeployHelpers
|
3
3
|
module CookbookHelper
|
4
4
|
def chef(context, commands)
|
5
|
+
context.log "Executing chef command #{commands}"
|
5
6
|
context.execute_command(%w(chef) + commands)
|
6
7
|
end
|
7
8
|
|
@@ -34,7 +35,7 @@ module Context
|
|
34
35
|
context.log("\n\nBuilding cookbook #{context.context_name}\n\n")
|
35
36
|
context.git_build(context)
|
36
37
|
Dir.chdir File.dirname(context.context_folder)
|
37
|
-
context.generate_cookbook(context, [context.context_name])
|
38
|
+
context.generate_cookbook(context, [context.context_name]) unless Dir.exist?(context.get_context_file(context, 'recipes'))
|
38
39
|
context.set_cookbook_version(context)
|
39
40
|
Dir.chdir context.context_folder
|
40
41
|
end
|
@@ -45,6 +46,12 @@ module Context
|
|
45
46
|
context.kitchen(context)
|
46
47
|
end
|
47
48
|
|
49
|
+
def cookbook_test_successful?(context)
|
50
|
+
result = cookbook_test(context)
|
51
|
+
context.log "\n\nCookbook test result: #{result}"
|
52
|
+
result
|
53
|
+
end
|
54
|
+
|
48
55
|
def cookbook_install(context)
|
49
56
|
cookbook_build(context)
|
50
57
|
context.log "\n\nInstalling cookbook in folder #{Dir.pwd}\nAnd context #{context.context_name} is created in folder #{context.context_folder} at version #{context.version}"
|
@@ -66,19 +73,28 @@ module Context
|
|
66
73
|
|
67
74
|
def clean_file(context, file)
|
68
75
|
clean_file = context.get_context_file(context, file)
|
69
|
-
|
76
|
+
context.log "Clean file #{clean_file}"
|
70
77
|
FileUtils.rm(clean_file) if File.exist?(clean_file)
|
71
78
|
end
|
72
79
|
|
73
80
|
def cookbook_clean(context)
|
74
|
-
cookbook_build(context)
|
81
|
+
context.cookbook_build(context)
|
75
82
|
context.log "\n\nCleaningcookbook in folder #{Dir.pwd}\nAnd context #{context.context_name} is created in folder #{context.context_folder} at version #{context.version}"
|
76
|
-
clean_file(context, 'Policyfile.lock.json')
|
83
|
+
context.clean_file(context, 'Policyfile.lock.json')
|
84
|
+
end
|
85
|
+
|
86
|
+
def mix_run_list(context, run_list)
|
87
|
+
context.execute_command(['chef-client', '-o', run_list])
|
88
|
+
end
|
89
|
+
|
90
|
+
def cookbook_version(context)
|
91
|
+
File.write(context.get_context_file(context, 'VERSION'))
|
77
92
|
end
|
78
93
|
|
79
94
|
def set_cookbook_version(context)
|
80
95
|
context.git_build(context)
|
81
96
|
File.write(context.get_context_file(context, 'VERSION'), context.shorten_version(context).strip)
|
97
|
+
File.write(context.get_context_file(context, 'DATE'), GVB.date)
|
82
98
|
end
|
83
99
|
end
|
84
100
|
end
|
@@ -14,11 +14,9 @@ module Context
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def cucumber(context, commands = [])
|
17
|
-
# context.chef_exec(context,['cucumber'] + commands)
|
18
|
-
|
19
17
|
context.existing_cucumber_runtime = cucumber_runtime(context, commands)
|
20
|
-
# The dup is to keep ARGV intact, so that tools like ruby-debug can respawn.
|
21
18
|
cucumber_runtime(context, commands).run!
|
19
|
+
# context.chef_exec(context,['cucumber'] + commands)
|
22
20
|
end
|
23
21
|
|
24
22
|
def cucumber_test(context)
|
@@ -26,6 +24,12 @@ module Context
|
|
26
24
|
context.log "Working in folder #{Dir.pwd}\nAnd context #{context.context_name} is created in folder #{context.context_folder} at version #{context.version}"
|
27
25
|
context.cucumber(context)
|
28
26
|
end
|
27
|
+
|
28
|
+
def cucumber_test_successful?(context)
|
29
|
+
result = cucumber_test(context)
|
30
|
+
context.log "\n\nCucumber test result: #{result}"
|
31
|
+
result
|
32
|
+
end
|
29
33
|
end
|
30
34
|
end
|
31
35
|
end
|
@@ -15,6 +15,11 @@ module Context
|
|
15
15
|
|
16
16
|
def show_help(context)
|
17
17
|
help_message = <<MESSAGE_END
|
18
|
+
#{
|
19
|
+
context.actions_permitted.each do |action|
|
20
|
+
puts "Available action '#{action}'"
|
21
|
+
end
|
22
|
+
}
|
18
23
|
Use not option or the option 'cycle' to cycle through the deployer once
|
19
24
|
Use the option 'agent' to made a continual loop of the cycle
|
20
25
|
Use the option 'bump' to bump the patch version
|
@@ -27,56 +32,33 @@ MESSAGE_END
|
|
27
32
|
context.error_log(context.context_name, help_message)
|
28
33
|
end
|
29
34
|
|
35
|
+
def actions_permitted?(action)
|
36
|
+
log "Is Default action '#{action}' permitted?"
|
37
|
+
action_is_permit = actions_permitted.include?(action)
|
38
|
+
|
39
|
+
log "The answer is #{action_is_permit} through '#{actions_permitted}'"
|
40
|
+
action_is_permit
|
41
|
+
end
|
42
|
+
|
30
43
|
def execute_action(context, action)
|
31
44
|
state_action = if action.nil?
|
32
45
|
show_help(context)
|
33
46
|
false
|
34
47
|
else
|
35
|
-
|
36
|
-
|
37
|
-
context.
|
38
|
-
context.cycle
|
39
|
-
true
|
40
|
-
when 'agent'
|
41
|
-
context.log "\nAlways in execution\n"
|
42
|
-
while true do
|
43
|
-
context.cycle
|
44
|
-
end
|
45
|
-
true
|
46
|
-
when 'bump'
|
47
|
-
context.log "\nBump minor version\n"
|
48
|
-
context.patch_bump
|
49
|
-
true
|
50
|
-
when 'release'
|
51
|
-
context.log "\nBump major version\n"
|
52
|
-
context.minor_bump
|
53
|
-
true
|
54
|
-
when 'upgrade'
|
55
|
-
context.log "\nBump major version\n"
|
56
|
-
context.major_bump
|
57
|
-
true
|
58
|
-
when 'test'
|
59
|
-
context.log "\nExecute tests\n"
|
60
|
-
context.test_context_successful?
|
61
|
-
when 'reset'
|
62
|
-
context.log "\nReset versionning\n"
|
63
|
-
system('rake')
|
64
|
-
# context.cucumber_test(deployer)
|
65
|
-
true
|
66
|
-
when 'help'
|
67
|
-
context.show_help(context)
|
68
|
-
true
|
48
|
+
if context.respond_to?(action)
|
49
|
+
context.log("\n\nStarting Action '#{action}'")
|
50
|
+
context.send(action)
|
69
51
|
else
|
70
|
-
context.error_log
|
71
|
-
show_help(context)
|
52
|
+
context.error_log(context, "Action '#{action}' is unavailable")
|
72
53
|
false
|
73
54
|
end
|
74
55
|
end
|
75
|
-
context.commit
|
56
|
+
# context.commit
|
76
57
|
if state_action
|
77
58
|
context.log "\n\nAction #{action} executed correctly in context #{context}"
|
59
|
+
state_action.perform unless state_action.kind_of?(TrueClass) || state_action.kind_of?(Integer)
|
78
60
|
else
|
79
|
-
context.error_log(context.context_name, "Failed to execute action #{action} in context #{context}")
|
61
|
+
context.error_log(context.context_name, "Failed to execute action #{action} in context #{context.context_name} resulting to a #{state_action}")
|
80
62
|
end
|
81
63
|
end
|
82
64
|
end
|
@@ -9,17 +9,19 @@ module Context
|
|
9
9
|
if context.present_localy?
|
10
10
|
Dir.chdir(context.context_folder)
|
11
11
|
context.git_pull(context)
|
12
|
+
true
|
12
13
|
else
|
13
14
|
context.error_log context.context_name, "Cloning from source in #{Dir.pwd}"
|
14
15
|
local_dir = File.join(Dir.pwd, context.context_name)
|
15
16
|
context.git context, ["clone git@github.com:JimboDragonGit/#{context.context_name}.git"] unless ::Dir.exist?(local_dir)
|
16
17
|
context.move_folder(local_dir)
|
18
|
+
true
|
17
19
|
end
|
18
20
|
end
|
19
21
|
|
20
22
|
def git_pull(context)
|
21
23
|
context.git_build(context) unless context.actual_working_directory?
|
22
|
-
context.git context, %w(pull)
|
24
|
+
log "Git pull result: #{context.git context, %w(pull)}"
|
23
25
|
end
|
24
26
|
|
25
27
|
def git_commit(context)
|
@@ -28,21 +30,21 @@ module Context
|
|
28
30
|
context.git context, ["commit -m 'Create #{context.context_name} automatic commit'"]
|
29
31
|
end
|
30
32
|
|
31
|
-
def git_release(context)
|
32
|
-
|
33
|
-
|
34
|
-
end
|
33
|
+
# def git_release(context)
|
34
|
+
# context.git_build(context)
|
35
|
+
# context.git context, ['push', '--follow-tags']
|
36
|
+
# end
|
35
37
|
|
36
|
-
def git_bump(context, level)
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
end
|
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
|
41
43
|
|
42
|
-
def patch_reset(context)
|
43
|
-
|
44
|
-
|
45
|
-
end
|
44
|
+
# def patch_reset(context)
|
45
|
+
# context.git_build(context)
|
46
|
+
# context.git_bump(context, 'minor')
|
47
|
+
# end
|
46
48
|
|
47
49
|
def git_update_available?(context)
|
48
50
|
context.git_build(context)
|
@@ -0,0 +1,112 @@
|
|
1
|
+
module Context
|
2
|
+
module DeployHelpers
|
3
|
+
module HabitatHelper
|
4
|
+
def habitat_organisation_name(context)
|
5
|
+
'jimbodragon'
|
6
|
+
end
|
7
|
+
|
8
|
+
def habitat(context, commands = [])
|
9
|
+
context.chef_exec(context, ['hab'] + commands)
|
10
|
+
end
|
11
|
+
|
12
|
+
def intialize_habitat(context, commands = [])
|
13
|
+
context.habitat(context, ['plan', 'init'] + commands)
|
14
|
+
end
|
15
|
+
|
16
|
+
def render_habitat(context, commands = [])
|
17
|
+
context.habitat(context, ['plan', 'render'] + commands)
|
18
|
+
end
|
19
|
+
|
20
|
+
def build_habitat(context, commands = [])
|
21
|
+
context.habitat(context, ['studio', 'build', 'habitat/plan.sh'] + commands)
|
22
|
+
context.set_hab_build_id(context)
|
23
|
+
end
|
24
|
+
|
25
|
+
def start_habitat_job(context, commands = [])
|
26
|
+
context.log("Starting an Habitat job #{context.get_shell_data(['hab', 'bldr', 'job', 'start', 'habitat/plan.sh'])}")
|
27
|
+
true
|
28
|
+
end
|
29
|
+
|
30
|
+
def promote_habitat(context, job_id = File.read(get_context_file(context, 'HAB_BUILD_ID')), channel = 'unstable')
|
31
|
+
if ! context.already_promoted?(context) && context.latest_hab_build_succeed?(context)
|
32
|
+
context.habitat(context, ['bldr', 'job', 'promote', job_id, channel])
|
33
|
+
else
|
34
|
+
context.error_log(context, "Promote context #{context.context_name} impossible")
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def load_habitat(context, commands = [])
|
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)
|
42
|
+
else
|
43
|
+
context.execute_command(%w(sudo hab) + supervisor_command + commands) unless Gem.win_platform?
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def run_habitat_supervisor(context, commands = [])
|
48
|
+
supervisor_command = %w(sup run)
|
49
|
+
if context.is_admin?
|
50
|
+
context.habitat(context, supervisor_command + commands)
|
51
|
+
else
|
52
|
+
context.execute_command(%w(sudo hab) + supervisor_command + commands) unless Gem.win_platform?
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def install_habitat_supervisor(context, commands = [])
|
57
|
+
supervisor_command = %w(sup run)
|
58
|
+
if context.is_admin?
|
59
|
+
context.habitat(context, supervisor_command + commands)
|
60
|
+
else
|
61
|
+
context.execute_command(%w(sudo hab) + supervisor_command + commands) 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.log "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.log "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.log "And return array is #{build_result.return_arr}"
|
80
|
+
# build_result.return_str = build_result.return_arr[3]
|
81
|
+
# context.log "And return string is #{build_result.return_str}"
|
82
|
+
# build_result.result_arr = build_result.return_str.split(' ')
|
83
|
+
# context.log "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)
|
104
|
+
context.git_build(context)
|
105
|
+
# , "#{organisation_name}/#{context_name}"
|
106
|
+
log "Setting the build ID to #{context.hab_build_id(context)}"
|
107
|
+
|
108
|
+
File.write(context.get_context_file(context, 'HAB_BUILD_ID'), context.hab_build_id(context))
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|