hippo-cli 1.1.2 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9340773519ba8065cba065f1e26edd5634df0456c62c5c7367e2e1e557173b1b
4
- data.tar.gz: d4e0939fcb6794659b5399a850d9ef76bc02eaad053fb7e32d2701c383480435
3
+ metadata.gz: f8b14eb5652ec29878ff1d7ccf48685ed7ea0d6c345587e16cd237ebcdf42609
4
+ data.tar.gz: f180aef6e85fc1cb857dfef0578e2a3a14c3c5e6cc89b3808b07c7e150d8f35d
5
5
  SHA512:
6
- metadata.gz: 5bdd945ebe90c00af7b70e8f3a776f2a9ded0cf6b5623f3e3612a41d86c42cb805808623226c29b77d88273c2c452459ff52dd80389e2a960a200bcb40de3fef
7
- data.tar.gz: 9f2f4b3ed1a7e8823d3fcc476d71c429422396dbbd1b1b8e18662ddec6aed40775b0f3bb015649fbfd16764ac5a9360b212308898ddbb9f5ecc0be854e6ae98b
6
+ metadata.gz: 26f0e6b8e35bcf6bdb751b00faff8be463d28c36dcff91640e67c90f2c99f9cafccd3c37ceb354170e8f654e1841d9915a06597abc48ad3477de83ada8453942
7
+ data.tar.gz: be4e0bc1f4180726bee41aece0f947882f9c37006a776107b073dcc6bab0be9525a86c5750e92d119b48622e7a55e91c7713422c4f0def824f9dd8424396025c
checksums.yaml.gz.sig CHANGED
Binary file
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)
data/cli/apply_config.rb CHANGED
@@ -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)
data/cli/console.rb CHANGED
@@ -3,10 +3,6 @@
3
3
  command :console do
4
4
  desc 'Open a console based on the 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
  option '-d', '--deployment [NAME]', 'The name of the deployment to use' do |value, options|
11
7
  options[:deployment] = value.to_s
12
8
  end
data/cli/create.rb CHANGED
@@ -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"
data/cli/deploy.rb CHANGED
@@ -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
data/cli/install.rb CHANGED
@@ -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)
data/cli/kubectl.rb CHANGED
@@ -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)
data/cli/logs.rb CHANGED
@@ -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
data/cli/objects.rb CHANGED
@@ -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
data/cli/package_list.rb CHANGED
@@ -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)
data/cli/package_notes.rb CHANGED
@@ -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
data/cli/package_test.rb CHANGED
@@ -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)
data/cli/prepare.rb CHANGED
@@ -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)
data/cli/readme.rb ADDED
@@ -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
data/cli/secrets.rb CHANGED
@@ -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)
data/cli/setup.rb ADDED
@@ -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, 'hippo.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
data/cli/stages.rb CHANGED
@@ -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
data/cli/status.rb CHANGED
@@ -3,10 +3,6 @@
3
3
  command :status do
4
4
  desc 'Show current status of the namespace'
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 '--full', 'Include all relevant objects in namespace' do |_value, options|
11
7
  options[:full] = true
12
8
  end
data/cli/tidy.rb ADDED
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ command :tidy do
4
+ desc 'Remove live objects that are not referenced by the manifest'
5
+ action do |context|
6
+ require 'hippo/cli'
7
+ cli = Hippo::CLI.setup(context)
8
+ cli.preflight
9
+
10
+ objects_to_prune = cli.stage.live_objects(pruneable_only: true)
11
+ if objects_to_prune.empty?
12
+ puts 'There are no objects to tidy'
13
+ exit 0
14
+ end
15
+
16
+ puts "Found #{objects_to_prune.size} object(s) to tidy"
17
+ puts
18
+ objects_to_prune.each do |obj|
19
+ $stdout.print ' ' + obj[:live].kind.ljust(25)
20
+ $stdout.print obj[:live].name
21
+ puts
22
+ end
23
+ puts
24
+
25
+ require 'hippo/util'
26
+ unless Hippo::Util.confirm('Do you wish to continue?')
27
+ puts 'No problem, not removing anything right now'
28
+ exit 0
29
+ end
30
+
31
+ cli.stage.delete_pruneable_objects
32
+ end
33
+ end
data/cli/update.rb ADDED
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ command :update do
4
+ desc 'Get the latest updates from the remote manifest'
5
+ action do
6
+ require 'hippo/working_directory'
7
+ wd = Hippo::WorkingDirectory.new
8
+
9
+ unless wd.can_update?
10
+ puts "No need to update #{wd.source_type} manifests"
11
+ exit 0
12
+ end
13
+
14
+ if wd.last_updated_at
15
+ puts "Last updated: #{wd.last_updated_at}"
16
+ else
17
+ puts 'Does not exist yet. Downloading for the first time.'
18
+ end
19
+
20
+ wd.update_from_remote(verbose: true)
21
+ end
22
+ end
data/cli/vars.rb CHANGED
@@ -3,10 +3,6 @@
3
3
  command :vars do
4
4
  desc 'Show all variables available for use in this 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)