hippo-cli 1.1.1 → 1.2.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 96a621d666288ef2ec40ae5384c0a2ba823f011cd2384db2d0eee53d2dbf6fc1
4
- data.tar.gz: 05cf19519259186bd789f02d996b580ba76a7b7e9f598b308c2705c636d25e6c
3
+ metadata.gz: 7c8e44785f4199b58a0a78270b0b2aa856076b59b86c4ba7411fdbe821a2893e
4
+ data.tar.gz: 0403d0c48ded78e1fe036964d06ad259a3d64d86a1bcc4ed91b5cff3420e9628
5
5
  SHA512:
6
- metadata.gz: 911cfb6bdbbcf16ef73a5dc1d36bd53aa06dc7f94e9f53a9cc0aa964400a266cc25583d97651684ebf3394f340f780520bfb7af0e189a656dd48d2338beed7fb
7
- data.tar.gz: 466ec97e4b4a4a1dcdd223f18be57fbeddb72aea29aacc1d64fc2b728ca807ec0865619024773b49613ac19aa14dcfea275bcdd9a3cdfa6395ea1dc601b67855
6
+ metadata.gz: 53c73c8339bc4d98cfa3870e2e9d3593a63885ecda1247357e1f9e9826e5dcfb8b0509aef0dd5999b6af3e859d37952aac6d387bdffff4b382f1a8935547ebb4
7
+ data.tar.gz: 6f594edae7085e08135d32d9871a1acb0a6e371689338e872ce6772e41545bfd1efd73d13d83e52967b857044ff9ff9a2b61e9e8628a680011a8e2f34cceb396
data/bin/hippo CHANGED
@@ -8,7 +8,7 @@ require 'hippo/error'
8
8
  require 'hippo/version'
9
9
  require 'swamp/cli'
10
10
 
11
- COMMANDS_WITHOUT_STAGE = %w[help init version stages].freeze
11
+ COMMANDS_WITHOUT_STAGE = %w[help init version stages update setup].freeze
12
12
 
13
13
  begin
14
14
  cli = Swamp::CLI.new(:hippo, version: Hippo::VERSION)
@@ -3,10 +3,6 @@
3
3
  command :'apply-config' do
4
4
  desc 'Apply configuration'
5
5
 
6
- option '-h', '--hippofile [RECIPE]', 'The path to the Hippofile (defaults: ./Hippofile)' do |value, options|
7
- options[:hippofile] = value.to_s
8
- end
9
-
10
6
  action do |context|
11
7
  require 'hippo/cli'
12
8
  cli = Hippo::CLI.setup(context)
@@ -3,10 +3,6 @@
3
3
  command :'apply-services' do
4
4
  desc 'Apply service configuration'
5
5
 
6
- option '-h', '--hippofile [RECIPE]', 'The path to the Hippofile (defaults: ./Hippofile)' do |value, options|
7
- options[:hippofile] = value.to_s
8
- end
9
-
10
6
  action do |context|
11
7
  require 'hippo/cli'
12
8
  cli = Hippo::CLI.setup(context)
@@ -3,10 +3,6 @@
3
3
  command :create do
4
4
  desc 'Create a new stage'
5
5
 
6
- option '-h', '--hippofile [RECIPE]', 'The path to the Hippofile (defaults: ./Hippofile)' do |value, options|
7
- options[:hippofile] = value.to_s
8
- end
9
-
10
6
  option '-n', '--namespace [NAMESPACE]', 'The namespace for the new stage' do |value, options|
11
7
  options[:namespace] = value
12
8
  end
@@ -21,10 +17,10 @@ command :create do
21
17
 
22
18
  action do |context|
23
19
  require 'hippo/manifest'
24
- manifest = Hippo::Manifest.load_from_file(context.options[:hippofile] || './Hippofile')
20
+ wd = Hippo::WorkingDirectory.new
25
21
 
26
22
  stage_name = CURRENT_STAGE
27
- stage_path = File.join(manifest.root, 'stages', "#{stage_name}.yaml")
23
+ stage_path = File.join(wd.root, stage_name, 'config.yaml')
28
24
 
29
25
  if !context.options[:force] && File.file?(stage_path)
