Class: Jatai::Commands::Up

Inherits:
Base
  • Object
show all
Defined in:
lib/jatai/commands/up.rb

Constant Summary collapse

POLL_INTERVAL =
5
PROVISION_TIMEOUT =
180
DEPLOY_TIMEOUT =
900
PROVISION_MAX_POLLS =
36
DEPLOY_MAX_POLLS =
180

Instance Method Summary collapse

Methods inherited from Base

#api, #app_slug, #error, #info, #pastel, #project_config, #require_auth!, #success

Instance Method Details

#execute(options = {}) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/jatai/commands/up.rb', line 14

def execute(options = {})
  require_auth!
  config = project_config

  @app = find_or_create_app(config)
  slug = @app["slug"]

  if %w[active sleeping].include?(@app["status"])
    info("Iniciando deploy...")
  else
    info("Provisionando infraestrutura...")
    trigger_provision(slug) if %w[pending error].include?(@app["status"])
    unless wait_for_provisioning(@app["id"], slug)
      return
    end
    success("Infraestrutura provisionada!")
    info("Iniciando primeiro deploy...")
  end

  deploy = trigger_deploy(slug)
  info("       Na fila...")

  if wait_for_deploy_complete(slug, deploy["id"])
    # URL canônica vem do servidor (marca nova). Fallback só p/ servidor antigo.
    url = @app["url"] || "https://#{@app["subdomain"] || slug}.jataiapp.com.br"
    success("Deploy concluído! App disponível em #{url}")
  end
rescue Api::Client::ValidationError => e
  error("Erro ao criar app: #{e.message}")
rescue Api::Client::ApiError => e
  error("Erro: #{e.message}")
end