amigrind 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +10 -0
  3. data/.rspec +2 -0
  4. data/.rubocop.yml +72 -0
  5. data/.travis.yml +4 -0
  6. data/CODE_OF_CONDUCT.md +49 -0
  7. data/Gemfile +4 -0
  8. data/LICENSE.txt +201 -0
  9. data/README.md +112 -0
  10. data/Rakefile +6 -0
  11. data/amigrind.gemspec +36 -0
  12. data/bin/amigrind +8 -0
  13. data/lib/amigrind.rb +29 -0
  14. data/lib/amigrind/blueprints/aws_config.rb +56 -0
  15. data/lib/amigrind/blueprints/base_ami_source.rb +15 -0
  16. data/lib/amigrind/blueprints/blueprint.rb +22 -0
  17. data/lib/amigrind/blueprints/evaluator.rb +269 -0
  18. data/lib/amigrind/blueprints/parent_blueprint_source.rb +10 -0
  19. data/lib/amigrind/blueprints/provisioner.rb +20 -0
  20. data/lib/amigrind/blueprints/provisioners/file_upload.rb +29 -0
  21. data/lib/amigrind/blueprints/provisioners/local_shell.rb +28 -0
  22. data/lib/amigrind/blueprints/provisioners/remote_shell.rb +57 -0
  23. data/lib/amigrind/build/packer_runner.rb +106 -0
  24. data/lib/amigrind/build/rackerizer.rb +134 -0
  25. data/lib/amigrind/builder.rb +46 -0
  26. data/lib/amigrind/cli.rb +12 -0
  27. data/lib/amigrind/cli/_helpers.rb +49 -0
  28. data/lib/amigrind/cli/_root.rb +43 -0
  29. data/lib/amigrind/cli/blueprints/_category.rb +15 -0
  30. data/lib/amigrind/cli/blueprints/list.rb +21 -0
  31. data/lib/amigrind/cli/blueprints/show.rb +22 -0
  32. data/lib/amigrind/cli/build/_category.rb +15 -0
  33. data/lib/amigrind/cli/build/execute.rb +32 -0
  34. data/lib/amigrind/cli/build/print_packer.rb +28 -0
  35. data/lib/amigrind/cli/environments/_category.rb +15 -0
  36. data/lib/amigrind/cli/environments/list.rb +23 -0
  37. data/lib/amigrind/cli/environments/show.rb +22 -0
  38. data/lib/amigrind/cli/inventory/_category.rb +15 -0
  39. data/lib/amigrind/cli/inventory/add_to_channel.rb +28 -0
  40. data/lib/amigrind/cli/inventory/get-image.rb +34 -0
  41. data/lib/amigrind/cli/inventory/list.rb +14 -0
  42. data/lib/amigrind/cli/inventory/remove_from_channel.rb +28 -0
  43. data/lib/amigrind/cli/repo/_category.rb +15 -0
  44. data/lib/amigrind/cli/repo/init.rb +22 -0
  45. data/lib/amigrind/config.rb +89 -0
  46. data/lib/amigrind/environments/channel.rb +9 -0
  47. data/lib/amigrind/environments/environment.rb +66 -0
  48. data/lib/amigrind/environments/rb_evaluator.rb +7 -0
  49. data/lib/amigrind/repo.rb +217 -0
  50. data/lib/amigrind/version.rb +3 -0
  51. data/sample_config/config.yaml +9 -0
  52. data/sample_repo/.amigrind_root +0 -0
  53. data/sample_repo/blueprints/dependent_ubuntu.rb +21 -0
  54. data/sample_repo/blueprints/simple_ubuntu.rb +37 -0
  55. data/sample_repo/environments/development.yaml.example +15 -0
  56. metadata +288 -0