30
26
  puts "\e[31mA stage named '#{stage_name}' already exists. Use --force to overwrite configuration.\e[0m"
@@ -35,7 +31,7 @@ command :create do
35
31
 
36
32
  namespace = context.options[:namespace]
37
33
  if namespace.nil?
38
- namespace = Hippo::Util.ask('Enter a namespace for this stage', default: "#{manifest.name}-#{stage_name}")
34
+ namespace = Hippo::Util.ask('Enter a namespace for this stage', default: "#{wd.manifest.name}-#{stage_name}")
39
35
  end
40
36
 
41
37
  context_name = context.options[:context]
@@ -49,13 +45,13 @@ command :create do
49
45
  yaml['context'] = context_name
50
46
 
51
47
  require 'hippo/bootstrap_parser'
52
- yaml['config'] = Hippo::BootstrapParser.parse(manifest.bootstrap['config'])
48
+ yaml['config'] = Hippo::BootstrapParser.parse(wd.manifest.bootstrap['config'])
53
49
 
54
50
  require 'hippo/stage'
55
- stage = Hippo::Stage.new(manifest, yaml)
51
+ stage = Hippo::Stage.new(wd, File.dirname(stage_path), yaml)
56
52
 
57
53
  require 'hippo/cli'
58
- cli = Hippo::CLI.new(manifest, stage)
54
+ cli = Hippo::CLI.new(wd, stage)
59
55
  cli.apply_namespace
60
56
 
61
57
  if stage.secret_manager.key_available?
@@ -67,11 +63,11 @@ command :create do
67
63
 
68
64
  FileUtils.mkdir_p(File.dirname(stage_path))
69
65
  File.open(stage_path, 'w') { |f| f.write(yaml.to_yaml.sub(/\A---\n/m, '')) }
70
- puts "Written new stage file to stages/#{stage.name}.yaml"
66
+ puts "Written new stage file to #{stage.name}/config.yaml"
71
67
 
72
- secrets = Hippo::BootstrapParser.parse(manifest.bootstrap['secrets'])
68
+ secrets = Hippo::BootstrapParser.parse(wd.manifest.bootstrap['secrets'])
73
69
  stage.secret_manager.write_file(secrets.to_yaml)
74
- puts "Written encrypted secrets into secrets/#{stage.name}.yaml"
70
+ puts "Written encrypted secrets into #{stage.name}/secrets.yaml"
75
71
 
76
72
  puts
77
73
  puts "\e[32mStage '#{stage.name}' has been created successfully.\e[0m"
@@ -3,10 +3,6 @@
3
3
  command :deploy do
4
4
  desc 'Deploy the application to Kubernetes (including image build/push)'
5
5
 
6
- option '-h', '--hippofile [RECIPE]', 'The path to the Hippofile (defaults: ./Hippofile)' do |value, options|
7
- options[:hippofile] = value.to_s
8
- end
9
-
10
6
  option '--no-jobs', 'Do not run the deploy jobs' do |_value, options|
11
7
  options[:jobs] = false
12
8
  end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ command :exec do
4
+ desc 'Exec a command on a given pod'
5
+
6
+ action do |context|
7
+ require 'hippo/cli'
8
+ cli = Hippo::CLI.setup(context)
9
+ cli.preflight
10
+
11
+ command = context.args[2]
12
+ if command.nil?
13
+ raise Error, 'Must specify command alias as first argument after `exec`'
14
+ end
15
+
16
+ command = cli.stage.command(command)
17
+ raise Error, "Invalid command alias `#{context.args[2]}`" if command.nil?
18
+
19
+ command_to_run = ([command[:command]] + context.args[3..-1]).join(' ')
20
+
21
+ exec cli.stage.kubectl("exec -it #{command[:target]} -- #{command_to_run}").join(' ')
22
+ end
23
+ end
@@ -3,10 +3,6 @@
3
3
  command :install do
4
4
  desc 'Run installation jobs for the application'
5
5
 
6
- option '-h', '--hippofile [RECIPE]', 'The path to the Hippofile (defaults: ./Hippofile)' do |value, options|
7
- options[:hippofile] = value.to_s
8
- end
9
-
10
6
  option '--no-deploy', 'Do not deploy after install' do |_value, options|
