uffizzi-cli 0.7.3 → 0.8.0
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/README.md +6 -0
- data/lib/uffizzi/cli/preview.rb +39 -15
- data/lib/uffizzi/config_file.rb +9 -5
- data/lib/uffizzi/services/preview_service.rb +13 -25
- data/lib/uffizzi/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 17ac6475e11de6c24b044f64e19541587683aaad4bd3b72cafbc5160b92364a8
|
4
|
+
data.tar.gz: 228b5a14b359af42f9698eba6bd98c94155dfd05791b55378dfc99cf6ffe365d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4d9e8d2f99a297d2fac8452bc03e180c71f7b1e05d71ac333704b2e1649fffdfd2bb4f6b86ffb0d186e441629cb809b2d5c450984b2a36af49080b9b08fab700
|
7
|
+
data.tar.gz: ce3cdb192caa7ab39a7edec3b5d01788505cae7a4a2d5f440b99ef203f86f18d67c22ec5c07ef67603dc6ebb35871857f3f536ac71720b4634c46579f8e771d6
|
data/README.md
CHANGED
@@ -177,3 +177,9 @@ Supported credential types - `docker-hub`, `acr`, `ecr`, `gcr`
|
|
177
177
|
## Contributing
|
178
178
|
|
179
179
|
Bug reports and pull requests are welcome on GitHub at https://github.com/UffizziCloud/uffizzi_cli. See `CONTRIBUTING.md` in this repository.
|
180
|
+
|
181
|
+
## License
|
182
|
+
|
183
|
+
This project is licensed under the terms of the Apache-2.0 license.
|
184
|
+
|
185
|
+
See this license at [`LICENSE`](LICENSE).
|
data/lib/uffizzi/cli/preview.rb
CHANGED
@@ -23,7 +23,7 @@ module Uffizzi
|
|
23
23
|
run('create', file_path: file_path)
|
24
24
|
end
|
25
25
|
|
26
|
-
desc 'uffizzi preview update [DEPLOYMENT_ID] [COMPOSE_FILE]', '
|
26
|
+
desc 'uffizzi preview update [DEPLOYMENT_ID] [COMPOSE_FILE]', 'Update a preview'
|
27
27
|
method_option :output, required: false, type: :string, aliases: '-o', enum: ['json', 'github-action']
|
28
28
|
def update(deployment_name, file_path)
|
29
29
|
run('update', deployment_name: deployment_name, file_path: file_path)
|
@@ -86,33 +86,39 @@ module Uffizzi
|
|
86
86
|
params = file_path.nil? ? {} : prepare_params(file_path)
|
87
87
|
response = create_deployment(ConfigFile.read_option(:server), project_slug, params)
|
88
88
|
|
89
|
-
if ResponseHelper.created?(response)
|
90
|
-
deployment = response[:body][:deployment]
|
91
|
-
success_message = "Preview created with name deployment-#{deployment[:id]}"
|
92
|
-
PreviewService.start_deploy_containers(project_slug, deployment, success_message)
|
93
|
-
else
|
89
|
+
if !ResponseHelper.created?(response)
|
94
90
|
ResponseHelper.handle_failed_response(response)
|
95
91
|
end
|
92
|
+
|
93
|
+
deployment = response[:body][:deployment]
|
94
|
+
Uffizzi.ui.say("Preview created with name deployment-#{deployment[:id]}")
|
95
|
+
|
96
|
+
success = PreviewService.run_containers_deploy(project_slug, deployment)
|
97
|
+
|
98
|
+
display_deployment_data(deployment, success)
|
96
99
|
rescue SystemExit, Interrupt, SocketError
|
97
100
|
deployment_id = response[:body][:deployment][:id]
|
98
|
-
handle_preview_interruption(deployment_id,
|
101
|
+
handle_preview_interruption(deployment_id, ConfigFile.read_option(:server), project_slug)
|
99
102
|
end
|
100
103
|
|
101
104
|
def handle_update_command(deployment_name, file_path, project_slug)
|
102
105
|
deployment_id = PreviewService.read_deployment_id(deployment_name)
|
103
106
|
|
104
|
-
|
107
|
+
raise Uffizzi::Error.new("Preview should be specified in 'deployment-PREVIEW_ID' format") if deployment_id.nil?
|
105
108
|
|
106
109
|
params = prepare_params(file_path)
|
107
110
|
response = update_deployment(ConfigFile.read_option(:server), project_slug, deployment_id, params)
|
108
111
|
|
109
|
-
if ResponseHelper.ok?(response)
|
110
|
-
deployment = response[:body][:deployment]
|
111
|
-
success_message = "Preview with ID deployment-#{deployment_id} was successfully updated."
|
112
|
-
PreviewService.start_deploy_containers(project_slug, deployment, success_message)
|
113
|
-
else
|
112
|
+
if !ResponseHelper.ok?(response)
|
114
113
|
ResponseHelper.handle_failed_response(response)
|
115
114
|
end
|
115
|
+
|
116
|
+
deployment = response[:body][:deployment]
|
117
|
+
Uffizzi.ui.say("Preview with ID deployment-#{deployment_id} was successfully updated.")
|
118
|
+
|
119
|
+
success = PreviewService.run_containers_deploy(project_slug, deployment)
|
120
|
+
|
121
|
+
display_deployment_data(deployment, success)
|
116
122
|
end
|
117
123
|
|
118
124
|
def handle_events_command(deployment_name, project_slug)
|
@@ -218,8 +224,8 @@ module Uffizzi
|
|
218
224
|
}
|
219
225
|
end
|
220
226
|
|
221
|
-
def handle_preview_interruption(deployment_id,
|
222
|
-
deletion_response = delete_deployment(
|
227
|
+
def handle_preview_interruption(deployment_id, server, project_slug)
|
228
|
+
deletion_response = delete_deployment(server, project_slug, deployment_id)
|
223
229
|
deployment_name = "deployment-#{deployment_id}"
|
224
230
|
preview_deletion_message = if ResponseHelper.no_content?(deletion_response)
|
225
231
|
"The preview #{deployment_name} has been disabled."
|
@@ -229,5 +235,23 @@ module Uffizzi
|
|
229
235
|
|
230
236
|
raise Uffizzi::Error.new("The preview creation was interrupted. #{preview_deletion_message}")
|
231
237
|
end
|
238
|
+
|
239
|
+
def display_deployment_data(deployment, success)
|
240
|
+
if Uffizzi.ui.output_format.nil?
|
241
|
+
Uffizzi.ui.say('Done')
|
242
|
+
preview_url = "https://#{deployment[:preview_url]}"
|
243
|
+
Uffizzi.ui.say(preview_url) if success
|
244
|
+
else
|
245
|
+
deployment_data = build_deployment_data(deployment)
|
246
|
+
Uffizzi.ui.output(deployment_data)
|
247
|
+
end
|
248
|
+
end
|
249
|
+
|
250
|
+
def build_deployment_data(deployment)
|
251
|
+
{
|
252
|
+
id: "deployment-#{deployment[:id]}",
|
253
|
+
url: "https://#{deployment[:preview_url]}",
|
254
|
+
}
|
255
|
+
end
|
232
256
|
end
|
233
257
|
end
|
data/lib/uffizzi/config_file.rb
CHANGED
@@ -8,17 +8,21 @@ module Uffizzi
|
|
8
8
|
CONFIG_PATH = "#{Dir.home}/.config/uffizzi/config_default.json"
|
9
9
|
|
10
10
|
class << self
|
11
|
+
def config_path
|
12
|
+
CONFIG_PATH
|
13
|
+
end
|
14
|
+
|
11
15
|
def create(account_id, cookie, server)
|
12
16
|
data = prepare_config_data(account_id, cookie, server)
|
13
17
|
data.each_pair { |key, value| write_option(key, value) }
|
14
18
|
end
|
15
19
|
|
16
20
|
def delete
|
17
|
-
File.delete(
|
21
|
+
File.delete(config_path) if exists?
|
18
22
|
end
|
19
23
|
|
20
24
|
def exists?
|
21
|
-
File.exist?(
|
25
|
+
File.exist?(config_path)
|
22
26
|
end
|
23
27
|
|
24
28
|
def read_option(option)
|
@@ -79,7 +83,7 @@ module Uffizzi
|
|
79
83
|
end
|
80
84
|
|
81
85
|
def read
|
82
|
-
data = File.read(
|
86
|
+
data = File.read(config_path)
|
83
87
|
options = data.split("\n")
|
84
88
|
options.reduce({}) do |acc, option|
|
85
89
|
key, value = option.split('=', 2)
|
@@ -112,11 +116,11 @@ module Uffizzi
|
|
112
116
|
end
|
113
117
|
|
114
118
|
def create_file
|
115
|
-
dir = File.dirname(
|
119
|
+
dir = File.dirname(config_path)
|
116
120
|
|
117
121
|
FileUtils.mkdir_p(dir) unless File.directory?(dir)
|
118
122
|
|
119
|
-
File.new(
|
123
|
+
File.new(config_path, 'w')
|
120
124
|
end
|
121
125
|
end
|
122
126
|
end
|
@@ -5,6 +5,7 @@ require 'uffizzi/clients/api/api_client'
|
|
5
5
|
class PreviewService
|
6
6
|
class << self
|
7
7
|
include ApiClient
|
8
|
+
|
8
9
|
def read_deployment_id(deployment_name)
|
9
10
|
return nil unless deployment_name.start_with?('deployment-')
|
10
11
|
return nil unless deployment_name.split('-').size == 2
|
@@ -15,23 +16,23 @@ class PreviewService
|
|
15
16
|
deployment_id
|
16
17
|
end
|
17
18
|
|
18
|
-
def
|
19
|
+
def run_containers_deploy(project_slug, deployment)
|
19
20
|
deployment_id = deployment[:id]
|
20
21
|
params = { id: deployment_id }
|
21
22
|
|
22
23
|
response = deploy_containers(Uffizzi::ConfigFile.read_option(:server), project_slug, deployment_id, params)
|
23
24
|
|
24
|
-
if Uffizzi::ResponseHelper.no_content?(response)
|
25
|
-
Uffizzi.ui.say(success_message)
|
26
|
-
create_deployment(deployment, project_slug)
|
27
|
-
else
|
25
|
+
if !Uffizzi::ResponseHelper.no_content?(response)
|
28
26
|
Uffizzi::ResponseHelper.handle_failed_response(response)
|
29
27
|
end
|
28
|
+
|
29
|
+
activity_items = wait_containers_creation(deployment, project_slug)
|
30
|
+
wait_containers_deploy(deployment, project_slug, activity_items)
|
30
31
|
end
|
31
32
|
|
32
33
|
private
|
33
34
|
|
34
|
-
def
|
35
|
+
def wait_containers_creation(deployment, project_slug)
|
35
36
|
spinner = TTY::Spinner.new('[:spinner] Creating containers...', format: :dots)
|
36
37
|
spinner.auto_spin
|
37
38
|
|
@@ -49,10 +50,10 @@ class PreviewService
|
|
49
50
|
|
50
51
|
Uffizzi.ui.say('Done')
|
51
52
|
|
52
|
-
|
53
|
+
activity_items
|
53
54
|
end
|
54
55
|
|
55
|
-
def
|
56
|
+
def wait_containers_deploy(deployment, project_slug, activity_items)
|
56
57
|
spinner = TTY::Spinner::Multi.new('[:spinner] Deploying preview...', format: :dots, style: {
|
57
58
|
middle: ' ',
|
58
59
|
bottom: ' ',
|
@@ -64,20 +65,13 @@ class PreviewService
|
|
64
65
|
response = get_activity_items(Uffizzi::ConfigFile.read_option(:server), project_slug, deployment[:id])
|
65
66
|
handle_activity_items_response(response, spinner)
|
66
67
|
activity_items = response[:body][:activity_items]
|
67
|
-
|
68
|
+
update_containers_spinners!(activity_items, containers_spinners)
|
68
69
|
break if activity_items.all? { |activity_item| activity_item[:state] == 'deployed' || activity_item[:state] == 'failed' }
|
69
70
|
|
70
71
|
sleep(5)
|
71
72
|
end
|
72
73
|
|
73
|
-
|
74
|
-
Uffizzi.ui.say('Done')
|
75
|
-
preview_url = "https://#{deployment[:preview_url]}"
|
76
|
-
Uffizzi.ui.say(preview_url) if spinner.success?
|
77
|
-
else
|
78
|
-
output_data = build_output_data(deployment)
|
79
|
-
Uffizzi.ui.output(output_data)
|
80
|
-
end
|
74
|
+
spinner.success?
|
81
75
|
end
|
82
76
|
|
83
77
|
def create_containers_spinners(activity_items, spinner)
|
@@ -91,10 +85,11 @@ class PreviewService
|
|
91
85
|
end
|
92
86
|
end
|
93
87
|
|
94
|
-
def
|
88
|
+
def update_containers_spinners!(activity_items, containers_spinners)
|
95
89
|
finished_activity_items = activity_items.filter do |activity_item|
|
96
90
|
activity_item[:state] == 'deployed' || activity_item[:state] == 'failed'
|
97
91
|
end
|
92
|
+
|
98
93
|
finished_activity_items.each do |activity_item|
|
99
94
|
container_spinner = containers_spinners.detect { |spinner| spinner[:name] == activity_item[:name] }
|
100
95
|
spinner = container_spinner[:spinner]
|
@@ -113,12 +108,5 @@ class PreviewService
|
|
113
108
|
Uffizzi::ResponseHelper.handle_failed_response(response)
|
114
109
|
end
|
115
110
|
end
|
116
|
-
|
117
|
-
def build_output_data(output_data)
|
118
|
-
{
|
119
|
-
id: "deployment-#{output_data[:id]}",
|
120
|
-
url: "https://#{output_data[:preview_url]}",
|
121
|
-
}
|
122
|
-
end
|
123
111
|
end
|
124
112
|
end
|
data/lib/uffizzi/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: uffizzi-cli
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Josh Thurman
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date: 2022-05-
|
12
|
+
date: 2022-05-26 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: awesome_print
|