brasa 0.5.2 → 0.7.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b01ebcbc4eb417f8b1dac15e9e4b3ecdeb95ae7a7a470097023c1392db688cef
4
- data.tar.gz: 0bc8d7b38a3f71469c7d396b260a54f646c0003cb19efa8d39c4afbf80a369f0
3
+ metadata.gz: c43a2e611cb76f921a9c2066be2fe84a4da611eb81aff758d47bb481a09f3710
4
+ data.tar.gz: 78108a8be50018a5ff96ad2c4026e20b2942d74234d335e0aad065360976ef00
5
5
  SHA512:
6
- metadata.gz: 4fba676de313e7587c4138475991a88e9b470aca71f938ee70e2fb3cc7271b81f7fa5929e78ab13512d93ad1c2f236a9ff64bcca91ff71401715a81bebc975ba
7
- data.tar.gz: dc5b3b1d3eb17cc4e69d2d614b2817c334a9c17af8ae44eb3d18aaddf4961a2b07f9df6724e714802c39ea731d5e8b41d390491e5954528abe3bf39124371397
6
+ metadata.gz: 7cf9cf1b338037c816efadd34cc79a395b0d24a6edb045d9d3cce197a678274b8ddafcc7a925c35480fd2b37ed579fba5014c8da5525bad67bfadc0ddeeda4d3
7
+ data.tar.gz: 8766f38b9203e02dd9f92f8fa0c21fd4c94c4ace3362c1b9c28925cfcd36833873665ffb4d80e0621f42b1f24cf546eef787e12b2b24be2b9aa402c3b6cad78e
data/lib/brasa/cli.rb CHANGED
@@ -79,8 +79,8 @@ module Brasa
79
79
  subcommand "redis", Commands::Redis
80
80
 
81
81
  desc "scale", "Escalar a aplicação"
82
- option :web, type: :numeric, desc: "Número de instâncias web"
83
- option :preset, type: :string, desc: "Preset (hobby, production, scale)"
82
+ option :replicas, type: :numeric, desc: "Número de réplicas"
83
+ option :preset, type: :string, desc: "Preset (micro, hobby, pro)"
84
84
  def scale
85
85
  Commands::Scale.new.execute(options)
86
86
  end
@@ -14,13 +14,11 @@ module Brasa
14
14
  db = helper.api.get("/api/v1/apps/#{slug}/database")
15
15
 
16
16
  puts helper.pastel.bold("Banco de dados de #{slug}")
17
- puts " Engine: #{db["engine"]} #{db["engine_version"]}"
18
- puts " Modo: #{db["mode"]}"
17
+ puts " Tier: #{db["database_tier"] || db["mode"]}"
19
18
  puts " Host: #{db["host"]}"
20
19
  puts " Porta: #{db["port"]}"
21
20
  puts " Nome: #{db["name"]}"
22
21
  puts " Status: #{db["status"]}"
23
- puts " Machine: #{db["machine_type"]}" if db["machine_type"] && db["machine_type"] != "embedded"
24
22
  rescue Api::Client::ApiError => e
25
23
  helper.error("Erro: #{e.message}")
26
24
  end
@@ -39,7 +39,7 @@ module Brasa
39
39
  ws = connect_websocket
40
40
  started = Time.now
41
41
 
42
- ws.on_log { |msg| print msg["line"] + "\n" if msg["line"] }
42
+ ws.on_log { |msg| print msg["line"] + "\n" if msg.is_a?(Hash) && msg["line"] }
43
43
  ws.subscribe("DeployLogChannel", deploy_id: deploy_id)
44
44
 
