sambot 0.1.158 → 0.1.159
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/sambot.rb +1 -0
- data/lib/sambot/base_command.rb +1 -24
- data/lib/sambot/chef/cookbook.rb +32 -54
- data/lib/sambot/chef/generator.rb +28 -38
- data/lib/sambot/chef/hooks.rb +4 -2
- data/lib/sambot/chef/kitchen.rb +33 -42
- data/lib/sambot/chef/metadata.rb +14 -14
- data/lib/sambot/cli.rb +22 -19
- data/lib/sambot/config.rb +59 -4
- data/lib/sambot/docs/bump.txt +1 -0
- data/lib/sambot/docs/{generate.txt → create.txt} +0 -0
- data/lib/sambot/fs.rb +33 -0
- data/lib/sambot/runtime.rb +13 -29
- data/lib/sambot/template.rb +22 -1
- data/lib/sambot/templates/.config.yml.erb +7 -7
- data/lib/sambot/{docs/configure.txt → templates/.consul.yml} +0 -0
- data/lib/sambot/templates/.vault.yml +0 -0
- data/lib/sambot/templates/README.md +0 -0
- data/lib/sambot/templates/Vagrantfile.erb +7 -5
- data/lib/sambot/templates/attributes/default.rb +0 -0
- data/lib/sambot/templates/{gcp_bootstrap.ps1.erb → bootstrap_scripts/google/bootstrap.ps1.erb} +0 -0
- data/lib/sambot/templates/{gcp_bootstrap.sh.erb → bootstrap_scripts/google/bootstrap.sh.erb} +0 -1
- data/lib/sambot/templates/bootstrap_scripts/local/sidecar_vault/bootstrap.ps1.erb +33 -0
- data/lib/sambot/templates/bootstrap_scripts/local/sidecar_vault/bootstrap.sh.erb +34 -0
- data/lib/sambot/templates/{local_bootstrap.ps1 → bootstrap_scripts/local/standalone_vault/bootstrap.ps1.erb} +0 -0
- data/lib/sambot/templates/{local_bootstrap.sh → bootstrap_scripts/local/standalone_vault/bootstrap.sh.erb} +0 -0
- data/lib/sambot/templates/{pre-commit → git_hooks/pre-commit} +0 -0
- data/lib/sambot/templates/{pre-push → git_hooks/pre-push} +0 -0
- data/lib/sambot/templates/local/vault/helper.rb +11 -0
- data/lib/sambot/templates/recipes/configure.rb.erb +0 -0
- data/lib/sambot/templates/recipes/default.rb.erb +0 -0
- data/lib/sambot/templates/recipes/install.rb.erb +0 -0
- data/lib/sambot/templates/spec/spec_helper.rb +2 -0
- data/lib/sambot/templates/test/default_test.rb +0 -0
- data/lib/sambot/templates/{.kitchen.gcp.yml.erb → test_kitchen/google.yml.erb} +0 -0
- data/lib/sambot/templates/{.kitchen.yml.erb → test_kitchen/local.yml.erb} +2 -2
- data/lib/sambot/templates/{.kitchen.rackspace.yml.erb → test_kitchen/rackspace.yml.erb} +5 -5
- data/lib/sambot/ui.rb +12 -6
- data/lib/sambot/version.rb +1 -1
- metadata +26 -17
- data/lib/sambot/commands/cookbook_cmd.rb +0 -44
- data/lib/sambot/docs/start.txt +0 -21
- data/lib/sambot/docs/stop.txt +0 -7
- data/lib/sambot/workflow/dns.rb +0 -43
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f27feb0c87f9680b1441083a5226c3c45f34949d
|
4
|
+
data.tar.gz: 137d801be27d2a4331845631e71e4f7d2cdaf052
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 49a6f7111b10455d4067fde52cabf814912f5ede523ccc9226d81a92892dbc846c7ea62c513e496aff3b533a2dfc5e1b769506f21f64a153018304858bf5835d
|
7
|
+
data.tar.gz: c7197211b5b94c3d0d8dd2898525d7f10738d8f6583523a685f728b16fde7d15860d1ecd5d46128903bc3730fa8b3f1d637a4190a976b8f01082def49ad8d480
|
data/lib/sambot.rb
CHANGED
data/lib/sambot/base_command.rb
CHANGED
@@ -62,36 +62,13 @@ module Sambot
|
|
62
62
|
|
63
63
|
no_commands do
|
64
64
|
|
65
|
-
def
|
66
|
-
return true if need_dev_credentials && (!ENV['SAMBOT_DEV_USERNAME'] && !ENV['SAMBOT_DEV_PASSWORD'])
|
67
|
-
return need_sudo_password && !ENV['SAMBOT_SUDO_PASSWORD']
|
68
|
-
end
|
69
|
-
|
70
|
-
def execute(need_dev_credentials: false, need_sudo_password: false)
|
71
|
-
if missing_credentials(need_dev_credentials, need_sudo_password)
|
72
|
-
UI.info("Sambot will need to make some secure operations on your behalf. You can provide your credentials below or set them as environment variables:")
|
73
|
-
end
|
74
|
-
if need_dev_credentials && !ENV['SAMBOT_DEV_USERNAME']
|
75
|
-
ENV['SAMBOT_DEV_USERNAME'] = UI.ask("No environment variable SAMBOT_DEV_USERNAME found. Please provide your DEV/QE AD username: ")
|
76
|
-
end
|
77
|
-
if need_dev_credentials && !ENV['SAMBOT_DEV_PASSWORD']
|
78
|
-
ENV['SAMBOT_DEV_PASSWORD'] = UI.ask_password("No environment variable SAMBOT_DEV_PASSWORD found. Please provide your DEV/QE AD password: ")
|
79
|
-
puts "\n"
|
80
|
-
end
|
81
|
-
if need_sudo_password && !ENV['SAMBOT_SUDO_PASSWORD']
|
82
|
-
ENV['SAMBOT_SUDO_PASSWORD'] = UI.ask_password("No environment variable SAMBOT_SUDO_PASSWORD found. Please provide your sudo password - this is required for operations such as setting up your local SSH tunnels: ")
|
83
|
-
puts "\n"
|
84
|
-
end
|
65
|
+
def execute()
|
85
66
|
Runtime.ensure_latest
|
86
67
|
yield
|
87
68
|
rescue ApplicationError => e
|
88
69
|
UI.error(e.message)
|
89
70
|
end
|
90
71
|
|
91
|
-
def config
|
92
|
-
Config.new.read
|
93
|
-
end
|
94
|
-
|
95
72
|
def self.docs(path)
|
96
73
|
File.read(File.join(File.dirname(__FILE__), '/docs', path + '.txt'))
|
97
74
|
end
|
data/lib/sambot/chef/cookbook.rb
CHANGED
@@ -7,87 +7,65 @@ module Sambot
|
|
7
7
|
module Chef
|
8
8
|
class Cookbook
|
9
9
|
|
10
|
-
ESSENTIAL_FILES = [
|
11
|
-
'.config.yml',
|
12
|
-
'recipes',
|
13
|
-
'README.md'
|
14
|
-
].freeze
|
15
|
-
|
16
10
|
GENERATED_FILES = {
|
17
11
|
'teamcity.sh.erb': {eruby: true, dest: 'teamcity.sh', platform: [:windows, :centos]},
|
18
12
|
'chefignore': {eruby: false, dest: 'chefignore', platform: [:windows, :centos]},
|
19
13
|
'Berksfile': {eruby: false, dest: 'Berksfile', platform: [:windows, :centos]},
|
20
14
|
'.rubocop.yml': {eruby: false, dest: '.rubocop.yml', platform: [:windows, :centos]},
|
21
15
|
'.gitignore.sample': {eruby: false, dest: '.gitignore', platform: [:windows, :centos]},
|
22
|
-
'local_bootstrap.sh': {eruby: false, dest: 'local_bootstrap.sh', platform: [:centos]},
|
23
|
-
'local_bootstrap.ps1': {eruby: false, dest: 'local_bootstrap.ps1', platform: [:windows]},
|
24
|
-
'gcp_bootstrap.sh.erb': {eruby: true, dest: 'gcp_bootstrap.sh', platform: [:centos]},
|
25
|
-
'gcp_bootstrap.ps1.erb': {eruby: true, dest: 'gcp_bootstrap.ps1', platform: [:windows]},
|
26
16
|
'Vagrantfile.erb': {eruby: false, dest: 'Vagrantfile.erb', platform: [:windows, :centos]},
|
27
17
|
'winrm_config': {eruby: false, dest: 'winrm_config', platform: [:windows]}
|
28
18
|
}
|
29
19
|
|
30
|
-
CHEF_ARTEFACTS = ['Berksfile.lock']
|
31
|
-
|
32
|
-
KITCHEN_FILES_PATTERN = '\.kitchen*\.yml'
|
33
|
-
|
34
20
|
class << self
|
35
21
|
|
36
|
-
def build(config)
|
37
|
-
|
38
|
-
|
22
|
+
def build(config, cloud, vault_setup = nil)
|
23
|
+
create_files(config)
|
24
|
+
Generator.from_templates(config, cloud, vault_setup, GENERATED_FILES)
|
25
|
+
Kitchen.setup(cloud, config)
|
39
26
|
Metadata.generate(config)
|
40
27
|
Hooks.copy()
|
41
28
|
UI.info('The cookbook has been successfully built.')
|
42
29
|
end
|
43
30
|
|
31
|
+
def bump()
|
32
|
+
new_version = Config.bump_version
|
33
|
+
UI.info("You have bumped the version of this cookbook to #{new_version}.")
|
34
|
+
end
|
35
|
+
|
44
36
|
def clean()
|
45
37
|
UI.info('Removing all generated files from this cookbook.')
|
46
|
-
targets =
|
47
|
-
targets.each { |file| delete(file) }
|
38
|
+
targets = GENERATED_FILES.map{ |key, val| val[:dest]} - ['.gitignore']
|
39
|
+
targets.each { |file| Sambot::FS.delete(file) }
|
40
|
+
Sambot::FS.delete('bootstrap.sh')
|
41
|
+
Sambot::FS.delete('bootstrap.ps1')
|
42
|
+
Metadata.clean
|
43
|
+
Kitchen.clean
|
48
44
|
UI.info('The cookbook has been successfully cleaned.')
|
49
45
|
end
|
50
46
|
|
51
|
-
def
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
def generate(config)
|
57
|
-
Git.init(config[:name])
|
58
|
-
Dir.chdir(config[:name]) do
|
59
|
-
['test', 'spec', 'recipes', 'attributes'].each {|target| FileUtils.mkdir(target) }
|
60
|
-
Dir.chdir('attributes') do
|
61
|
-
FileUtils.touch('default.rb')
|
62
|
-
end
|
63
|
-
Dir.chdir('recipes') do
|
64
|
-
FileUtils.touch('install.rb')
|
65
|
-
FileUtils.touch('configure.rb')
|
66
|
-
FileUtils.touch('default.rb')
|
67
|
-
end
|
68
|
-
Dir.chdir('test') do
|
69
|
-
FileUtils.touch('default_test.rb')
|
70
|
-
end
|
71
|
-
Dir.chdir('spec') do
|
72
|
-
File.write('spec_helper.rb', <<-EOT)
|
73
|
-
require 'chefspec'
|
74
|
-
require 'chefspec/berkshelf'
|
75
|
-
EOT
|
76
|
-
FileUtils.touch('default_spec.rb')
|
77
|
-
end
|
78
|
-
FileUtils.touch('README.md')
|
79
|
-
Template.new('.config.yml.erb').write(config, '.config.yml')
|
80
|
-
UI.debug("./.config.yml has been added to the cookbook.")
|
47
|
+
def create(config)
|
48
|
+
Git.init(config.name)
|
49
|
+
Dir.chdir(config.name) do
|
50
|
+
create_files(config)
|
81
51
|
end
|
82
|
-
UI.info('The cookbook has been successfully
|
52
|
+
UI.info('The cookbook has been successfully created.')
|
83
53
|
end
|
84
54
|
|
85
55
|
private
|
86
56
|
|
87
|
-
def
|
88
|
-
|
89
|
-
|
90
|
-
|
57
|
+
def create_files(config)
|
58
|
+
['spec', 'test', 'attributes', '.vault.yml', '.consul.yml', 'local', 'README.md'].each { |resource| FS.copy(resource) }
|
59
|
+
['recipes', 'libraries', 'resources', 'files', 'templates'].each { |target| FS.mkdir(target) }
|
60
|
+
Dir.chdir('recipes') do
|
61
|
+
Template.new('recipes/install.rb.erb').write({config: config}, 'install.rb') unless FS.exist?('install.rb')
|
62
|
+
Template.new('recipes/configure.rb.erb').write({config: config}, 'configure.rb') unless FS.exist?('configure.rb')
|
63
|
+
Template.new('recipes/default.rb.erb').write({config: config}, 'default.rb') unless FS.exist?('default.rb')
|
64
|
+
end
|
65
|
+
unless FS.exist?('.config.yml')
|
66
|
+
Template.new('.config.yml.erb').write({config: config}, '.config.yml')
|
67
|
+
UI.debug("./.config.yml has been added to the cookbook.")
|
68
|
+
end
|
91
69
|
end
|
92
70
|
|
93
71
|
end
|
@@ -5,27 +5,32 @@ module Sambot
|
|
5
5
|
module Chef
|
6
6
|
class Generator
|
7
7
|
|
8
|
-
def self.from_templates(config,
|
9
|
-
|
10
|
-
|
11
|
-
cookbook_essentials.each { |path| exists!(path) } if cookbook_essentials
|
12
|
-
cookbook_generated_files.each do |template_name, opts|
|
13
|
-
generate_from_template(template_name.to_s, opts, platforms)
|
14
|
-
end
|
15
|
-
override_bootstrap_mechanism(config['bootstrap']) if config['bootstrap']
|
8
|
+
def self.from_templates(config, cloud, vault_setup, generated_files)
|
9
|
+
generated_files.each { |template_name, opts| generate_from_template(template_name.to_s, opts, config) }
|
10
|
+
generate_bootstrap_scripts(config, cloud, vault_setup)
|
16
11
|
end
|
17
12
|
|
18
13
|
private
|
19
14
|
|
20
|
-
def self.
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
15
|
+
def self.bootstrap_centos(path)
|
16
|
+
generate_bootstrap_from_template('bootstrap.sh', path, 'sh')
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.bootstrap_windows(path)
|
20
|
+
generate_bootstrap_from_template('bootstrap.ps1', path, 'ps1')
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.bootstrap(config, path)
|
24
|
+
bootstrap_centos(path) if config.runs_on_centos?
|
25
|
+
bootstrap_windows(path) if config.runs_on_windows?
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.generate_bootstrap_from_template(dest, path, suffix)
|
29
|
+
Template.new("bootstrap_scripts/#{path}/bootstrap.#{suffix}.erb").process({eruby: true, dest: "bootstrap.#{suffix}"})
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.generate_bootstrap_scripts(config, cloud, vault_setup)
|
33
|
+
cloud != 'local'? bootstrap(config, cloud) : bootstrap(config, "local/#{vault_setup}_vault")
|
29
34
|
end
|
30
35
|
|
31
36
|
def self.exists!(path)
|
@@ -33,36 +38,21 @@ module Sambot
|
|
33
38
|
raise ApplicationError, "The file or directory #{path} was not found in the current directory."
|
34
39
|
end
|
35
40
|
|
36
|
-
def self.generate_from_template(template_file, opts,
|
37
|
-
UI.debug("Processing #{template_file} with opts #{opts.inspect} on platform #{
|
41
|
+
def self.generate_from_template(template_file, opts, config)
|
42
|
+
UI.debug("Processing #{template_file} with opts #{opts.inspect} on platform #{config.available_platforms}")
|
38
43
|
template = Template.new(template_file)
|
39
|
-
if valid_platform?(opts,
|
40
|
-
|
41
|
-
if opts[:eruby]
|
42
|
-
UI.debug("Parsing #{template.path} using Erubis")
|
43
|
-
template.write({}, opts[:dest])
|
44
|
-
else
|
45
|
-
FileUtils.cp(template.path, opts[:dest].to_s)
|
46
|
-
end
|
47
|
-
if File.executable?(template.path)
|
48
|
-
UI.debug("Making #{opts[:dest]} executable")
|
49
|
-
make_executable(template.path, opts[:dest])
|
50
|
-
end
|
44
|
+
if valid_platform?(opts, config)
|
45
|
+
template.process(opts)
|
51
46
|
UI.debug("#{opts[:dest]} has been added to the cookbook.")
|
52
47
|
end
|
53
48
|
end
|
54
49
|
|
55
|
-
def self.valid_platform?(opts,
|
50
|
+
def self.valid_platform?(opts, config)
|
56
51
|
targets = opts[:platform].map { |x| x.to_s}
|
57
|
-
result = targets &
|
52
|
+
result = targets & config.available_platforms
|
58
53
|
result.size > 0
|
59
54
|
end
|
60
55
|
|
61
|
-
def self.make_executable(file, working_path)
|
62
|
-
current_mask = File.stat(file).mode
|
63
|
-
new_mask = current_mask | '0000000000000001'.to_i(2)
|
64
|
-
File.chmod(new_mask, working_path)
|
65
|
-
end
|
66
56
|
end
|
67
57
|
end
|
68
58
|
end
|
data/lib/sambot/chef/hooks.rb
CHANGED
@@ -4,10 +4,12 @@ module Sambot
|
|
4
4
|
module Chef
|
5
5
|
class Hooks
|
6
6
|
|
7
|
+
SCRIPTS = ['pre-push', 'pre-commit']
|
8
|
+
|
7
9
|
def self.copy
|
8
|
-
|
10
|
+
SCRIPTS.each do |hook|
|
9
11
|
working_path = ".git/hooks/#{hook}"
|
10
|
-
template_path = Template.new(hook).path
|
12
|
+
template_path = Template.new("git_hooks/#{hook}").path
|
11
13
|
File.delete(working_path) if File.exist?(working_path)
|
12
14
|
FileUtils.cp(template_path, working_path)
|
13
15
|
UI.debug("The #{hook} Git hook has been added to the cookbook.")
|
data/lib/sambot/chef/kitchen.rb
CHANGED
@@ -4,68 +4,59 @@ module Sambot
|
|
4
4
|
module Chef
|
5
5
|
class Kitchen
|
6
6
|
|
7
|
-
LOCAL = '.kitchen.yml'
|
8
|
-
GCP = '.kitchen.gcp.yml'
|
9
|
-
RACKSPACE = '.kitchen.rackspace.yml'
|
10
|
-
|
11
7
|
class << self
|
12
8
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
9
|
+
GENERATED_FILE = '.kitchen.yml'
|
10
|
+
|
11
|
+
def setup(cloud, config)
|
12
|
+
contents = generate_yml(cloud, config.name, config.available_platforms, config.suites)
|
13
|
+
File.write(GENERATED_FILE, contents)
|
14
|
+
UI.debug("#{GENERATED_FILE} has been added to the cookbook.")
|
19
15
|
end
|
20
16
|
|
21
|
-
def
|
17
|
+
def clean
|
18
|
+
FS.delete(GENERATED_FILE)
|
19
|
+
end
|
20
|
+
|
21
|
+
def generate_yml(cloud, cookbook_name, platforms, suites = nil)
|
22
22
|
raise ApplicationError, 'Missing platforms when trying to generate Test-Kitchen YAML.' unless platforms
|
23
23
|
raise ApplicationError, 'Missing cookbook name when trying to generate Test-Kitchen YAML.' unless cookbook_name
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
}
|
29
|
-
test_kitchen_configs.each do |key, value|
|
30
|
-
if suites
|
31
|
-
value['suites'] = Marshal.load(Marshal.dump(suites))
|
32
|
-
case key.to_s
|
33
|
-
when LOCAL
|
34
|
-
add_platform_identifier(value, 'LOCAL')
|
35
|
-
when GCP
|
36
|
-
add_platform_identifier(value, 'GCP')
|
37
|
-
when RACKSPACE
|
38
|
-
add_platform_identifier(value, 'RACKSPACE')
|
39
|
-
end
|
40
|
-
end
|
41
|
-
test_kitchen_configs[key] = value.to_yaml
|
24
|
+
template = read_template(cloud, cookbook_name, platforms)
|
25
|
+
if suites
|
26
|
+
template['suites'] = Marshal.load(Marshal.dump(suites))
|
27
|
+
add_platform_identifier(template, cloud)
|
42
28
|
end
|
43
|
-
|
29
|
+
template.to_yaml
|
44
30
|
end
|
45
31
|
|
46
32
|
private
|
47
33
|
|
34
|
+
# Adds attributes to each test suite that is only applicable to testing
|
35
|
+
# environments. These are things like controlling how Vault token
|
36
|
+
# renewal works and specifying the cloud platform.
|
48
37
|
def add_platform_identifier(value, platform)
|
49
|
-
value['suites'].each do |
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
38
|
+
value['suites'].each do |suite|
|
39
|
+
suite['run_list'] = handle_customized_runlists(suite, platform)
|
40
|
+
suite['attributes'] = suite['attributes'] || {}
|
41
|
+
suite['attributes']['cloud_platform'] = platform
|
42
|
+
suite['attributes']['vault'] = suite['attributes']['vault'] || {}
|
43
|
+
suite['attributes']['vault']['exec_renew'] = false
|
55
44
|
end
|
56
45
|
end
|
57
46
|
|
47
|
+
# Provides the ability to have a different run-list for different clouds.
|
48
|
+
# This only works for the 'local' cloud and the 'dev' clouds i.e. Rackspace
|
49
|
+
# and Google.
|
58
50
|
def handle_customized_runlists(config, platform)
|
59
51
|
runlist = config['run_list']
|
60
52
|
return runlist if runlist.is_a?(Array)
|
61
|
-
platform == '
|
53
|
+
platform == 'local' ? runlist['local'] : runlist['dev']
|
62
54
|
end
|
63
55
|
|
64
|
-
def read_template(
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
YAML.load(result.gsub(/\_@/, '<%=').gsub(/@\_/, '%>'))
|
56
|
+
def read_template(cloud, cookbook_name, platforms)
|
57
|
+
ctx = {platforms: platforms, name: cookbook_name}
|
58
|
+
result = Template.new("test_kitchen/#{cloud}.yml.erb").evaluate(ctx, {:pattern => '<!--% %-->'})
|
59
|
+
YAML.load(result)
|
69
60
|
end
|
70
61
|
|
71
62
|
end
|
data/lib/sambot/chef/metadata.rb
CHANGED
@@ -8,27 +8,27 @@ module Sambot
|
|
8
8
|
|
9
9
|
class << self
|
10
10
|
|
11
|
+
GENERATED_FILES = ['metadata.rb', 'Berksfile.lock']
|
12
|
+
|
13
|
+
def clean
|
14
|
+
GENERATED_FILES.each do |filename|
|
15
|
+
FS.delete(filename)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
11
19
|
def generate(config, dest = 'metadata.rb')
|
12
20
|
write({
|
13
|
-
'cookbook_name' => config
|
14
|
-
'cookbook_platforms' => config
|
15
|
-
'cookbook_version' => config
|
16
|
-
'cookbook_description' => config
|
17
|
-
'cookbook_dependencies' =>
|
18
|
-
'cookbook_gems' => config
|
21
|
+
'cookbook_name' => config.name,
|
22
|
+
'cookbook_platforms' => config.available_platforms,
|
23
|
+
'cookbook_version' => config.version,
|
24
|
+
'cookbook_description' => config.description,
|
25
|
+
'cookbook_dependencies' => config.dependencies,
|
26
|
+
'cookbook_gems' => config.gems,
|
19
27
|
}, dest)
|
20
28
|
end
|
21
29
|
|
22
30
|
private
|
23
31
|
|
24
|
-
def map_dependencies(config)
|
25
|
-
config['dependencies'] ? config['dependencies'].map { |x| transform_hashes(x) } : []
|
26
|
-
end
|
27
|
-
|
28
|
-
def transform_hashes(obj)
|
29
|
-
obj.is_a?(Hash) ? "#{obj.keys.first}', '#{obj.values.first}" : obj
|
30
|
-
end
|
31
|
-
|
32
32
|
def write(ctx, dest)
|
33
33
|
template = Sambot::Template.new('metadata.rb.erb').write(ctx, dest)
|
34
34
|
UI.debug("A new metadata.rb file has been generated.")
|
data/lib/sambot/cli.rb
CHANGED
@@ -1,41 +1,51 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require_relative 'base_command'
|
4
|
-
require_relative 'commands/cookbook_cmd'
|
5
4
|
|
6
5
|
module Sambot
|
7
6
|
class CLI < BaseCommand
|
8
7
|
|
9
|
-
desc 'cookbook', 'Manage Chef cookbooks'
|
10
|
-
subcommand 'cookbook', Sambot::Commands::CookbookCmd
|
11
|
-
|
12
8
|
desc 'clean', 'Remove all generated build files from a Chef cookbook'
|
13
9
|
def clean
|
14
10
|
execute { Chef::Cookbook.clean() }
|
15
11
|
end
|
16
12
|
|
17
|
-
desc '
|
13
|
+
desc 'bump', 'Bump the patch version of a cookbook'
|
18
14
|
def bump
|
19
15
|
execute { Chef::Cookbook.bump() }
|
20
16
|
end
|
21
17
|
|
22
18
|
desc 'build', 'Builds a Chef cookbook from its configuration file'
|
19
|
+
option :local, :type => :boolean
|
20
|
+
option :google, :type => :boolean
|
21
|
+
option :rackspace, :type => :boolean
|
22
|
+
option :vault, :type => :string, :default => 'standalone'
|
23
23
|
def build
|
24
|
-
execute
|
24
|
+
execute do
|
25
|
+
cloud = nil
|
26
|
+
cloud = 'local' if options[:local]
|
27
|
+
cloud = 'google' if options[:google]
|
28
|
+
cloud = 'rackspace' if options[:rackspace]
|
29
|
+
unless cloud
|
30
|
+
UI.error('Please select which environment this is building for using one of the following flags: --local, --rackspace or --google')
|
31
|
+
exit
|
32
|
+
end
|
33
|
+
Chef::Cookbook.build(Config.read, cloud, options[:vault])
|
34
|
+
end
|
25
35
|
end
|
26
36
|
|
27
|
-
desc '
|
28
|
-
def
|
37
|
+
desc 'create', 'Creates a new Chef cookbook'
|
38
|
+
def create
|
29
39
|
execute do
|
30
|
-
|
40
|
+
opts = {
|
31
41
|
name: ask(' What is the name of this cookbook?'),
|
32
42
|
type: ask(' What type of cookbook will this be?', :limited_to => ['wrapper', 'role']),
|
33
43
|
platforms: ask(' What operating system will this cookbook run on?', :limited_to => ['windows', 'centos', 'both']),
|
34
44
|
description: ask(' What does this cookbook do?')
|
35
45
|
}
|
36
|
-
|
37
|
-
|
38
|
-
Chef::Cookbook.
|
46
|
+
opts[:identifier] = ask(' What will be the unique machiner identifier for this role cookbook?') if opts[:type] == 'role'
|
47
|
+
opts[:platforms] = opts[:platforms] == 'both' ? ['centos', 'windows'] : [opts[:platforms]]
|
48
|
+
Chef::Cookbook.create(Config.new(opts))
|
39
49
|
end
|
40
50
|
end
|
41
51
|
|
@@ -44,12 +54,5 @@ module Sambot
|
|
44
54
|
execute { puts "##teamcity[buildNumber '#{config['version'].to_s}']" }
|
45
55
|
end
|
46
56
|
|
47
|
-
desc 'configure', 'Sets up an engineering workstation'
|
48
|
-
def configure
|
49
|
-
execute(need_dev_credentials: true, need_sudo_password: true) do
|
50
|
-
Workflow::Workstation.configure(ENV['SAMBOT_DEV_PASSWORD'])
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
57
|
end
|
55
58
|
end
|