11
7
  options[:deploy] = false
12
8
  end
data/cli/key.rb CHANGED
@@ -3,13 +3,10 @@
3
3
  command :key do
4
4
  desc 'Display/generate details about the secret encryption key'
5
5
 
6
- option '-h', '--hippofile [RECIPE]', 'The path to the Hippofile (defaults: ./Hippofile)' do |value, options|
7
- options[:hippofile] = value.to_s
8
- end
9
-
10
6
  option '-g', '--generate', 'Generate a new key' do |_value, options|
11
7
  options[:generate] = true
12
8
  end
9
+
13
10
  action do |context|
14
11
  require 'hippo/cli'
15
12
  cli = Hippo::CLI.setup(context)
@@ -3,10 +3,6 @@
3
3
  command :kubectl do
4
4
  desc 'Execute kubectl commands with the correct namespace for the stage'
5
5
 
6
- option '-h', '--hippofile [RECIPE]', 'The path to the Hippofile (defaults: ./Hippofile)' do |value, options|
7
- options[:hippofile] = value.to_s
8
- end
9
-
10
6
  action do |context|
11
7
  require 'hippo/cli'
12
8
  cli = Hippo::CLI.setup(context)
@@ -3,10 +3,6 @@
3
3
  command :logs do
4
4
  desc 'Display logs for a particular pod'
5
5
 
6
- option '-h', '--hippofile [RECIPE]', 'The path to the Hippofile (defaults: ./Hippofile)' do |value, options|
7
- options[:hippofile] = value.to_s
8
- end
9
-
10
6
  option '-p', '--pod [POD]', 'The name of the pod' do |value, options|
11
7
  options[:pod] = value
12
8
  end
@@ -3,10 +3,6 @@
3
3
  command :objects do
4
4
  desc 'Display all objects that will be exported'
5
5
 
6
- option '-h', '--hippofile [RECIPE]', 'The path to the Hippofile (defaults: ./Hippofile)' do |value, options|
7
- options[:hippofile] = value.to_s
8
- end
9
-
10
6
  option '-t', '--type [TYPE]', 'Limit which type of object to return (one of config, deployments or services)' do |value, options|
11
7
  options[:type] = value
12
8
  end
@@ -3,10 +3,6 @@
3
3
  command :'package:install' do
4
4
  desc 'Install a named helm package'
5
5
 
6
- option '-h', '--hippofile [RECIPE]', 'The path to the Hippofile (defaults: ./Hippofile)' do |value, options|
7
- options[:hippofile] = value.to_s
8
- end
9
-
10
6
  option '-p', '--package [NAME]', 'The name of the package to install' do |value, options|
11
7
  options[:package] = value
12
8
  end
@@ -3,10 +3,6 @@
3
3
  command :'package:list' do
4
4
  desc 'List all available packages with status'
5
5
 
6
- option '-h', '--hippofile [RECIPE]', 'The path to the Hippofile (defaults: ./Hippofile)' do |value, options|
7
- options[:hippofile] = value.to_s
8
- end
9
-
10
6
  action do |context|
11
7
  require 'hippo/cli'
12
8
  cli = Hippo::CLI.setup(context)
@@ -3,10 +3,6 @@
3
3
  command :'package:notes' do
4
4
  desc 'Show notes about an installed Helm package'
5
5
 
6
- option '-h', '--hippofile [RECIPE]', 'The path to the Hippofile (defaults: ./Hippofile)' do |value, options|
7
- options[:hippofile] = value.to_s
8
- end
9
-
10
6
  option '-p', '--package [NAME]', 'The name of the package to install' do |value, options|
11
7
  options[:package] = value
12
8
  end
@@ -3,10 +3,6 @@
3
3
  command :'package:test' do
4
4
  desc 'Test a package installation'
5
5
 
6
- option '-h', '--hippofile [RECIPE]', 'The path to the Hippofile (defaults: ./Hippofile)' do |value, options|
7
- options[:hippofile] = value.to_s
8
- end
9
-
10
6
  option '-p', '--package [NAME]', 'The name of the package' do |value, options|