45
45
  status = ws.wait_for("DeployStatusChannel",
@@ -6,16 +6,18 @@ module Brasa
6
6
  module Commands
7
7
  class Init < Base
8
8
  PRESETS = {
9
- "nano" => "Nano1 vCPU, 1GB RAM, DB embedded (R$ 19/mês)",
10
- "micro" => "Micro1 vCPU, 1GB RAM, DB embedded (R$ 29/mês)",
11
- "hobby" => "Hobby1 vCPU, 1GB RAM, DB managed (R$ 99/mês)",
12
- "production" => "Production — 4 vCPU, 4GB RAM, DB managed + storage (R$ 299/mês)",
13
- "scale" => "Scale — 8 vCPU, 8GB RAM, DB managed + storage (R$ 599/mês)"
9
+ "micro" => "Micro256MB RAM, 1 réplica (Grátis)",
10
+ "hobby" => "Hobby — 1GB RAM, réplicas ilimitadas (R$ 19/mês)",
11
+ "pro" => "Pro2GB RAM, réplicas ilimitadas (R$ 69/mês)"
14
12
  }.freeze
15
13
 
16
14
  REGIONS = { "br-se1" => "São Paulo", "br-ne1" => "Nordeste" }.freeze
17
15
  STACKS = { "rails" => "Rails", "node" => "Node.js", "docker" => "Docker (custom Dockerfile)" }.freeze
18
- DATABASE_ENGINES = { "postgresql" => "PostgreSQL", "mysql" => "MySQL" }.freeze
16
+ DATABASE_TIERS = {
17
+ "mini" => "Mini — 512MB, 20 conexões (Grátis)",
18
+ "essencial" => "Essencial — 1GB, 50 conexões (R$ 19/mês)",
19
+ "padrao" => "Padrão — 5GB, 100 conexões (R$ 49/mês)"
20
+ }.freeze
19
21
 
20
22
  def execute(options = {})
21
23
  prompt = TTY::Prompt.new
@@ -39,7 +41,7 @@ module Brasa
39
41
  name = prompt.ask("Nome do app:") { |q| q.required true }
40
42
  preset = prompt.select("Preset:", PRESETS.map { |k, v| { name: v, value: k } })
41
43
  region = prompt.select("Região:", REGIONS.map { |k, v| { name: "#{v} (#{k})", value: k } })
42
- engine = prompt.select("Banco de dados:", DATABASE_ENGINES.map { |k, v| { name: v, value: k } })
44
+ db_tier = prompt.select("Banco de dados:", DATABASE_TIERS.map { |k, v| { name: v, value: k } })
43
45
  branch = detect_git_branch || "main"
44
46
 
45
47
  config = {
@@ -48,7 +50,7 @@ module Brasa
48
50
  "preset" => preset,
49
51
  "region" => region,
50
52
  "branch" => branch,
51
- "database_engine" => engine
53
+ "database_tier" => db_tier
52
54
  }
53
55
 
54
56
  File.write(config_path, YAML.dump(config))
@@ -24,11 +24,11 @@ module Brasa
24
24
  message = entry["message"]
25
25
 
26
26
  level_str = case level
27
- when "error" then pastel.red(level)
28
- when "warn" then pastel.yellow(level)
29
- when "info" then pastel.green(level)
30
- else pastel.dim(level || "log")
31
- end
27
+ when "error" then pastel.red(level)
28
+ when "warn" then pastel.yellow(level)
29
+ when "info" then pastel.green(level)
30
+ else pastel.dim(level || "log")
31
+ end
32
32
 
33
33
  puts "#{pastel.dim(timestamp)} #{pastel.cyan(source)} [#{level_str}] #{message}"
34
34
  end
@@ -23,7 +23,7 @@ module Brasa
23
23
  when String
24
24
  puts result
25
25
  else
26
- puts result.to_s
26
+ puts result
27
27
  end
28
28
  rescue Api::Client::ApiError => e
29
29
  error("Erro: #{e.message}")
@@ -9,15 +9,18 @@ module Brasa
9
9
  slug = app_slug
10
10
 
11
11
  body = {}
12
- body[:web] = options["web"].to_i if options["web"]
12
+ body[:replicas] = options["replicas"].to_i if options["replicas"]
13
13
  body[:preset] = options["preset"] if options["preset"]
14
14
 
15
15
  if body.empty?
16
- error("Informe ao menos --web ou --preset. Ex: brasa scale --web 3")
16
+ error("Informe ao menos --replicas ou --preset. Ex: brasa scale --replicas 3")
17
17
  return
18
18
  end
19
19
 
20
20
  estimate = api.post("/api/v1/apps/#{slug}/scale/estimate", body: body)
21
+ info("Preset: #{estimate["preset"]}")
22
+ info("Réplicas: #{estimate["replicas"]}") if estimate["replicas"]
23
+ info("CPU: #{estimate["cpu_limit"]} | RAM: #{estimate["memory_limit"]}") if estimate["cpu_limit"]
21
24
  info("Custo estimado: R$ #{estimate["monthly_cost"]}/mês")
22
25
 
23
26
  prompt = TTY::Prompt.new
@@ -15,8 +15,9 @@ module Brasa
15
15
  puts " Status: #{colorize_status(app["status"])}"
16
16
  puts " Região: #{app["region"]}"
17
17
  puts " Preset: #{app["preset"]}"
18
- puts " DB: #{app["database_engine"]}"
19
- puts " URL: https://#{app["subdomain"]}.usebrasa.com.br"
18
+ puts " DB: #{app["database_tier"]}"
19
+ subdomain = app["subdomain"] || app["slug"]
20
+ puts " URL: https://#{subdomain}.usebrasa.com.br"
20
21
 
21
22
  if app["last_deploy"]
22
23
  deploy = app["last_deploy"]
@@ -37,6 +38,8 @@ module Brasa
37
38
  case status
38
39
  when "active", "live"
39
40
  pastel.green(status)
41
+ when "sleeping"
42
+ pastel.blue(status)
40
43
  when "failed", "error"
41
44
  pastel.red(status)
42
45
  when "building", "deploying", "provisioning"
@@ -18,7 +18,7 @@ module Brasa
18
18
  @app = find_or_create_app(config)
19
19
  slug = @app["slug"]
20
20
 
21
- if @app["status"] == "active"
21
+ if %w[active sleeping].include?(@app["status"])
22
22
  info("Iniciando deploy...")
23
23
  else
24
24
  info("Provisionando infraestrutura...")
@@ -72,7 +72,7 @@ module Brasa
72
72
  name: config[:app], stack: config[:stack], preset: config[:preset],
73
73
  region: config[:region], repo_url: detect_git_remote, repo_branch: config[:branch]
74
74
  }
