Module: Trinidad::Sandbox::Helpers::Deploy

Defined in:
lib/trinidad_sandbox_extension/app/helpers/deploy.rb

Instance Method Summary collapse

Instance Method Details

#deploy_from_form(params) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/trinidad_sandbox_extension/app/helpers/deploy.rb', line 10

def deploy_from_form(params)
  repo_url = params["repo"]
  if repo_url.empty?
    repo_not_found
  else
    branch = params["branch"]
    branch = 'master' if branch.empty?

    ssh = normalize_uri repo_url
    path = params["path"]
    path = path_from_repo(ssh) if path.empty? && !enable_default?

    unless valid_path? path
      invalid_app_path(path)
    else
      status = find_and_deploy(ssh, branch, path)
      redirect_to_home status
    end
  end
end

#deploy_from_web_hook(params) ⇒ Object



31
32
33
34
35
36
37
38
39
40
# File 'lib/trinidad_sandbox_extension/app/helpers/deploy.rb', line 31

def deploy_from_web_hook(params)
  payload = JSON.parse(params['payload'])
  url = payload['repository']['url']
  branch = File.basename payload['ref']

  ssh = normalize_uri url
  path = path_from_repo(ssh)

  status = find_and_deploy(ssh, branch, path)
end

#deploy_new_application(path, repo, branch, dest) ⇒ Object



55
56
57
58
59
# File 'lib/trinidad_sandbox_extension/app/helpers/deploy.rb', line 55

def deploy_new_application(path, repo, branch, dest)
  clone(repo, branch, dest)
  bundle(dest)
  ApplicationContext.create(path, dest)
end

#find_and_deploy(repo, branch, path) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/trinidad_sandbox_extension/app/helpers/deploy.rb', line 42

def find_and_deploy(repo, branch, path)
  dest = File.join(host.app_base, path)

  deployed_app = ApplicationContext.find_by_doc_base(dest)
  status = if deployed_app
    redeploy_application(deployed_app, repo, branch, dest)
    204
  else
    deploy_new_application(path, repo, branch, dest)
    201
  end
end

#redeploy_application(context, repo, branch, dest) ⇒ Object



61
62
63
64
65
66
67
68
# File 'lib/trinidad_sandbox_extension/app/helpers/deploy.rb', line 61

def redeploy_application(context, repo, branch, dest)
  context.send(:setPaused, true)
  FileUtils.rm_rf File.expand_path(dest)

  clone(repo, branch, dest)

  context.reload
end