captive-cli 1.0.0 → 1.2.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/lib/captive/cli/dependencies.rb +12 -2
- data/lib/captive/cli.rb +10 -5
- data/lib/captive/commands/apps_commands.rb +25 -50
- data/lib/captive/commands/apps_restart.rb +23 -9
- data/lib/captive/commands/cron_declaration.rb +25 -0
- data/lib/captive/commands/crons_commands.rb +123 -0
- data/lib/captive/commands/env_commands.rb +66 -0
- data/lib/captive/commands/env_set.rb +40 -0
- data/lib/captive/dashboard/apps_resource.rb +26 -0
- data/lib/captive/dashboard/env_vars_resource.rb +27 -0
- data/lib/captive/dashboard/scheduled_tasks_resource.rb +32 -0
- data/lib/captive/dashboard_api.rb +56 -0
- data/lib/captive/dashboard_response.rb +39 -0
- data/lib/captive/errors.rb +9 -3
- data/lib/captive/flux.rb +11 -2
- data/lib/captive/kubectl.rb +0 -10
- data/lib/captive/loader.rb +6 -4
- data/lib/captive/presenter/app_info.rb +40 -0
- data/lib/captive/presenter/scheduled_task.rb +36 -0
- data/lib/captive/shell_completions.rb +4 -2
- data/lib/captive/token_file.rb +20 -0
- data/lib/captive/validation_message.rb +26 -0
- data/lib/captive/version.rb +1 -1
- metadata +14 -8
- data/lib/captive/cluster_apps.rb +0 -82
- data/lib/captive/commands/apps_info.rb +0 -70
- data/lib/captive/commands/apps_rebuild.rb +0 -52
- data/lib/captive/commands/env_kube_commands.rb +0 -25
- data/lib/captive/commands/env_list_kube.rb +0 -16
- data/lib/captive/gh_cli.rb +0 -89
- data/lib/captive/platform_root.rb +0 -25
data/lib/captive/gh_cli.rb
DELETED
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require "json"
|
|
4
|
-
require "open3"
|
|
5
|
-
require_relative "errors"
|
|
6
|
-
|
|
7
|
-
module Captive
|
|
8
|
-
class GhCLI
|
|
9
|
-
def trigger_workflow(repo, workflow: "ci.yml", ref: "main", fields: {})
|
|
10
|
-
field_args = fields.flat_map { |k, v| [ "--field", "#{k}=#{v}" ] }
|
|
11
|
-
run("workflow", "run", workflow, "--repo", repo, "--ref", ref, *field_args)
|
|
12
|
-
rescue RuntimeError => e
|
|
13
|
-
raise WorkflowDispatchNotConfigured,
|
|
14
|
-
"Le workflow '#{workflow}' de '#{repo}' n'a pas de trigger workflow_dispatch.\n" \
|
|
15
|
-
" Regénère le ci.yml : captive apps launch <app> dans le repo de l'app." \
|
|
16
|
-
if e.message.include?("workflow_dispatch")
|
|
17
|
-
raise
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
def workflow_exists?(repo)
|
|
21
|
-
%w[deploy.yml ci.yml].any? do |file|
|
|
22
|
-
run("api", "/repos/#{repo}/contents/.github/workflows/#{file}") && true
|
|
23
|
-
rescue RuntimeError
|
|
24
|
-
false
|
|
25
|
-
end
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
def latest_run_status(repo)
|
|
29
|
-
output = run("run", "list", "--repo", repo, "--limit", "1",
|
|
30
|
-
"--json", "status,conclusion", "--jq", ".[0]")
|
|
31
|
-
data = JSON.parse(output)
|
|
32
|
-
return :success if data["status"] == "completed" && data["conclusion"] == "success"
|
|
33
|
-
return :failure if data["status"] == "completed"
|
|
34
|
-
|
|
35
|
-
:in_progress
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
def image_exists?(repo, tag)
|
|
39
|
-
output = run("api", "/repos/#{repo}/packages/container/#{repo.split("/").last}/versions",
|
|
40
|
-
"--jq", ".[].metadata.container.tags[]")
|
|
41
|
-
output.split("\n").include?(tag)
|
|
42
|
-
rescue RuntimeError => e
|
|
43
|
-
return false if e.message.include?("404") || e.message.include?("Not Found")
|
|
44
|
-
|
|
45
|
-
raise
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
def app_installed?(repo)
|
|
49
|
-
run("api", "repos/#{repo}/installation")
|
|
50
|
-
true
|
|
51
|
-
rescue RuntimeError
|
|
52
|
-
false
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
def detect_type(repo)
|
|
56
|
-
data = JSON.parse(run("api", "repos/#{repo}"))
|
|
57
|
-
case data["language"]
|
|
58
|
-
when "Ruby" then "rails-app"
|
|
59
|
-
when "JavaScript", "TypeScript" then "node-app"
|
|
60
|
-
else raise UnknownAppType, "language non supportée : #{data["language"]}"
|
|
61
|
-
end
|
|
62
|
-
end
|
|
63
|
-
|
|
64
|
-
PLATFORM_REPO = "captive-studio/captive-platform"
|
|
65
|
-
|
|
66
|
-
def dispatch_build(repo)
|
|
67
|
-
repo_name = repo.split("/").last.downcase
|
|
68
|
-
sha = run("api", "repos/#{repo}/git/ref/heads/main", "--jq", ".object.sha").strip
|
|
69
|
-
body = JSON.generate(
|
|
70
|
-
event_type: "build-app",
|
|
71
|
-
client_payload: { repo: repo, repo_name: repo_name, sha: sha, ref: "refs/heads/main" }
|
|
72
|
-
)
|
|
73
|
-
run_with_input("api", "repos/#{PLATFORM_REPO}/dispatches", "-X", "POST", "--input", "-",
|
|
74
|
-
input: body)
|
|
75
|
-
end
|
|
76
|
-
|
|
77
|
-
def run(*args, input: nil)
|
|
78
|
-
opts = input ? { stdin_data: input } : {}
|
|
79
|
-
out, err, status = Open3.capture3("gh", *args, **opts)
|
|
80
|
-
raise "gh #{args.join(" ")} failed: #{err}" unless status.success?
|
|
81
|
-
|
|
82
|
-
out
|
|
83
|
-
end
|
|
84
|
-
|
|
85
|
-
def run_with_input(*args, input:)
|
|
86
|
-
run(*args, input: input)
|
|
87
|
-
end
|
|
88
|
-
end
|
|
89
|
-
end
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require "pathname"
|
|
4
|
-
require_relative "errors"
|
|
5
|
-
|
|
6
|
-
module Captive
|
|
7
|
-
# Où est le clone de captive-platform. Installé en gem, le CLI ne vit plus dans le monorepo :
|
|
8
|
-
# la racine se trouve en remontant depuis le dossier courant, comme git trouve .git, ou se
|
|
9
|
-
# désigne par CAPTIVE_PLATFORM_ROOT. Seul `apps rebuild` en a encore besoin (ADR 0018).
|
|
10
|
-
module PlatformRoot
|
|
11
|
-
ENV_VAR = "CAPTIVE_PLATFORM_ROOT"
|
|
12
|
-
|
|
13
|
-
def self.find(start: Dir.pwd, env: ENV)
|
|
14
|
-
env[ENV_VAR] || ascend(start) ||
|
|
15
|
-
raise(PlatformRootNotFound, "Clone de captive-platform introuvable depuis #{start}. " \
|
|
16
|
-
"Lance la commande depuis le clone ou définis #{ENV_VAR}.")
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
def self.ascend(start)
|
|
20
|
-
Pathname.new(start).realpath.ascend
|
|
21
|
-
.find { |dir| dir.join("services").directory? && dir.join(".sops.yaml").file? }&.to_s
|
|
22
|
-
end
|
|
23
|
-
private_class_method :ascend
|
|
24
|
-
end
|
|
25
|
-
end
|