Skip to content

Commit

Permalink
Destroy old droplets.
Browse files Browse the repository at this point in the history
  • Loading branch information
ryotarai committed Aug 22, 2014
1 parent 6c42437 commit 81beac0
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
22 changes: 22 additions & 0 deletions ci/destroy_old_droplets.rb
@@ -0,0 +1,22 @@
require 'net/https'
require 'json'
require 'time'

http = Net::HTTP.new("api.digitalocean.com", 443)
http.use_ssl = true

res = http.start do
http.get("/v2/droplets", "Authorization" => "Bearer #{ENV['DIGITALOCEAN_TOKEN']}")
end

droplets = JSON.parse(res.body)['droplets']
droplets.each do |droplet|
next unless /^itamae-/ =~ droplet['name']
if Time.now - Time.parse(droplet['created_at']) >= 60 * 60
puts "destroying #{droplet}..."
res = http.start do
http.delete("/v2/droplets/#{droplet['id']}", "Authorization" => "Bearer #{ENV['DIGITALOCEAN_TOKEN']}")
end
end
end

5 changes: 5 additions & 0 deletions wercker.yml
Expand Up @@ -74,3 +74,8 @@ build:
name: shutdown vm
code: vagrant destroy -f
cwd: spec/integration

- script:
name: shutdown old vms
code: ruby ci/destroy_old_droplets.rb

0 comments on commit 81beac0

Please sign in to comment.