75
- app_params[:database_engine] = config[:database_engine] if config[:database_engine]
75
+ app_params[:database_tier] = config[:database_tier] if config[:database_tier]
76
76
  api.post("/api/v1/apps", body: { app: app_params })
77
77
  end
78
78
 
@@ -122,7 +122,7 @@ module Brasa
122
122
  ws = connect_websocket
123
123
  started = Time.now
124
124
 
125
- ws.on_log { |msg| print msg["line"] + "\n" if msg["line"] }
125
+ ws.on_log { |msg| print msg["line"] + "\n" if msg.is_a?(Hash) && msg["line"] }
126
126
  ws.subscribe("DeployLogChannel", deploy_id: deploy_id)
127
127
 
128
128
  status = ws.wait_for("DeployStatusChannel",
@@ -160,7 +160,10 @@ module Brasa
160
160
  PROVISION_MAX_POLLS.times do |i|
161
161
  app = api.get("/api/v1/apps/#{slug}")
162
162
  return true if app["status"] == "active"
163
- return (error("\nErro no provisionamento."); false) if app["status"] == "error"
163
+ if app["status"] == "error"
164
+ error("\nErro no provisionamento.")
165
+ return false
166
+ end
164
167
  if app["status"] != last_status
165
168
  print "\n #{status_label(app["status"])}"
166
169
  last_status = app["status"]
@@ -182,7 +185,10 @@ module Brasa
182
185
  DEPLOY_MAX_POLLS.times do |i|
183
186
  deploy = api.get("/api/v1/apps/#{slug}/deploys/#{deploy_id}")
184
187
  return true if deploy["status"] == "live"
185
- return (error("\nDeploy falhou."); false) if deploy["status"] == "failed"
188
+ if deploy["status"] == "failed"
189
+ error("\nDeploy falhou.")
190
+ return false
191
+ end
186
192
  if deploy["status"] != last_status
187
193
  print "\n #{status_label(deploy["status"])}"
188
194
  last_status = deploy["status"]
@@ -199,9 +205,9 @@ module Brasa
199
205
  end
200
206
 
201
207
  def status_label(status)
202
- { "pending" => "Aguardando...", "provisioning" => "Provisionando VM...",
208
+ { "pending" => "Aguardando...", "provisioning" => "Provisionando...",
203
209
  "queued" => "Na fila...", "building" => "Construindo imagem...",
204
- "deploying" => "Deployando..." }[status] || status
210
+ "deploying" => "Implantando..." }[status] || status
205
211
  end
206
212
 
207
213
  def show_elapsed(started)
data/lib/brasa/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Brasa
2
- VERSION = "0.5.2"
2
+ VERSION = "0.7.0"
3
3
  end
@@ -6,7 +6,7 @@ module Brasa
6
6
  class CableClient
7
7
  class ConnectionError < StandardError; end
8
8
 
9
- RECONNECT_DELAYS = [1, 3, 10].freeze
9
+ RECONNECT_DELAYS = [ 1, 3, 10 ].freeze
10
10
 
11
11
  def initialize(api_url: nil, token: nil)
12
12
  @api_url = api_url || Brasa::Config.api_url
@@ -80,7 +80,7 @@ module Brasa
80
80
  data = JSON.parse(msg.data)
81
81
  client.send(:handle_message, data)
82
82
  rescue JSON::ParserError
83
- $stderr.puts "[WS] Mensagem malformada ignorada: #{msg.data.to_s.truncate(100)}" if ENV["BRASA_DEBUG"]
83
+ $stderr.puts "[WS] Mensagem malformada ignorada: #{msg.data.to_s[0..100]}" if ENV["BRASA_DEBUG"]
84
84
  end
85
85
  end
86
86
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: brasa
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.2
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brasa