Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
- name: Install dependencies
run: |
gem update --system 3.2.3
gem update --system 3.5.11
bundle install
- name: Release
run: |
Expand Down
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ source "https://rubygems.org"
# Specify your gem's dependencies in dockerapi.gemspec
gemspec

gem "rake", "~> 12.0"
gem "rake", "~> 13.0"
gem "rspec", "~> 3.0"
10 changes: 6 additions & 4 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@ PATH
remote: .
specs:
dockerapi (0.20.0)
excon (~> 0.79)
base64
excon (>= 0.97, < 2)

GEM
remote: https://rubygems.org/
specs:
base64 (0.2.0)
diff-lcs (1.5.1)
excon (0.112.0)
rake (12.3.3)
excon (1.1.1)
rake (13.2.1)
rspec (3.13.0)
rspec-core (~> 3.13.0)
rspec-expectations (~> 3.13.0)
Expand All @@ -30,7 +32,7 @@ PLATFORMS

DEPENDENCIES
dockerapi!
rake (~> 12.0)
rake (~> 13.0)
rspec (~> 3.0)

BUNDLED WITH
Expand Down
7 changes: 4 additions & 3 deletions dockerapi.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ Gem::Specification.new do |spec|
spec.description = "Interact with Docker API directly from Ruby code. Comprehensive implementation (all available endpoints), no local Docker installation required, easily manipulated http responses."
spec.homepage = "https://github.com/nu12/dockerapi"
spec.license = "MIT"
spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
spec.required_ruby_version = ">= 3.0"

spec.metadata["homepage_uri"] = spec.homepage
spec.metadata["source_code_uri"] = "https://github.com/nu12/dockerapi.git"
spec.metadata["changelog_uri"] = "https://github.com/nu12/dockerapi/blob/master/CHANGELOG.md"
spec.metadata["changelog_uri"] = "https://github.com/nu12/dockerapi/blob/main/CHANGELOG.md"
spec.metadata["documentation_uri"] = "https://www.rubydoc.info/gems/dockerapi"

# Specify which files should be added to the gem when it is released.
Expand All @@ -26,5 +26,6 @@ Gem::Specification.new do |spec|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
spec.require_paths = ["lib"]

spec.add_dependency("excon", "~> 0.79")
spec.add_dependency("base64")
spec.add_dependency("excon", ">= 0.97", "< 2")
end
2 changes: 1 addition & 1 deletion lib/docker/api/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def initialize connection = nil
# Output to stdout.
def default_streamer
streamer = lambda do |chunk, remaining_bytes, total_bytes|
p chunk.to_s.encode('UTF-8', invalid: :replace, undef: :replace, replace: '?') if Docker::API::PRINT_TO_STDOUT
p chunk.to_s.encode('UTF-8', invalid: :replace, undef: :replace, replace: '?') if Docker::API.print_to_stdout
end
streamer
end
Expand Down
2 changes: 1 addition & 1 deletion lib/docker/api/connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class Docker::API::Connection
# @param params [Hash]: Request parameters.
def request params
response = Docker::API::Response.new(@connection.request(params).data)
p response if Docker::API::PRINT_RESPONSE_TO_STDOUT
p response if Docker::API.print_response_to_stdout
response
end

Expand Down
16 changes: 14 additions & 2 deletions lib/dockerapi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,23 @@ module API

##
# This variable controls output verbosity.
PRINT_TO_STDOUT = true
def self.print_to_stdout
@@print_to_stdout
end
def self.print_to_stdout=(bool)
@@print_to_stdout = bool
end
self.print_to_stdout = true

##
# This variable controls output verbosity.
PRINT_RESPONSE_TO_STDOUT = false
def self.print_response_to_stdout
@@print_response_to_stdout
end
def self.print_response_to_stdout=(bool)
@@print_response_to_stdout = bool
end
self.print_response_to_stdout = false

##
# Valid values for parameter validations.
Expand Down
8 changes: 4 additions & 4 deletions spec/endpoints/image_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
it { expect(subject.create(fromSrc: path, repo: image, message: "Imported with dockerapi").status).to eq(200) }
end
context "from remote tar file" do
let(:url) { "https://github.com/nu12/dockerapi/blob/master/resources/busybox.tar?raw=true" }
let(:url) { "https://github.com/nu12/dockerapi/raw/refs/heads/main/resources/busybox.tar" }
it { expect(subject.create(fromSrc: url).status).to eq(200) }
it { expect(subject.create(fromSrc: url, repo: image, message: "Imported with dockerapi").status).to eq(200) }
it { expect(subject.create(fromSrc: "http://404").status).to eq(500) }
Expand Down Expand Up @@ -175,7 +175,7 @@
it { expect(subject.build("resources/build.tar.xz", memory: 4000000, rm: true, forcerm:true).status).to eq(200) }
it { expect(subject.build("resources/build.tar.xz", memory: 4000000, rm: true, forcerm:true, pull:true).status).to eq(200) }
it { expect(subject.build(nil, remote: "https://github.com/nu12/dockerapi/raw/refs/heads/main/resources/build.tar.xz").status).to eq(200) }
it { expect(subject.build(nil, remote: "https://raw.githubusercontent.com/nu12/dockerapi/master/resources/Dockerfile").status).to eq(200) }
it { expect(subject.build(nil, remote: "https://raw.githubusercontent.com/nu12/dockerapi/main/resources/Dockerfile").status).to eq(200) }
it { expect{subject.build("resources/build.tar.xz", invalid: "invalid")}.to raise_error(Docker::API::InvalidParameter) }
it { expect{subject.build(nil, remote: "https://github.com/nu12/dockerapi/raw/refs/heads/main/resources/build.tar.xz", invalid: "invalid")}.to raise_error(Docker::API::InvalidParameter) }
it { expect{subject.build(nil, invalid: "invalid", skip_validation: true)}.to raise_error(Docker::API::Error) }
Expand Down Expand Up @@ -223,7 +223,7 @@

described_class.new.tag(original, repo: local)

Docker::API::PRINT_RESPONSE_TO_STDOUT = true
Docker::API.print_response_to_stdout = true
end

it { expect(Docker::API::Container.new.list.json.size).to be > 0 }
Expand All @@ -248,7 +248,7 @@
end

after(:all) do
Docker::API::PRINT_RESPONSE_TO_STDOUT = false
Docker::API.print_response_to_stdout = false

container = Docker::API::Container.new
container.stop("registry")
Expand Down
4 changes: 2 additions & 2 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
require "bundler/setup"
require "dockerapi"

Docker::API::PRINT_TO_STDOUT = false
Docker::API.print_to_stdout = false

Docker::API::PRINT_RESPONSE_TO_STDOUT = false
Docker::API.print_response_to_stdout = false

RSpec.configure do |config|
# Enable flags like --only-failures and --next-failure
Expand Down