From 6dbaa1e07e8cd933e9b7f55deb91e3175b2a1d1c Mon Sep 17 00:00:00 2001 From: Tom Hulihan Date: Wed, 2 Apr 2014 15:59:04 -0400 Subject: [PATCH] Allow no credentials to be passed to #push. --- lib/docker/image.rb | 4 +- spec/docker/image_spec.rb | 11 +++ .../still_pushes.yml | 67 +++++++++++++++++++ 3 files changed, 80 insertions(+), 2 deletions(-) create mode 100644 spec/vcr/Docker_Image/_push/when_there_are_no_credentials/still_pushes.yml diff --git a/lib/docker/image.rb b/lib/docker/image.rb index 75bb88e5b..4e92cb948 100644 --- a/lib/docker/image.rb +++ b/lib/docker/image.rb @@ -27,8 +27,8 @@ def push(creds = nil, options = {}) raise ArgumentError, "Image does not have a name to push." unless repository - credentials = creds || Docker.creds - headers = Docker::Util.build_auth_header(credentials) + creds ||= Docker.creds + headers = creds.nil? ? {} : Docker::Util.build_auth_header(creds) connection.post( "/images/#{repository}/push", options, diff --git a/spec/docker/image_spec.rb b/spec/docker/image_spec.rb index 44cf2af65..36fbb5df2 100644 --- a/spec/docker/image_spec.rb +++ b/spec/docker/image_spec.rb @@ -127,6 +127,17 @@ it 'pushes the Image', :vcr do new_image.push(credentials) end + + context 'when there are no credentials' do + let(:credentials) { nil } + + before { Docker.creds = nil } + + it 'still pushes', :vcr do + expect { base_image.tag('repo' => 'localhost/base', 'tag' => 'latest') } + .to_not raise_error + end + end end describe '#tag' do diff --git a/spec/vcr/Docker_Image/_push/when_there_are_no_credentials/still_pushes.yml b/spec/vcr/Docker_Image/_push/when_there_are_no_credentials/still_pushes.yml new file mode 100644 index 000000000..231dacc20 --- /dev/null +++ b/spec/vcr/Docker_Image/_push/when_there_are_no_credentials/still_pushes.yml @@ -0,0 +1,67 @@ +--- +http_interactions: +- request: + method: post + uri: unix:///var/run/docker.sock/v1.10/images/create?fromImage=base + body: + encoding: US-ASCII + string: '' + headers: + User-Agent: + - Swipely/Docker-API 1.10.4 + Content-Type: + - text/plain + response: + status: + code: 200 + message: + headers: + Content-Type: + - application/json + Date: + - Wed, 02 Apr 2014 19:58:40 GMT + Connection: + - close + Transfer-Encoding: + - '' + body: + encoding: UTF-8 + string: "{\"status\":\"Pulling repository base\"}\r\n{\"status\":\"Pulling image + (ubuntu-quantl) from base\",\"progressDetail\":{},\"id\":\"b750fe79269d\"}{\"status\":\"Pulling + image (ubuntu-quantl) from base, endpoint: https://cdn-registry-1.docker.io/v1/\",\"progressDetail\":{},\"id\":\"b750fe79269d\"}{\"status\":\"Pulling + dependent layers\",\"progressDetail\":{},\"id\":\"b750fe79269d\"}{\"status\":\"Download + complete\",\"progressDetail\":{},\"id\":\"27cf78414709\"}{\"status\":\"Download + complete\",\"progressDetail\":{},\"id\":\"b750fe79269d\"}{\"status\":\"Download + complete\",\"progressDetail\":{},\"id\":\"b750fe79269d\"}" + http_version: + recorded_at: Wed, 02 Apr 2014 19:58:41 GMT +- request: + method: post + uri: unix:///var/run/docker.sock/v1.10/images/b750fe79269d/tag?repo=localhost%2Fbase&tag=latest + body: + encoding: US-ASCII + string: '' + headers: + User-Agent: + - Swipely/Docker-API 1.10.4 + Content-Type: + - text/plain + response: + status: + code: 201 + message: + headers: + Date: + - Wed, 02 Apr 2014 19:58:41 GMT + Content-Length: + - '0' + Content-Type: + - text/plain; charset=utf-8 + Connection: + - close + body: + encoding: UTF-8 + string: '' + http_version: + recorded_at: Wed, 02 Apr 2014 19:58:41 GMT +recorded_with: VCR 2.8.0