11
7
  options[:package] = value
12
8
  end
@@ -3,10 +3,6 @@
3
3
  command :'package:uninstall' do
4
4
  desc 'Uninstall a package'
5
5
 
6
- option '-h', '--hippofile [RECIPE]', 'The path to the Hippofile (defaults: ./Hippofile)' do |value, options|
7
- options[:hippofile] = value.to_s
8
- end
9
-
10
6
  option '-p', '--package [NAME]', 'The name of the package' do |value, options|
11
7
  options[:package] = value
12
8
  end
@@ -3,10 +3,6 @@
3
3
  command :'package:upgrade' do
4
4
  desc 'Upgrade a package'
5
5
 
6
- option '-h', '--hippofile [RECIPE]', 'The path to the Hippofile (defaults: ./Hippofile)' do |value, options|
7
- options[:hippofile] = value.to_s
8
- end
9
-
10
6
  option '-p', '--package [NAME]', 'The name of the package' do |value, options|
11
7
  options[:package] = value
12
8
  end
@@ -3,10 +3,6 @@
3
3
  command :'package:values' do
4
4
  desc 'Display the values file that will be used for all packages'
5
5
 
6
- option '-h', '--hippofile [RECIPE]', 'The path to the Hippofile (defaults: ./Hippofile)' do |value, options|
7
- options[:hippofile] = value.to_s
8
- end
9
-
10
6
  action do |context|
11
7
  require 'hippo/cli'
12
8
  cli = Hippo::CLI.setup(context)
@@ -16,7 +12,7 @@ command :'package:values' do
16
12
  puts "\e[33m#{'=' * 80}"
17
13
  puts package.name
18
14
  puts "#{'=' * 80}\e[0m"
19
- puts package.final_values.to_yaml.sub(/\A---\n/, '')
15
+ puts package.final_values.to_yaml(line_width: -1).sub(/\A---\n/, '')
20
16
  end
21
17
  end
22
18
  end
@@ -3,10 +3,6 @@
3
3
  command :prepare do
4
4
  desc 'Prepare Kubernetes namespace (including installing all packages)'
5
5
 
6
- option '-h', '--hippofile [RECIPE]', 'The path to the Hippofile (defaults: ./Hippofile)' do |value, options|
7
- options[:hippofile] = value.to_s
8
- end
9
-
10
6
  action do |context|
11
7
  require 'hippo/cli'
12
8
  cli = Hippo::CLI.setup(context)
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ command :readme do
4
+ desc 'Display the README'
5
+
6
+ action do |context|
7
+ require 'hippo/cli'
8
+ cli = Hippo::CLI.setup(context)
9
+ cli.preflight
10
+
11
+ readme = cli.stage.readme
12
+ raise Error, 'No README is configured for this application' if readme.nil?
13
+
14
+ puts '=' * 80
15
+ puts readme
16
+ puts '=' * 80
17
+ end
18
+ end
data/cli/run.rb CHANGED
@@ -3,10 +3,6 @@
3
3
  command :run do
4
4
  desc 'Create and run a pod using the given image'
5
5
 
6
- option '-h', '--hippofile [RECIPE]', 'The path to the Hippofile (defaults: ./Hippofile)' do |value, options|
7
- options[:hippofile] = value.to_s
8
- end
9
-
10
6
  option '--command [COMMAND]', 'The command to run (defaults to /bin/bash)' do |value, options|
11
7
  options[:command] = value.to_s
12
8
  end
@@ -16,7 +12,7 @@ command :run do
16
12
  cli = Hippo::CLI.setup(context)
17
13
  cli.preflight
18
14
 
19
- image = cli.stage.images.values.first
15
+ image = cli.stage.images[context.options[:image]] || cli.stage.images.values.first
20
16
  raise Error, "No image exists at #{image.image_url}" unless image.exists?
21
17
 
22
18
  command = context.options[:command] || '/bin/bash'
@@ -3,10 +3,6 @@
3
3
  command :secrets do
4
4
  desc 'Create/edit an encrypted secrets file'
5
5
 
