Skip to content

Instantly share code, notes, and snippets.

@coderberry
Created September 23, 2015 18:53
Show Gist options
  • Save coderberry/62aebb2c7ebac365668c to your computer and use it in GitHub Desktop.
Save coderberry/62aebb2c7ebac365668c to your computer and use it in GitHub Desktop.
Check deployment status of a Cloud66 stack
#!/usr/bin/env ruby
require 'typhoeus'
require 'json'
STATUSES = {
0 => 'Pending',
1 => 'Deployed',
2 => 'Deployment failed',
3 => 'Analyzing',
4 => 'Analyzed',
5 => 'Queued for deployment',
6 => 'Deploying',
7 => 'Unable to analyze'
}
NAME = 'MY_STACK_NAME'
TOKEN = File.read("/path/to/.cloud66/token")
current_status = 0
while current_status != 1
request = Typhoeus::Request.new(
"https://app.cloud66.com/api/3/stacks.json",
method: :get,
headers: { Authorization: "Bearer #{TOKEN}" }
)
request.run
response = request.response
begin
resp = JSON.parse(response.body)
resp['response'].each do |data|
if data['name'] == NAME
if current_status == data['status']
print "."
else
print STATUSES[data['status']]
end
current_status = data['status']
end
end
rescue
print "E"
end
sleep 5 unless current_status == 1
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment