Class: Qtc::Cli::Mar::Slugs
- Inherits:
-
Base
- Object
- Base
- Qtc::Cli::Mar::Slugs
show all
- Defined in:
- lib/qtc/cli/mar/slugs.rb
Instance Attribute Summary
Attributes included from Common
#datacenter_id
Instance Method Summary
collapse
Methods included from Common
#client, #current_cloud_dc, #current_cloud_id, #current_cloud_token, #extract_app_in_dir, #ini_filename, #inifile, #instance_info, #platform_base_url, #platform_client
Instance Method Details
#create_slug(instance_id, options) ⇒ Object
58
59
60
61
62
63
64
65
|
# File 'lib/qtc/cli/mar/slugs.rb', line 58
def create_slug(instance_id, options)
process_types = resolve_proc_types(options)
data = {
tag: options.tag,
process_types: process_types
}
client.post("/apps/#{instance_id}/slugs", data, {}, {'Authorization' => "Bearer #{current_cloud_token}"})
end
|
#deploy(slug_id, options) ⇒ Object
53
54
55
56
|
# File 'lib/qtc/cli/mar/slugs.rb', line 53
def deploy(slug_id, options)
instance_id = resolve_instance_id(options)
client.post("/apps/#{instance_id}/slugs/#{slug_id}/deploy", {}, {}, {'Authorization' => "Bearer #{current_cloud_token}"})
end
|
#list(options) ⇒ Object
12
13
14
15
16
17
18
19
20
21
22
|
# File 'lib/qtc/cli/mar/slugs.rb', line 12
def list(options)
instance_id = resolve_instance_id(options)
slugs = client.get("/apps/#{instance_id}/slugs/", {}, {'Authorization' => "Bearer #{current_cloud_token}"})
if slugs && slugs['results'].size > 0
template = "%-20.20s %-30.30s %-30.30s"
puts template % ["TAG", "CREATED", "DEPLOYED"]
slugs['results'].each do |slug|
puts template % [slug['tag'], slug['createdAt'], slug['deployedAt']]
end
end
end
|
#remove(slug_id, options) ⇒ Object
24
25
26
27
|
# File 'lib/qtc/cli/mar/slugs.rb', line 24
def remove(slug_id, options)
instance_id = resolve_instance_id(options)
client.delete("/apps/#{instance_id}/slugs/#{slug_id}", {}, {}, {'Authorization' => "Bearer #{current_cloud_token}"})
end
|
#resolve_proc_types(options) ⇒ Object
67
68
69
70
71
72
73
74
75
76
|
# File 'lib/qtc/cli/mar/slugs.rb', line 67
def resolve_proc_types(options)
if options.procfile
procfile_hash = {}
procfile = YAML.load(File.read(options.procfile), :encoding => 'utf-8')
procfile_hash.merge!(procfile) if procfile
procfile_hash
else
raise StandardError 'Procfile must be given'
end
end
|
#upload(options) ⇒ Object
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
# File 'lib/qtc/cli/mar/slugs.rb', line 29
def upload(options)
instance_id = resolve_instance_id(options)
slug = create_slug(instance_id, options)
upload_uri = URI(slug['blob']['url'])
puts "Starting slug upload, if your slug is large this may take a while"
begin
open(File.new(options.slug), 'rb') do |io|
aws_client = Net::HTTP.new(upload_uri.host)
req = Net::HTTP::Put.new(upload_uri.request_uri)
req.content_length = io.size
req.body_stream = io
req['Content-Type'] = 'application/octet-stream'
aws_client.request(req)
end
rescue => exc
puts "Slug upload failed:#{exc.to_s}"
raise StandardError "Slug upload failed!"
end
puts "Slug uploaded successfully, you may now deploy it using commit tag: #{slug['tag']}"
end
|