6
- option '-h', '--hippofile [RECIPE]', 'The path to the Hippofile (defaults: ./Hippofile)' do |value, options|
7
- options[:hippofile] = value.to_s
8
- end
9
-
10
6
  action do |context|
11
7
  require 'hippo/cli'
12
8
  cli = Hippo::CLI.setup(context)
@@ -0,0 +1,71 @@
1
+ # frozen_string_literal: true
2
+
3
+ command :setup do
4
+ desc 'Create a new configuration directory'
5
+
6
+ option '--local [PATH]', 'Use a local manifest from the given path' do |value, options|
7
+ options[:local] = value
8
+ end
9
+
10
+ option '--remote [REPO]', 'Use a repo manifest from the given repository' do |value, options|
11
+ options[:remote] = value
12
+ end
13
+
14
+ option '-p [PATH]', '--path [PATH]', 'Path within the remote repository' do |value, options|
15
+ options[:path] = value
16
+ end
17
+
18
+ option '-b [BRANCH]', '--branch [BRANCH]', 'Branch on remote repository' do |value, options|
19
+ options[:branch] = value
20
+ end
21
+
22
+ action do |context|
23
+ path = context.args[0]
24
+ raise Error, 'Provide path as first argument' if path.nil?
25
+
26
+ path = File.expand_path(path)
27
+
28
+ raise Error, "Directory already exists at #{path}" if File.exist?(path)
29
+
30
+ if context.options[:local] && context.options[:remote]
31
+ raise Error, 'Only specify --local OR --remote'
32
+ end
33
+
34
+ require 'fileutils'
35
+ FileUtils.mkdir_p(path)
36
+ source = {}
37
+ if local_path = context.options[:local]
38
+ source['type'] = 'local'
39
+ source['localOptions'] = {
40
+ 'path' => File.expand_path(local_path)
41
+ }
42
+ elsif repo = context.options[:remote]
43
+ source['type'] = 'remote'
44
+ source['remoteOptions'] = { 'repository' => repo }
45
+ if context.options[:path]
46
+ source['remoteOptions']['path'] = context.options[:path]
47
+ end
48
+ if context.options[:branch]
49
+ source['remoteOptions']['branch'] = context.options[:branch]
50
+ end
51
+ end
52
+
53
+ require 'yaml'
54
+ config = { 'source' => source }
55
+ File.open(File.join(path, 'manifest.yaml'), 'w') { |f| f.write(config.to_yaml) }
56
+ puts "Created configuration directory at #{path}"
57
+
58
+ require 'hippo/working_directory'
59
+ wd = Hippo::WorkingDirectory.new(path)
60
+ if wd.can_update?
61
+ puts 'Updating local copy of remote repository...'
62
+ wd.update_from_remote
63
+ puts "\e[32mUpdate completed successfully.\e[0m"
64
+ puts
65
+ puts " Repository....: \e[33m#{wd.remote_repository}\e[0m"
66
+ puts " Branch........: \e[33m#{wd.remote_branch}\e[0m"
67
+ puts " Path..........: \e[33m#{wd.remote_path}\e[0m"
68
+ puts
69
+ end
70
+ end
71
+ end
@@ -2,15 +2,12 @@
2
2
 
3
3
  command :stages do
4
4
  desc 'List all stages that are available'
5
- option '-h', '--hippofile [RECIPE]', 'The path to the Hippofile (defaults: ./Hippofile)' do |value, options|
6
- options[:hippofile] = value.to_s
7
- end
8
5
 
9
- action do |context|
6
+ action do |_context|
10
7
  require 'hippo/manifest'
11
- manifest = Hippo::Manifest.load_from_file(context.options[:hippofile] || './Hippofile')
8
+ wd = Hippo::WorkingDirectory.new
12
9
 
13
- if manifest.stages.empty?
10
+ if wd.stages.empty?
14
11
  puts 'There are no stages configured yet.'
15
12
  puts 'Use the following command to create one:'
16
13
  puts
@@ -19,7 +16,7 @@ command :stages do
19
16
  exit 0
20
17
  end
21
18
 
22
- manifest.stages.each do |_, stage|
19
+ wd.stages.each do |_, stage|
23
20
  puts "- #{stage.name}"
24
21
  end
25
22
  end