-
-
Save kareemk/f1af79de76542a5e9040 to your computer and use it in GitHub Desktop.
Docker Exec over SSH for Tutum
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/ruby | |
require 'net/http' | |
require 'json' | |
raise "Invalid arguments: dssh [container-name] [command=/bin/bash]" if ARGV.length < 1 | |
service_name = "#{ARGV[0]}" | |
ARGV[1] ||= "/bin/bash" | |
command = ARGV[1..-1].join(' ') | |
uri = URI.parse("https://dashboard.tutum.co") | |
http = Net::HTTP.new(uri.host, uri.port) | |
http.use_ssl = true | |
headers = { "Authorization" => "ApiKey koko:#{ENV['TUTUM_API_KEY']}" } | |
# Get list of containers that match | |
container = "#{service_name}-1" | |
response = http.get("/api/v1/container/?name=#{container}", headers) | |
if response.code == "200" | |
container_info = JSON.load(response.body)["objects"].first | |
dns = container_info["public_dns"] | |
image_name = container_info["image_name"] | |
exec "ssh -t root@#{dns} docker exec -i -t '$(docker ps | grep \"#{image_name}\" | cut -d\" \" -f1 | head -1) #{command}'" | |
else | |
puts "Error accessing tutum: #{response.body}" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment