brasa 0.2.3 → 0.3.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/brasa/commands/up.rb +39 -11
- data/lib/brasa/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 7285bea2b7d7a7f1db549db5faa7e0a3c4f60c15baf185210b46c0f8e162c792
|
|
4
|
+
data.tar.gz: c826e60cc8895e4ab2bb0aa26db0600b86abcd9fe1ff0d77f49d3701d07111c2
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: dce0daf704b7880388fd0233fa0308152a871480aeace5fdd88cb31514049ae2ee83b96bbf936cb340db6a4a66a1a96ebbd7c55eba0a4708d116873201124d35
|
|
7
|
+
data.tar.gz: c3b1504e6fd93b18fcb813b3c4abd0f669674dff8f28dc74dcc49fad3357331351ad22db6642cedb89dd0ed0ff1a41eca55674ceb578e01286290ef247981f07
|
data/lib/brasa/commands/up.rb
CHANGED
|
@@ -10,21 +10,24 @@ module Brasa
|
|
|
10
10
|
require_auth!
|
|
11
11
|
config = project_config
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
app = create_app(config)
|
|
16
|
-
info("App #{app["slug"]} criado. Provisionando infraestrutura...")
|
|
13
|
+
app = find_or_create_app(config)
|
|
14
|
+
slug = app["slug"]
|
|
17
15
|
|
|
18
|
-
|
|
19
|
-
|
|
16
|
+
if app["status"] == "active"
|
|
17
|
+
info("Iniciando deploy...")
|
|
18
|
+
else
|
|
19
|
+
info("Provisionando infraestrutura...")
|
|
20
|
+
unless wait_for_provisioning(slug)
|
|
21
|
+
return
|
|
22
|
+
end
|
|
23
|
+
success("Infraestrutura provisionada!")
|
|
24
|
+
info("Iniciando primeiro deploy...")
|
|
20
25
|
end
|
|
21
|
-
success("Infraestrutura provisionada!")
|
|
22
26
|
|
|
23
|
-
|
|
24
|
-
deploy = trigger_deploy(app["slug"])
|
|
27
|
+
deploy = trigger_deploy(slug)
|
|
25
28
|
|
|
26
|
-
if wait_for_deploy(
|
|
27
|
-
success("Deploy concluído! App disponível em https://#{
|
|
29
|
+
if wait_for_deploy(slug, deploy["id"])
|
|
30
|
+
success("Deploy concluído! App disponível em https://#{slug}.usebrasa.com.br")
|
|
28
31
|
end
|
|
29
32
|
rescue Api::Client::ValidationError => e
|
|
30
33
|
error("Erro ao criar app: #{e.message}")
|
|
@@ -34,12 +37,32 @@ module Brasa
|
|
|
34
37
|
|
|
35
38
|
private
|
|
36
39
|
|
|
40
|
+
def find_or_create_app(config)
|
|
41
|
+
existing = api.get("/api/v1/apps/#{config[:app]}")
|
|
42
|
+
info("App #{existing["slug"]} encontrado (#{existing["status"]}).")
|
|
43
|
+
ensure_repo_url(existing["slug"])
|
|
44
|
+
existing
|
|
45
|
+
rescue Api::Client::NotFoundError
|
|
46
|
+
info("Criando app #{config[:app]}...")
|
|
47
|
+
create_app(config)
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def ensure_repo_url(slug)
|
|
51
|
+
repo = detect_git_remote
|
|
52
|
+
return unless repo
|
|
53
|
+
|
|
54
|
+
api.patch("/api/v1/apps/#{slug}", body: { app: { repo_url: repo } })
|
|
55
|
+
rescue Api::Client::ApiError
|
|
56
|
+
# Não bloquear o fluxo se falhar ao atualizar repo
|
|
57
|
+
end
|
|
58
|
+
|
|
37
59
|
def create_app(config)
|
|
38
60
|
api.post("/api/v1/apps", body: {
|
|
39
61
|
name: config[:app],
|
|
40
62
|
stack: config[:stack],
|
|
41
63
|
preset: config[:preset],
|
|
42
64
|
region: config[:region],
|
|
65
|
+
repo_url: detect_git_remote,
|
|
43
66
|
repo_branch: config[:branch]
|
|
44
67
|
})
|
|
45
68
|
end
|
|
@@ -48,6 +71,11 @@ module Brasa
|
|
|
48
71
|
api.post("/api/v1/apps/#{slug}/deploys")
|
|
49
72
|
end
|
|
50
73
|
|
|
74
|
+
def detect_git_remote
|
|
75
|
+
remote = `git remote get-url origin 2>/dev/null`.strip
|
|
76
|
+
remote.empty? ? nil : remote
|
|
77
|
+
end
|
|
78
|
+
|
|
51
79
|
def wait_for_provisioning(slug)
|
|
52
80
|
MAX_POLLS.times do
|
|
53
81
|
app = api.get("/api/v1/apps/#{slug}")
|
data/lib/brasa/version.rb
CHANGED