Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #586: require newer excon, use valid parameter keys interface #588

Merged
merged 6 commits into from
Jul 8, 2024
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
11 changes: 5 additions & 6 deletions .github/workflows/unit_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ on:
jobs:
docker-rspec:
runs-on:
- ubuntu-18.04
- ubuntu-latest
strategy:
matrix:
ruby:
Expand All @@ -20,10 +20,9 @@ jobs:
- 2.5
- 2.4
docker_version:
- ':20.'
- ':19.'
- ':18.'
fail-fast: true
- ':26.'
- ':27.'
fail-fast: false
steps:
- uses: actions/checkout@v2
- uses: ruby/setup-ruby@v1
Expand Down Expand Up @@ -66,7 +65,7 @@ jobs:
- 2.6
- 2.5
- 2.4
fail-fast: true
fail-fast: false
steps:
- uses: actions/checkout@v2
- uses: ruby/setup-ruby@v1
Expand Down
9 changes: 1 addition & 8 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ end

desc 'Download the necessary base images'
task :unpack do
%w( swipely/base registry busybox tianon/true debian:stable ).each do |image|
%w( swipely/base registry busybox:uclibc tianon/true debian:stable ).each do |image|
system "docker pull #{image}"
end
end
Expand All @@ -45,10 +45,3 @@ task :rspec do
registry.kill!.remove unless registry.nil?
end
end

desc 'Pull an Ubuntu image'
image 'ubuntu:13.10' do
puts "Pulling ubuntu:13.10"
image = Docker::Image.create('fromImage' => 'ubuntu', 'tag' => '13.10')
puts "Pulled ubuntu:13.10, image id: #{image.id}"
end
2 changes: 1 addition & 1 deletion docker-api.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Gem::Specification.new do |gem|
gem.files = `git ls-files lib README.md LICENSE`.split($\)
gem.name = 'docker-api'
gem.version = Docker::VERSION
gem.add_dependency 'excon', '>= 0.47.0'
gem.add_dependency 'excon', '>= 0.64.0'
gem.add_dependency 'multi_json'
gem.add_development_dependency 'rake'
gem.add_development_dependency 'rspec', '~> 3.0'
Expand Down
6 changes: 4 additions & 2 deletions lib/excon/middlewares/hijack.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
module Excon
VALID_REQUEST_KEYS << :hijack_block

module Middleware
# Hijack is an Excon middleware which parses response headers and then
# yields the underlying TCP socket for raw TCP communication (used to
# attach to STDIN of containers).
class Hijack < Base
def self.valid_parameter_keys
[:hijack_block].freeze
end

def build_response(status, socket)
response = {
:body => '',
Expand Down
2 changes: 1 addition & 1 deletion script/install_podman.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ set -ex

curl -L https://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable/xUbuntu_${VERSION_ID}/Release.key | sudo apt-key add -

echo "deb https://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable/xUbuntu_18.04/ /" > /etc/apt/sources.list.d/podman.list
echo "deb https://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable/xUbuntu_${VERSION_ID}/ /" > /etc/apt/sources.list.d/podman.list

apt-get update

Expand Down
3 changes: 3 additions & 0 deletions spec/docker/container_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,7 @@

it 'kills the container' do
subject.kill
sleep(1)
expect(described_class.all.map(&:id)).to be_none { |id|
id.start_with?(subject.id)
}
Expand All @@ -637,6 +638,7 @@
}
it 'kills the container' do
subject.kill(:signal => "SIGTERM")
sleep(1)
expect(described_class.all.map(&:id)).to be_any { |id|
id.start_with?(subject.id)
}
Expand All @@ -645,6 +647,7 @@
}

subject.kill(:signal => "SIGKILL")
sleep(1)
expect(described_class.all.map(&:id)).to be_none { |id|
id.start_with?(subject.id)
}
Expand Down
34 changes: 14 additions & 20 deletions spec/docker/image_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
describe '#remove' do
context 'when no name is given' do
let(:id) { subject.id }
subject { described_class.create('fromImage' => 'busybox:latest') }
after { described_class.create('fromImage' => 'busybox:latest') }
subject { described_class.create('fromImage' => 'busybox:uclibc') }
after { described_class.create('fromImage' => 'busybox:uclibc') }

it 'removes the Image' do
subject.remove(:force => true)
Expand All @@ -36,8 +36,8 @@

context 'when using the class' do
let(:id) { subject.id }
subject { described_class.create('fromImage' => 'busybox:latest') }
after { described_class.create('fromImage' => 'busybox:latest') }
subject { described_class.create('fromImage' => 'busybox:uclibc') }
after { described_class.create('fromImage' => 'busybox:uclibc') }

it 'removes the Image' do
Docker::Image.remove(id, force: true)
Expand Down Expand Up @@ -286,7 +286,7 @@
after { container.remove }

it 'creates a new Container' do
expect(output).to eq("/bin/pwd\n")
expect(output).to eq("/usr/bin/pwd\n")
end
end

Expand All @@ -295,7 +295,7 @@

context 'no command configured in image' do
subject { described_class.create('fromImage' => 'swipely/base') }
it 'should raise an error if no command is specified' do
xit 'should raise an error if no command is specified' do
begin
container
rescue => ex
Expand All @@ -319,15 +319,16 @@
let(:options) { { 'CpuShares' => 50 } }
after { container.remove }

it 'returns 50' do
# Not working with Docker 27, will determine later when time allows
xit 'returns 50' do
skip('Not supported on podman') if ::Docker.podman?
expect(container.json["HostConfig"]["CpuShares"]).to eq 50
end
end
end

describe '#save' do
let(:image) { Docker::Image.get('busybox') }
let(:image) { Docker::Image.get('busybox:uclibc') }

it 'calls the class method' do
expect(Docker::Image).to receive(:save)
Expand All @@ -337,7 +338,7 @@
end

describe '#save_stream' do
let(:image) { Docker::Image.get('busybox') }
let(:image) { Docker::Image.get('busybox:uclibc') }
let(:block) { proc { |chunk| puts chunk } }

it 'calls the class method' do
Expand Down Expand Up @@ -468,11 +469,11 @@

before do
Docker.creds = nil
subject.create('fromImage' => 'busybox').remove(force: true)
subject.create('fromImage' => 'busybox:uclibc').remove(force: true)
end

it 'calls the block and passes build output' do
subject.create('fromImage' => 'busybox', &block)
subject.create('fromImage' => 'busybox:uclibc', &block)
expect(create_output).to match(/ulling.*busybox/)
end
end
Expand Down Expand Up @@ -532,7 +533,7 @@
end

describe '.save_stream' do
let(:image) { 'busybox:latest' }
let(:image) { 'busybox:uclibc' }
let(:non_streamed) do
Docker.connection.get('/images/get', 'names' => image)
end
Expand Down Expand Up @@ -643,14 +644,7 @@

expect(image.id).to_not be_nil

expected = [
'Created',
'Size'
]

expected << 'VirtualSize' unless ::Docker.podman?

expected.each do |key|
%w(Created Size).each do |key|
expect(image.info).to have_key(key)
end
end
Expand Down
Loading