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 +4 -4
- checksums.yaml.gz.sig +0 -0
- data/bin/hippo +1 -1
- data/cli/apply_config.rb +0 -4
- data/cli/apply_services.rb +0 -4
- data/cli/console.rb +0 -4
- data/cli/create.rb +9 -13
- data/cli/deploy.rb +0 -4
- data/cli/install.rb +0 -4
- data/cli/key.rb +1 -4
- data/cli/kubectl.rb +0 -4
- data/cli/logs.rb +0 -4
- data/cli/objects.rb +0 -4
- data/cli/package_install.rb +0 -4
- data/cli/package_list.rb +0 -4
- data/cli/package_notes.rb +0 -4
- data/cli/package_test.rb +0 -4
- data/cli/package_uninstall.rb +0 -4
- data/cli/package_upgrade.rb +0 -4
- data/cli/package_values.rb +0 -4
- data/cli/prepare.rb +0 -4
- data/cli/readme.rb +18 -0
- data/cli/run.rb +0 -4
- data/cli/secrets.rb +0 -4
- data/cli/setup.rb +71 -0
- data/cli/stages.rb +4 -7
- data/cli/status.rb +0 -4
- data/cli/tidy.rb +33 -0
- data/cli/update.rb +22 -0
- data/cli/vars.rb +0 -4
- data/lib/hippo/cli.rb +31 -27
- data/lib/hippo/image.rb +1 -0
- data/lib/hippo/manifest.rb +13 -17
- data/lib/hippo/repository_tag.rb +3 -2
- data/lib/hippo/secret_manager.rb +20 -19
- data/lib/hippo/stage.rb +75 -39
- data/lib/hippo/util.rb +61 -1
- data/lib/hippo/version.rb +1 -1
- data/lib/hippo/working_directory.rb +180 -0
- data/lib/hippo.rb +7 -0
- data/template/Hippofile +1 -2
- data.tar.gz.sig +0 -0
- metadata +7 -2
- metadata.gz.sig +0 -0
@@ -0,0 +1,180 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'hippo/manifest'
|
4
|
+
require 'hippo/util'
|
5
|
+
require 'hippo/error'
|
6
|
+
|
7
|
+
module Hippo
|
8
|
+
class WorkingDirectory
|
9
|
+
attr_reader :root
|
10
|
+
|
11
|
+
def initialize(root = FileUtils.pwd)
|
12
|
+
@root = root
|
13
|
+
end
|
14
|
+
|
15
|
+
# Return the path to the config file in this working directory
|
16
|
+
#
|
17
|
+
# @return [String]
|
18
|
+
def config_path
|
19
|
+
File.join(@root, 'manifest.yaml')
|
20
|
+
end
|
21
|
+
|
22
|
+
# Return the path to the local config file
|
23
|
+
#
|
24
|
+
# @return [String]
|
25
|
+
def local_config_path
|
26
|
+
File.join(@root, 'manifest.local.yaml')
|
27
|
+
end
|
28
|
+
|
29
|
+
# Return all the options configured in this working directory
|
30
|
+
#
|
31
|
+
# @return [Hash]
|
32
|
+
def options
|
33
|
+
return @options if @options
|
34
|
+
|
35
|
+
if File.file?(config_path)
|
36
|
+
@options = YAML.load_file(config_path)
|
37
|
+
if File.file?(local_config_path)
|
38
|
+
@options = @options.deep_merge(YAML.load_file(local_config_path))
|
39
|
+
end
|
40
|
+
@options
|
41
|
+
else
|
42
|
+
raise Error, "No manifest config file found at #{config_path}"
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
# Return the manifest objet for this working directory
|
47
|
+
#
|
48
|
+
# @return [Hippo::Manifest]
|
49
|
+
def manifest(update: true)
|
50
|
+
if update && !@updated_manifest
|
51
|
+
update_from_remote if can_update?
|
52
|
+
@updated_manifest = true
|
53
|
+
end
|
54
|
+
|
55
|
+
raise Error, 'No manifest path could be determined' if manifest_path.nil?
|
56
|
+
|
57
|
+
@manifest ||= Manifest.load_from_file(File.join(manifest_path, 'Hippofile'))
|
58
|
+
end
|
59
|
+
|
60
|
+
# Return the path to the manifest directory
|
61
|
+
#
|
62
|
+
# @return [String]
|
63
|
+
def manifest_path
|
64
|
+
case source_type
|
65
|
+
when 'local'
|
66
|
+
options.dig('source', 'localOptions', 'path')
|
67
|
+
when 'remote'
|
68
|
+
path = [remote_path] if remote_path
|
69
|
+
File.join(remote_root_path, *path)
|
70
|
+
else
|
71
|
+
raise Error, "Invalid source.type ('#{source_type}')"
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
# Return the type of manifest
|
76
|
+
#
|
77
|
+
# @return [String]
|
78
|
+
def source_type
|
79
|
+
options.dig('source', 'type')
|
80
|
+
end
|
81
|
+
|
82
|
+
# Return the path on the local filesystem that the remote repository
|
83
|
+
# should be stored in.
|
84
|
+
#
|
85
|
+
# @return [String]
|
86
|
+
def remote_root_path
|
87
|
+
repo_ref = Digest::SHA1.hexdigest([remote_repository, remote_branch].join('---'))
|
88
|
+
File.join(Hippo.tmp_root, 'manifests', repo_ref)
|
89
|
+
end
|
90
|
+
|
91
|
+
# Return the branch to use from the remote repository
|
92
|
+
#
|
93
|
+
# @return [String]
|
94
|
+
def remote_branch
|
95
|
+
options.dig('source', 'remoteOptions', 'branch') || 'master'
|
96
|
+
end
|
97
|
+
|
98
|
+
# Return the URL to the remote repository
|
99
|
+
#
|
100
|
+
# @return [String]
|
101
|
+
def remote_repository
|
102
|
+
options.dig('source', 'remoteOptions', 'repository')
|
103
|
+
end
|
104
|
+
|
105
|
+
# Return the path within the remote repository that we wish to work
|
106
|
+
# with.
|
107
|
+
#
|
108
|
+
# @return [String]
|
109
|
+
def remote_path
|
110
|
+
options.dig('source', 'remoteOptions', 'path')
|
111
|
+
end
|
112
|
+
|
113
|
+
# Update the local cached copy of the manifest from the remote
|
114
|
+
#
|
115
|
+
# @return [Boolean]
|
116
|
+
def update_from_remote(verbose: false)
|
117
|
+
return false unless source_type == 'remote'
|
118
|
+
|
119
|
+
Util.action "Updating manifest from #{remote_repository}..." do
|
120
|
+
if File.directory?(remote_root_path)
|
121
|
+
Util.system("git -C #{remote_root_path} fetch")
|
122
|
+
else
|
123
|
+
FileUtils.mkdir_p(File.dirname(remote_root_path))
|
124
|
+
Util.system("git clone #{remote_repository} #{remote_root_path}")
|
125
|
+
end
|
126
|
+
|
127
|
+
Util.system("git -C #{remote_root_path} checkout origin/#{remote_branch}")
|
128
|
+
File.open(update_timestamp_path, 'w') { |f| f.write(Time.now.to_i.to_s + "\n") }
|
129
|
+
end
|
130
|
+
|
131
|
+
if verbose
|
132
|
+
puts
|
133
|
+
puts " Repository....: \e[33m#{wd.remote_repository}\e[0m"
|
134
|
+
puts " Branch........: \e[33m#{wd.remote_branch}\e[0m"
|
135
|
+
puts " Path..........: \e[33m#{wd.remote_path}\e[0m"
|
136
|
+
puts
|
137
|
+
end
|
138
|
+
|
139
|
+
true
|
140
|
+
end
|
141
|
+
|
142
|
+
# Return the time this manifest was last updated
|
143
|
+
#
|
144
|
+
# @return [Time, nil]
|
145
|
+
def last_updated_at
|
146
|
+
if File.file?(update_timestamp_path)
|
147
|
+
timestamp = File.read(update_timestamp_path)
|
148
|
+
Time.at(timestamp.strip.to_i)
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
# Return the path to the file where the last updated timestamp
|
153
|
+
# is stored
|
154
|
+
#
|
155
|
+
# @return [String]
|
156
|
+
def update_timestamp_path
|
157
|
+
File.join(remote_root_path + '.uptime-timestamp')
|
158
|
+
end
|
159
|
+
|
160
|
+
# Can this working directory be updated?
|
161
|
+
#
|
162
|
+
# @return [Boolean]
|
163
|
+
def can_update?
|
164
|
+
source_type == 'remote'
|
165
|
+
end
|
166
|
+
|
167
|
+
# Load all stages that are available in this working directory
|
168
|
+
#
|
169
|
+
# @return [Hash<Symbol, Hippo::Stage>]
|
170
|
+
def stages
|
171
|
+
objects = Util.load_objects_from_path(File.join(@root, '**', 'config.{yml,yaml}'))
|
172
|
+
objects.each_with_object({}) do |(path, objects), hash|
|
173
|
+
objects.each do |obj|
|
174
|
+
stage = Stage.new(self, File.dirname(path), obj)
|
175
|
+
hash[stage.name] = stage
|
176
|
+
end
|
177
|
+
end
|
178
|
+
end
|
179
|
+
end
|
180
|
+
end
|
data/lib/hippo.rb
CHANGED
data/template/Hippofile
CHANGED
@@ -7,7 +7,7 @@ name: myapp
|
|
7
7
|
|
8
8
|
images:
|
9
9
|
main:
|
10
|
-
host:
|
10
|
+
host: registry.mycompany.commit
|
11
11
|
name: myorg/myapp
|
12
12
|
tag: latest
|
13
13
|
# Alternatively, load the tag name from the current HEAD commit of a
|
@@ -17,7 +17,6 @@ images:
|
|
17
17
|
# fromRepository:
|
18
18
|
# url: git@github.com:myorg/myapp
|
19
19
|
# branch: master
|
20
|
-
|
21
20
|
# If you wish, you can define a console command that allows you to easil
|
22
21
|
# open a console using `hippo [stage] console`
|
23
22
|
#
|
data.tar.gz.sig
CHANGED
Binary file
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hippo-cli
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam Cooke
|
@@ -30,7 +30,7 @@ cert_chain:
|
|
30
30
|
3wUJNGnT5XYq+qvTqmjkTSTfdGvZCM63C6bGdN5CAyMokGOOatGqyCMAONolWnfC
|
31
31
|
gm3t2GWWrxY=
|
32
32
|
-----END CERTIFICATE-----
|
33
|
-
date: 2020-02-
|
33
|
+
date: 2020-02-17 00:00:00.000000000 Z
|
34
34
|
dependencies:
|
35
35
|
- !ruby/object:Gem::Dependency
|
36
36
|
name: encryptor
|
@@ -161,10 +161,14 @@ files:
|
|
161
161
|
- cli/package_upgrade.rb
|
162
162
|
- cli/package_values.rb
|
163
163
|
- cli/prepare.rb
|
164
|
+
- cli/readme.rb
|
164
165
|
- cli/run.rb
|
165
166
|
- cli/secrets.rb
|
167
|
+
- cli/setup.rb
|
166
168
|
- cli/stages.rb
|
167
169
|
- cli/status.rb
|
170
|
+
- cli/tidy.rb
|
171
|
+
- cli/update.rb
|
168
172
|
- cli/vars.rb
|
169
173
|
- cli/version.rb
|
170
174
|
- lib/hippo.rb
|
@@ -183,6 +187,7 @@ files:
|
|
183
187
|
- lib/hippo/stage.rb
|
184
188
|
- lib/hippo/util.rb
|
185
189
|
- lib/hippo/version.rb
|
190
|
+
- lib/hippo/working_directory.rb
|
186
191
|
- template/Hippofile
|
187
192
|
homepage: https://github.com/adamcooke/hippo
|
188
193
|
licenses:
|
metadata.gz.sig
CHANGED
Binary file
|