cpl 0.3.3 → 0.4.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/Gemfile.lock +1 -1
- data/cpl.gemspec +1 -1
- data/lib/command/base.rb +2 -2
- data/lib/command/build_image.rb +11 -0
- data/lib/command/delete.rb +1 -1
- data/lib/command/deploy_image.rb +1 -1
- data/lib/command/env.rb +1 -1
- data/lib/command/exists.rb +1 -1
- data/lib/command/open.rb +1 -1
- data/lib/command/run.rb +1 -1
- data/lib/command/run_detached.rb +2 -2
- data/lib/command/setup.rb +2 -2
- data/lib/command/test.rb +2 -0
- data/lib/core/config.rb +10 -10
- data/lib/core/controlplane.rb +24 -19
- data/lib/cpl/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c162aaec9e6b476bb2ac9171d4cfbaf564a11f18821c1ee139c83120343ec127
|
4
|
+
data.tar.gz: 98a5f78b9fb4f17f4380e290d1ca01d2729570986b22b1fbf8171cedb5e9aca1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2f0cf811bd1e52e97039d66c24a282363798d1ae2e892d950360c6f99e1cfe84c0dd9da643c83b1a0de353d94fde1a6ded645ae167a804f2dc695f32439a84c4
|
7
|
+
data.tar.gz: 33d012cd711b38968d7eb8cff48cb313f3c7c0e71049a0c5c4af832ea9cd62c06a112b2975f40a9bbc78f36acb9eb2816a1f36be46b38112b4b1b45bf52ea180
|
data/Gemfile.lock
CHANGED
data/cpl.gemspec
CHANGED
@@ -9,7 +9,7 @@ Gem::Specification.new do |spec|
|
|
9
9
|
spec.email = ["justin@shakacode.com", "sergey@shakacode.com"]
|
10
10
|
|
11
11
|
spec.summary = "Heroku to Control Plane"
|
12
|
-
spec.description = "
|
12
|
+
spec.description = "CLI for providing Heroku-like platform-as-a-service on Control Plane"
|
13
13
|
spec.homepage = "https://github.com/shakacode/heroku-to-control-plane"
|
14
14
|
spec.license = "MIT"
|
15
15
|
|
data/lib/command/base.rb
CHANGED
@@ -137,7 +137,7 @@ module Command
|
|
137
137
|
end
|
138
138
|
|
139
139
|
def wait_for_workload(workload)
|
140
|
-
wait_for("workload to start") { cp.
|
140
|
+
wait_for("workload to start") { cp.fetch_workload(workload) }
|
141
141
|
end
|
142
142
|
|
143
143
|
def wait_for_replica(workload, location)
|
@@ -148,7 +148,7 @@ module Command
|
|
148
148
|
|
149
149
|
def ensure_workload_deleted(workload)
|
150
150
|
progress.puts "- Ensure workload is deleted"
|
151
|
-
cp.workload_delete(workload
|
151
|
+
cp.workload_delete(workload)
|
152
152
|
end
|
153
153
|
|
154
154
|
def latest_image_from(items, app_name: config.app, name_only: true)
|
data/lib/command/build_image.rb
CHANGED
@@ -15,11 +15,22 @@ module Command
|
|
15
15
|
HEREDOC
|
16
16
|
|
17
17
|
def call
|
18
|
+
ensure_docker_running!
|
19
|
+
|
18
20
|
dockerfile = config.current[:dockerfile] || "Dockerfile"
|
19
21
|
dockerfile = "#{config.app_cpln_dir}/#{dockerfile}"
|
20
22
|
progress.puts "- Building dockerfile: #{dockerfile}"
|
21
23
|
|
22
24
|
cp.image_build(latest_image_next, dockerfile: dockerfile)
|
23
25
|
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def ensure_docker_running!
|
30
|
+
`docker version > /dev/null 2>&1`
|
31
|
+
return if $?.success? # rubocop:disable Style/SpecialGlobalVars
|
32
|
+
|
33
|
+
Shell.abort("Can't run Docker. Please make sure that it's installed and started, then try again.")
|
34
|
+
end
|
24
35
|
end
|
25
36
|
end
|
data/lib/command/delete.rb
CHANGED
data/lib/command/deploy_image.rb
CHANGED
@@ -15,7 +15,7 @@ module Command
|
|
15
15
|
image = latest_image
|
16
16
|
|
17
17
|
config[:app_workloads].each do |workload|
|
18
|
-
cp.
|
18
|
+
cp.fetch_workload!(workload).dig("spec", "containers").each do |container|
|
19
19
|
next unless container["image"].match?(%r{^/org/#{config[:cpln_org]}/image/#{config.app}:})
|
20
20
|
|
21
21
|
cp.workload_set_image_ref(workload, container: container["name"], image: image)
|
data/lib/command/env.rb
CHANGED
@@ -12,7 +12,7 @@ module Command
|
|
12
12
|
HEREDOC
|
13
13
|
|
14
14
|
def call
|
15
|
-
cp.
|
15
|
+
cp.fetch_gvc!.dig("spec", "env").map do |prop|
|
16
16
|
# NOTE: atm no special chars handling, consider adding if needed
|
17
17
|
puts "#{prop['name']}=#{prop['value']}"
|
18
18
|
end
|
data/lib/command/exists.rb
CHANGED
data/lib/command/open.rb
CHANGED
@@ -23,7 +23,7 @@ module Command
|
|
23
23
|
|
24
24
|
def call
|
25
25
|
workload = config.options[:workload] || config[:one_off_workload]
|
26
|
-
data = cp.
|
26
|
+
data = cp.fetch_workload!(workload)
|
27
27
|
url = data["status"]["endpoint"]
|
28
28
|
opener = `which xdg-open open`.split("\n").grep_v("not found").first
|
29
29
|
|
data/lib/command/run.rb
CHANGED
@@ -59,7 +59,7 @@ module Command
|
|
59
59
|
progress.puts "- Cloning workload '#{workload}' on '#{config.options[:app]}' to '#{one_off}'"
|
60
60
|
|
61
61
|
# Create a base copy of workload props
|
62
|
-
spec = cp.
|
62
|
+
spec = cp.fetch_workload!(workload).fetch("spec")
|
63
63
|
container = spec["containers"].detect { _1["name"] == workload } || spec["containers"].first
|
64
64
|
|
65
65
|
# remove other containers if any
|
data/lib/command/run_detached.rb
CHANGED
@@ -57,7 +57,7 @@ module Command
|
|
57
57
|
progress.puts "- Cloning workload '#{workload}' on '#{config.options[:app]}' to '#{one_off}'"
|
58
58
|
|
59
59
|
# Get base specs of workload
|
60
|
-
spec = cp.
|
60
|
+
spec = cp.fetch_workload!(workload).fetch("spec")
|
61
61
|
container = spec["containers"].detect { _1["name"] == workload } || spec["containers"].first
|
62
62
|
|
63
63
|
# remove other containers if any
|
@@ -113,7 +113,7 @@ module Command
|
|
113
113
|
def show_logs_waiting # rubocop:disable Metrics/MethodLength
|
114
114
|
progress.puts "- Scheduled, fetching logs (it is cron job, so it may take up to a minute to start)"
|
115
115
|
begin
|
116
|
-
while cp.
|
116
|
+
while cp.fetch_workload(one_off)
|
117
117
|
sleep(WORKLOAD_SLEEP_CHECK)
|
118
118
|
print_uniq_logs
|
119
119
|
end
|
data/lib/command/setup.rb
CHANGED
@@ -37,7 +37,7 @@ module Command
|
|
37
37
|
def call
|
38
38
|
config.args.each do |template|
|
39
39
|
filename = "#{config.app_cpln_dir}/templates/#{template}.yml"
|
40
|
-
ensure_template(template, filename)
|
40
|
+
ensure_template!(template, filename)
|
41
41
|
apply_template(filename)
|
42
42
|
progress.puts(template)
|
43
43
|
end
|
@@ -45,7 +45,7 @@ module Command
|
|
45
45
|
|
46
46
|
private
|
47
47
|
|
48
|
-
def ensure_template(template, filename)
|
48
|
+
def ensure_template!(template, filename)
|
49
49
|
Shell.abort("Can't find template '#{template}' at '#{filename}', please create it.") unless File.exist?(filename)
|
50
50
|
end
|
51
51
|
|
data/lib/command/test.rb
CHANGED
data/lib/core/config.rb
CHANGED
@@ -19,7 +19,7 @@ class Config
|
|
19
19
|
end
|
20
20
|
|
21
21
|
def [](key)
|
22
|
-
ensure_current_config
|
22
|
+
ensure_current_config!
|
23
23
|
|
24
24
|
old_key = old_option_keys[key]
|
25
25
|
if current.key?(key)
|
@@ -41,37 +41,37 @@ class Config
|
|
41
41
|
|
42
42
|
private
|
43
43
|
|
44
|
-
def ensure_current_config
|
44
|
+
def ensure_current_config!
|
45
45
|
Shell.abort("Can't find current config, please specify an app.") unless current
|
46
46
|
end
|
47
47
|
|
48
|
-
def ensure_current_config_app(app)
|
48
|
+
def ensure_current_config_app!(app)
|
49
49
|
Shell.abort("Can't find app '#{app}' in 'controlplane.yml'.") unless current
|
50
50
|
end
|
51
51
|
|
52
|
-
def ensure_config
|
52
|
+
def ensure_config!
|
53
53
|
Shell.abort("'controlplane.yml' is empty.") unless config
|
54
54
|
end
|
55
55
|
|
56
|
-
def ensure_config_apps
|
56
|
+
def ensure_config_apps!
|
57
57
|
Shell.abort("Can't find key 'apps' in 'controlplane.yml'.") unless config[:apps]
|
58
58
|
end
|
59
59
|
|
60
|
-
def ensure_config_app(app, options)
|
60
|
+
def ensure_config_app!(app, options)
|
61
61
|
Shell.abort("App '#{app}' is empty in 'controlplane.yml'.") unless options
|
62
62
|
end
|
63
63
|
|
64
64
|
def pick_current_config
|
65
|
-
ensure_config
|
66
|
-
ensure_config_apps
|
65
|
+
ensure_config!
|
66
|
+
ensure_config_apps!
|
67
67
|
config[:apps].each do |c_app, c_data|
|
68
|
-
ensure_config_app(c_app, c_data)
|
68
|
+
ensure_config_app!(c_app, c_data)
|
69
69
|
if c_app.to_s == app || (c_data[:match_if_app_name_starts_with] && app.start_with?(c_app.to_s))
|
70
70
|
@current = c_data
|
71
71
|
break
|
72
72
|
end
|
73
73
|
end
|
74
|
-
ensure_current_config_app(app)
|
74
|
+
ensure_current_config_app!(app)
|
75
75
|
end
|
76
76
|
|
77
77
|
def load_app_config
|
data/lib/core/controlplane.rb
CHANGED
@@ -15,7 +15,7 @@ class Controlplane # rubocop:disable Metrics/ClassLength
|
|
15
15
|
def image_build(image, dockerfile:, push: true)
|
16
16
|
cmd = "cpln image build --org #{org} --name #{image} --dir #{config.app_dir} --dockerfile #{dockerfile}"
|
17
17
|
cmd += " --push" if push
|
18
|
-
perform(cmd)
|
18
|
+
perform!(cmd)
|
19
19
|
end
|
20
20
|
|
21
21
|
def image_query(app_name = config.app)
|
@@ -38,12 +38,12 @@ class Controlplane # rubocop:disable Metrics/ClassLength
|
|
38
38
|
perform_yaml(cmd)
|
39
39
|
end
|
40
40
|
|
41
|
-
def
|
41
|
+
def fetch_gvc(a_gvc = gvc)
|
42
42
|
api.gvc_get(gvc: a_gvc, org: org)
|
43
43
|
end
|
44
44
|
|
45
|
-
def
|
46
|
-
gvc_data =
|
45
|
+
def fetch_gvc!(a_gvc = gvc)
|
46
|
+
gvc_data = fetch_gvc(a_gvc)
|
47
47
|
return gvc_data if gvc_data
|
48
48
|
|
49
49
|
Shell.abort("Can't find GVC '#{gvc}', please create it with 'cpl setup gvc -a #{config.app}'.")
|
@@ -55,12 +55,12 @@ class Controlplane # rubocop:disable Metrics/ClassLength
|
|
55
55
|
|
56
56
|
# workload
|
57
57
|
|
58
|
-
def
|
58
|
+
def fetch_workload(workload)
|
59
59
|
api.workload_get(workload: workload, gvc: gvc, org: org)
|
60
60
|
end
|
61
61
|
|
62
|
-
def
|
63
|
-
workload_data =
|
62
|
+
def fetch_workload!(workload)
|
63
|
+
workload_data = fetch_workload(workload)
|
64
64
|
return workload_data if workload_data
|
65
65
|
|
66
66
|
Shell.abort("Can't find workload '#{workload}', please create it with 'cpl setup #{workload} -a #{config.app}'.")
|
@@ -74,45 +74,50 @@ class Controlplane # rubocop:disable Metrics/ClassLength
|
|
74
74
|
def workload_set_image_ref(workload, container:, image:)
|
75
75
|
cmd = "cpln workload update #{workload} #{gvc_org}"
|
76
76
|
cmd += " --set spec.containers.#{container}.image=/org/#{config[:cpln_org]}/image/#{image}"
|
77
|
-
perform(cmd)
|
77
|
+
perform!(cmd)
|
78
78
|
end
|
79
79
|
|
80
80
|
def workload_set_suspend(workload, value)
|
81
|
-
data =
|
81
|
+
data = fetch_workload!(workload)
|
82
82
|
data["spec"]["defaultOptions"]["suspend"] = value
|
83
83
|
apply(data)
|
84
84
|
end
|
85
85
|
|
86
86
|
def workload_force_redeployment(workload)
|
87
87
|
cmd = "cpln workload force-redeployment #{workload} #{gvc_org}"
|
88
|
+
perform!(cmd)
|
89
|
+
end
|
90
|
+
|
91
|
+
def workload_delete(workload)
|
92
|
+
cmd = "cpln workload delete #{workload} #{gvc_org}"
|
93
|
+
cmd += " 2> /dev/null"
|
88
94
|
perform(cmd)
|
89
95
|
end
|
90
96
|
|
91
|
-
def workload_delete(workload
|
97
|
+
def workload_delete!(workload)
|
92
98
|
cmd = "cpln workload delete #{workload} #{gvc_org}"
|
93
|
-
cmd
|
94
|
-
no_raise ? perform_no_raise(cmd) : perform(cmd)
|
99
|
+
perform!(cmd)
|
95
100
|
end
|
96
101
|
|
97
102
|
def workload_connect(workload, location:, container: nil, shell: nil)
|
98
103
|
cmd = "cpln workload connect #{workload} #{gvc_org} --location #{location}"
|
99
104
|
cmd += " --container #{container}" if container
|
100
105
|
cmd += " --shell #{shell}" if shell
|
101
|
-
perform(cmd)
|
106
|
+
perform!(cmd)
|
102
107
|
end
|
103
108
|
|
104
109
|
def workload_exec(workload, location:, container: nil, command: nil)
|
105
110
|
cmd = "cpln workload exec #{workload} #{gvc_org} --location #{location}"
|
106
111
|
cmd += " --container #{container}" if container
|
107
112
|
cmd += " -- #{command}"
|
108
|
-
perform(cmd)
|
113
|
+
perform!(cmd)
|
109
114
|
end
|
110
115
|
|
111
116
|
# logs
|
112
117
|
|
113
118
|
def logs(workload:)
|
114
119
|
cmd = "cpln logs '{workload=\"#{workload}\"}' --org #{org} -t -o raw --limit 200"
|
115
|
-
perform(cmd)
|
120
|
+
perform!(cmd)
|
116
121
|
end
|
117
122
|
|
118
123
|
def log_get(workload:, from:, to:)
|
@@ -126,18 +131,18 @@ class Controlplane # rubocop:disable Metrics/ClassLength
|
|
126
131
|
f.write(data.to_yaml)
|
127
132
|
f.rewind
|
128
133
|
cmd = "cpln apply #{gvc_org} --file #{f.path} > /dev/null"
|
129
|
-
perform(cmd)
|
134
|
+
perform!(cmd)
|
130
135
|
end
|
131
136
|
end
|
132
137
|
|
133
138
|
private
|
134
139
|
|
135
140
|
def perform(cmd)
|
136
|
-
system(cmd)
|
141
|
+
system(cmd)
|
137
142
|
end
|
138
143
|
|
139
|
-
def
|
140
|
-
system(cmd)
|
144
|
+
def perform!(cmd)
|
145
|
+
system(cmd) || exit(false)
|
141
146
|
end
|
142
147
|
|
143
148
|
def perform_yaml(cmd)
|
data/lib/cpl/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cpl
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Justin Gordon
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2023-03-
|
12
|
+
date: 2023-03-17 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: debug
|
@@ -137,7 +137,7 @@ dependencies:
|
|
137
137
|
- - "~>"
|
138
138
|
- !ruby/object:Gem::Version
|
139
139
|
version: 0.22.0
|
140
|
-
description:
|
140
|
+
description: CLI for providing Heroku-like platform-as-a-service on Control Plane
|
141
141
|
email:
|
142
142
|
- justin@shakacode.com
|
143
143
|
- sergey@shakacode.com
|