@@ -0,0 +1,49 @@
1
+ module Amigrind
2
+ module CLI
3
+ class << self
4
+ def output_format_options(cmd)
5
+ cmd.option :f, :format,
6
+ 'output format',
7
+ argument: :required
8
+ end
9
+
10
+ def repo_options(cmd)
11
+ cmd.option nil, :'repo-path',
12
+ 'path to the Amigrind repo',
13
+ argument: :required
14
+ end
15
+
16
+ def environment_options(cmd)
17
+ cmd.option nil, :environment,
18
+ 'name of the environment in the Amigrind repo',
19
+ argument: :required
20
+ end
21
+
22
+ def blueprint_options(cmd)
23
+ cmd.option nil, :blueprint,
24
+ 'name of the blueprint in the Amigrind repo',
25
+ argument: :required
26
+ end
27
+
28
+ def channel_options(cmd)
29
+ cmd.option nil, :channel,
30
+ 'channel to use, from the selected Amigrind environment',
31
+ argument: :required
32
+ end
33
+
34
+ def environment_name_parse(opts)
35
+ opts[:environment] ||
36
+ (Amigrind::Config['amigrind'] || {})['default_environment'] ||
37
+ 'default'
38
+ end
39
+
40
+ def with_repo_and_env(opts, &block)
41
+ Amigrind::Repo.with_repo(path: opts[:'repo-path']) do |repo|
42
+ env_name = CLI.environment_name_parse(opts)
43
+
44
+ block.call(repo, repo.environment(env_name))
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,43 @@
1
+ module Amigrind
2
+ module CLI
3
+ # credentials = Amigrind::Core::CredentialsHelper.from_cli_options(options)
4
+
5
+ ROOT = Cri::Command.define do
6
+ name File.basename($PROGRAM_NAME, ".*")
7
+ summary "the best way to build AMIs for AWS"
8
+
9
+ flag :h, :help, 'show help for this command' do |_, cmd|
10
+ puts cmd.help
11
+ exit 0
12
+ end
13
+
14
+ flag :v, :verbose, "debug logging instead of info" do |_, _|
15
+ Amigrind::Core::Logging.log_level(:debug)
16
+ end
17
+
18
+ flag :q, :quiet, "warn logging instead of info" do |_, _|
19
+ Amigrind::Core::Logging.log_level(:warn)
20
+ end
21
+
22
+ flag nil, :version, "show application version" do |_, _|
23
+ require 'json'
24
+
25
+ versions = {
26
+ 'amigrind' => Amigrind::VERSION,
27
+ 'amigrind-core' => Amigrind::Core::VERSION,
28
+ 'aws-sdk' => Aws::VERSION,
29
+ 'packer' => File.which('packer').nil? ? nil : `packer --version`.strip
30
+ }
31
+
32
+ puts JSON.pretty_generate versions
33
+
34
+ Kernel.exit 0
35
+ end
36
+
37
+ run do |_, _, cmd|
38
+ puts cmd.help
39
+ exit 0
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,15 @@
1
+ module Amigrind
2
+ module CLI
3
+ BLUEPRINTS = Cri::Command.define do
4
+ name 'blueprints'
5
+ description 'commands related to Amigrind blueprints in your Amigrind repo'
6
+
7
+ run do |_, _, cmd|
8
+ puts cmd.help
9
+ exit 0
10
+ end
11
+ end
12
+
13
+ ROOT.add_command(BLUEPRINTS)
14
+ end
15
+ end
@@ -0,0 +1,21 @@
1
+ module Amigrind
2
+ module CLI
3
+ BLUEPRINTS.add_command(
4
+ Cri::Command.define do
5
+ name 'list'
6
+ description 'lists Amigrind blueprints in the Amigrind repo'
7
+
8
+ CLI.repo_options(self)
9
+
10
+ CLI.output_format_options(self)
11
+
12
+ run do |opts, _, cmd|
13
+ Amigrind::Repo.with_repo(path: opts[:'repo-path']) do |repo|
14
+ # TODO: provide more information
15
+ JSON.pretty_generate(repo.blueprint_names.map { |n| { name: n } })
16
+ end
17
+ end
18
+ end
19
+ )
20
+ end
21
+ end
@@ -0,0 +1,22 @@
1
+ module Amigrind
2
+ module CLI
3
+ BLUEPRINTS.add_command(
4
+ Cri::Command.define do
5
+ name 'show'
6
+ description 'displays an evaluated Amigrind blueprint'
7
+
8
+ CLI.output_format_options(self)
9
+
10
+ CLI.repo_options(self)
11
+ CLI.environment_options(self)
12
+
13
+ run do |opts, args, cmd|
14
+ Amigrind::Repo.with_repo(path: opts[:'repo-path']) do |repo|
15
+ bp = repo.evaluate_blueprint(args[0], opts[:environment])
16
+ puts YAML.dump(bp)
17
+ end
18
+ end
19
+ end
20
+ )
21
+ end
22
+ end
@@ -0,0 +1,15 @@
1
+ module Amigrind
2
+ module CLI
3
+ BUILD = Cri::Command.define do
4
+ name 'build'
5
+ description 'commands related to building AMIs for consumption'
6
+
7
+ run do |_, _, cmd|
8
+ puts cmd.help
9
+ exit 0
10
+ end
11
+ end
12
+
13
+ ROOT.add_command(BUILD)
14
+ end
15
+ end
@@ -0,0 +1,32 @@
1
+ module Amigrind
2
+ module CLI
3
+ BUILD.add_command(
4
+ Cri::Command.define do
5
+ name 'execute'
6
+ description 'evaluates an Amigrind blueprint and runs it through Packer'
7
+
8
+ CLI.output_format_options(self)
9
+
10
+ CLI.repo_options(self)
11
+ CLI.environment_options(self)
12
+ CLI.blueprint_options(self)
13
+
14
+ flag nil, :'show-spools', 'if set, includes Packer output in stdout output.'
15
+
16
+ run do |opts, args, _|
17
+ CLI.with_repo_and_env(opts) do |repo, env|
18
+ bp = repo.evaluate_blueprint(args[0], env)
19
+ credentials = Amigrind::Config.aws_credentials(env)
20
+
21
+ builder = Amigrind::Builder.new(credentials, bp, repo)
22
+
23
+ retval = builder.build
24
+ retval.delete(:spools) unless opts[:'show-spools']
25
+
26
+ puts JSON.pretty_generate(retval)
27
+ end
28
+ end
29
+ end
30
+ )
31
+ end
32
+ end
@@ -0,0 +1,28 @@
1
+ module Amigrind
2
+ module CLI
3
+ BUILD.add_command(
4
+ Cri::Command.define do
5
+ name 'print-packer'
6
+ description 'evaluates an Amigrind blueprint and prints Packer JSON'
7
+
8
+ CLI.output_format_options(self)
9
+
10
+ CLI.repo_options(self)
11
+ CLI.environment_options(self)
12
+ CLI.blueprint_options(self)
13
+
14
+ run do |opts, args, _|
15
+ CLI.with_repo_and_env(opts) do |repo, env|
16
+ bp = repo.evaluate_blueprint(args[0], env)
17
+ credentials = Amigrind::Config.aws_credentials(env)
18
+
19
+ builder = Amigrind::Builder.new(credentials, bp, repo)
20
+ template = builder.rackerize
21
+
22
+ puts template
23
+ end
24
+ end
25
+ end
26
+ )
27
+ end
28
+ end
@@ -0,0 +1,15 @@
1
+ module Amigrind
2
+ module CLI
3
+ ENVIRONMENTS = Cri::Command.define do
4
+ name 'environments'
5
+ description 'commands related to Amigrind environments in your Amigrind repo'
6
+
7
+ run do |_, _, cmd|
8
+ puts cmd.help
9
+ exit 0
10
+ end
11
+ end
12
+
13
+ ROOT.add_command(ENVIRONMENTS)
14
+ end
15
+ end
@@ -0,0 +1,23 @@
1
+ module Amigrind
2
+ module CLI
3
+ ENVIRONMENTS.add_command(
4
+ Cri::Command.define do
5
+ name 'list'
6
+ description 'lists Amigrind environments in the Amigrind repo'
7
+
8
+ CLI.repo_options(self)
9
+
10
+ CLI.output_format_options(self)
11
+
12
+ flag nil, :terse, "only print environment names"
13
+
14
+ run do |opts, _, cmd|
15
+ Amigrind::Repo.with_repo(path: opts[:'repo-path']) do |repo|
16
+ # TODO: provide more information
17
+ JSON.pretty_generate(repo.environment_names.map { |n| { name: n } })
18
+ end
19
+ end
20
+ end
21
+ )
22
+ end
23
+ end
@@ -0,0 +1,22 @@
1
+ module Amigrind
2
+ module CLI
3
+ ENVIRONMENTS.add_command(
4
+ Cri::Command.define do
5
+ name 'show'
6
+ description 'displays a single Amigrind environment'
7
+
8
+ CLI.repo_options(self)
9
+
10
+ CLI.output_format_options(self)
11
+
12
+ run do |opts, args, cmd|
13
+ Amigrind::Repo.with_repo(path: opts[:'repo-path']) do |repo|
14
+ repo.with_environment(args[0]) do |env|
15
+ YAML.dump(env)
16
+ end
17
+ end
18
+ end
19
+ end
20
+ )
21
+ end
22
+ end
@@ -0,0 +1,15 @@
1
+ module Amigrind
2
+ module CLI
3
+ INVENTORY = Cri::Command.define do
4
+ name 'inventory'
5
+ description 'commands related to the current Amigrind AMI inventory'
6
+
7
+ run do |_, _, cmd|
8
+ puts cmd.help
9
+ exit 0
10
+ end
11
+ end
12
+
13
+ ROOT.add_command(INVENTORY)
14
+ end
15
+ end
@@ -0,0 +1,28 @@
1
+ module Amigrind
2
+ module CLI
3
+ INVENTORY.add_command(
4
+ Cri::Command.define do
5
+ name 'add-to-channel'
6
+ description 'adds a given AMI to an Amigrind channel'
7
+
8
+ CLI.output_format_options(self)
9
+
10
+ CLI.repo_options(self)
11
+ CLI.environment_options(self)
12
+
13
+ run do |opts, args, _|
14
+ CLI.with_repo_and_env(opts) do |repo, env|
15
+ raise "usage: amigrind inventory add-to-channel BLUEPRINT_NAME AMI_NUMBER CHANNEL_NAME"\
16
+ unless args.size == 3
17
+
18
+ blueprint_name = args[0]
19
+ ami_number = args[1].to_i
20
+ channel_name = args[2].to_sym
21
+
22
+ repo.add_to_channel(env, blueprint_name, ami_number, channel_name)
23
+ end
24
+ end
25
+ end
26
+ )
27
+ end
28
+ end
@@ -0,0 +1,34 @@
1
+ module Amigrind
2
+ module CLI
3
+ INVENTORY.add_command(
4
+ Cri::Command.define do
5
+ name 'get-image'
6
+ description 'gets an image from an Amigrind channel'
7
+
8
+ CLI.output_format_options(self)
9
+
10
+ CLI.repo_options(self)
11
+ CLI.environment_options(self)
12
+
13
+ option nil, :'steps-back',
14
+ "number of steps back from the head of the channel to request (default: 0)",
15
+ argument: :required
16
+
17
+ run do |opts, args, _|
18
+ CLI.with_repo_and_env(opts) do |repo, env|
19
+ raise "usage: amigrind inventory get-image BLUEPRINT_NAME CHANNEL"\
20
+ unless args.size == 2
21
+
22
+ blueprint_name = args[0]
23
+ channel_name = args[1].to_sym
24
+
25
+ steps_back = (opts[:'steps-back'] || 0).to_i
26
+
27
+ image = repo.get_image_by_channel(env, blueprint_name, channel_name, steps_back)
28
+ puts JSON.pretty_generate(name: image.name, ami: image.id)
29
+ end
30
+ end
31
+ end
32
+ )
33
+ end
34
+ end
@@ -0,0 +1,14 @@
1
+ module Amigrind
2
+ module CLI
3
+ INVENTORY.add_command(
4
+ Cri::Command.define do
5
+ name 'list'
6
+ description 'lists Amigrind AMIs from the specified region'
7
+
8
+ run do |opts, args, _|
9
+ raise 'TODO; look in the AWS console for now'
10
+ end
11
+ end
12
+ )
13
+ end
14
+ end
@@ -0,0 +1,28 @@
1
+ module Amigrind
2
+ module CLI
3
+ INVENTORY.add_command(
4
+ Cri::Command.define do
5
+ name 'remove-from-channel'
6
+ description 'remove a given AMI from an Amigrind channel'
7
+
8
+ CLI.output_format_options(self)
9
+
10
+ CLI.repo_options(self)
11
+ CLI.environment_options(self)
12
+
13
+ run do |opts, args, _|
14
+ CLI.with_repo_and_env(opts) do |repo, env|
15
+ raise "usage: amigrind inventory remove-from-channel BLUEPRINT_NAME AMI_NUMBER CHANNEL_NAME"\
16
+ unless args.size == 3
17
+
18
+ blueprint_name = args[0]
19
+ ami_number = args[1].to_i
20
+ channel_name = args[2].to_sym
21
+
22
+ repo.remove_from_channel(env, blueprint_name, ami_number, channel_name)
23
+ end
24
+ end
25
+ end
26
+ )
27
+ end
28
+ end
@@ -0,0 +1,15 @@
1
+ module Amigrind
2
+ module CLI
3
+ REPO = Cri::Command.define do
4
+ name 'repo'
5
+ description 'commands related to managing and creating Amigrind repos'
6
+
7
+ run do |_, _, cmd|
8
+ puts cmd.help
9
+ exit 0
10
+ end
11
+ end
12
+
13
+ ROOT.add_command(REPO)
14
+ end
15
+ end