class Freighter::DockerRestAPI
Constants
- ResponseObject
Public Class Methods
new(url)
click to toggle source
# File lib/freighter/docker_rest_api.rb, line 7 def initialize(url) @base_url = url @http = Excon.new url end
Public Instance Methods
authenticate()
click to toggle source
authentication should not be necessary if the user is already authenticated with the docker client on the host
# File lib/freighter/docker_rest_api.rb, line 13 def authenticate request { post(path: '/auth', body: JSON.dump({ 'username' => ENV['DOCKER_HUB_USER_NAME'], 'password' => ENV['DOCKER_HUB_PASSWORD'], 'email' => ENV['DOCKER_HUB_EMAIL'] }), headers: { "Content-Type" => "application/json" }) } end
list_images()
click to toggle source
# File lib/freighter/docker_rest_api.rb, line 32 def list_images request { get path: '/images/json' } end
pull(tag)
click to toggle source
This pulls a specified image def pull(image, repo, tag='latest')
# File lib/freighter/docker_rest_api.rb, line 19 def pull(tag) request do post(path: "/images/create", query: { tag: tag }) end end
running_containers()
click to toggle source
returns all running containers
# File lib/freighter/docker_rest_api.rb, line 26 def running_containers request do get(path: '/containers/json') end end
Protected Instance Methods
request() { || ... }
click to toggle source
# File lib/freighter/docker_rest_api.rb, line 40 def request(&block) begin binding.pry response = yield rescue Excon::Errors::SocketError => e logger.error e.message end status = response.status if status >= 200 and status < 300 begin ResponseObject.new JSON.parse(response.body), status rescue JSON::ParserError => e binding.pry end else LOGGER.error "Could not process request:\n request: #{@last_request_args.inspect}\n response: #{response.inspect}" end end