Skip to content

Commit

Permalink
Merge pull request #590 from bquorning/frozen-strings
Browse files Browse the repository at this point in the history
Ensure that docker-api works with frozen strings
  • Loading branch information
ls-todd-lunter authored Oct 30, 2024
2 parents a4d4416 + c416cfd commit 60f2c78
Show file tree
Hide file tree
Showing 37 changed files with 97 additions and 35 deletions.
2 changes: 0 additions & 2 deletions .cane

This file was deleted.

26 changes: 16 additions & 10 deletions .github/workflows/unit_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ jobs:
strategy:
matrix:
ruby:
- 3.3
- 3.2
- 3.1
- '3.0'
- 2.7
- 2.6
- 2.5
Expand All @@ -24,14 +28,13 @@ jobs:
- ':27.'
fail-fast: false
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}
- name: install bundler
run: |
gem install bundler -v '~> 1.17.3'
bundle update
bundler-cache: true
- name: Update gems
run: bundle update
- name: install docker
env:
DOCKER_VERSION: ${{ matrix.docker_version }}
Expand Down Expand Up @@ -61,20 +64,23 @@ jobs:
strategy:
matrix:
ruby:
- 3.3
- 3.2
- 3.1
- '3.0'
- 2.7
- 2.6
- 2.5
- 2.4
fail-fast: false
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}
- name: install bundler
run: |
gem install bundler -v '~> 1.17.3'
bundle update
bundler-cache: true
- name: Update gems
run: bundle update
- name: install podman
run: sudo ./script/install_podman.sh
- name: spec tests
Expand Down
2 changes: 2 additions & 0 deletions .simplecov
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

SimpleCov.start do
add_group 'Library', 'lib'
add_group 'Specs', 'spec'
Expand Down
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

source 'http://rubygems.org'

gemspec
10 changes: 3 additions & 7 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,23 +1,19 @@
# frozen_string_literal: true

require 'bundler/setup'

ENV['PATH'] = "/opt/docker/:#{ENV['PATH']}" if ENV['CI'] == 'true'

require 'docker'
require 'rspec/core/rake_task'
require 'cane/rake_task'


desc 'Run the full test suite from scratch'
task :default => [:unpack, :rspec, :quality]
task :default => [:unpack, :rspec]

RSpec::Core::RakeTask.new do |t|
t.pattern = 'spec/**/*_spec.rb'
end

Cane::RakeTask.new(:quality) do |cane|
cane.canefile = '.cane'
end

desc 'Download the necessary base images'
task :unpack do
%w( swipely/base registry busybox:uclibc tianon/true debian:stable ).each do |image|
Expand Down
3 changes: 0 additions & 3 deletions TESTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@ This repository comes with five Rake commands to assist in your testing of the c
## `rake rspec`
This command will run Rspec tests normally on your local system. You must have all the required base images pulled.

## `rake quality`
This command runs a code quality threshold checker to hinder bad code.

## `rake unpack`
Pulls down all the required base images for testing.

Expand Down
3 changes: 2 additions & 1 deletion docker-api.gemspec
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# -*- encoding: utf-8 -*-
# frozen_string_literal: true

require File.expand_path('../lib/docker/version', __FILE__)

Gem::Specification.new do |gem|
Expand All @@ -15,7 +17,6 @@ Gem::Specification.new do |gem|
gem.add_development_dependency 'rake'
gem.add_development_dependency 'rspec', '~> 3.0'
gem.add_development_dependency 'rspec-its'
gem.add_development_dependency 'cane'
gem.add_development_dependency 'pry'
gem.add_development_dependency 'single_cov'
gem.add_development_dependency 'webmock'
Expand Down
2 changes: 2 additions & 0 deletions lib/docker-api.rb
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
# frozen_string_literal: true

require 'docker'
2 changes: 2 additions & 0 deletions lib/docker.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'cgi'
require 'multi_json'
require 'excon'
Expand Down
2 changes: 2 additions & 0 deletions lib/docker/base.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

# This class is a base class for Docker Container and Image.
# It is implementing accessor methods for the models attributes.
module Docker::Base
Expand Down
2 changes: 2 additions & 0 deletions lib/docker/connection.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

# This class represents a Connection to a Docker server. The Connection is
# immutable in that once the url and options is set they cannot be changed.
class Docker::Connection
Expand Down
2 changes: 2 additions & 0 deletions lib/docker/container.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

# This class represents a Docker Container. It's important to note that nothing
# is cached so that the information is always up to date.
class Docker::Container
Expand Down
2 changes: 2 additions & 0 deletions lib/docker/error.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

# This module holds the Errors for the gem.
module Docker::Error

Expand Down
2 changes: 2 additions & 0 deletions lib/docker/event.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

# This class represents a Docker Event.
class Docker::Event
include Docker::Error
Expand Down
2 changes: 2 additions & 0 deletions lib/docker/exec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

# This class represents a Docker Exec Instance.
class Docker::Exec
include Docker::Base
Expand Down
16 changes: 9 additions & 7 deletions lib/docker/image.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

# This class represents a Docker Image.
class Docker::Image
include Docker::Base
Expand Down Expand Up @@ -28,7 +30,7 @@ def push(creds = nil, options = {}, &block)
repo, tag = Docker::Util.parse_repo_tag(repo_tag)
raise ArgumentError, "Image does not have a name to push." if repo.nil?

body = ""
body = +""
credentials = creds || Docker.creds || {}
headers = Docker::Util.build_auth_header(credentials)
opts = {:tag => tag}.merge(options)
Expand Down Expand Up @@ -119,7 +121,7 @@ class << self
def create(opts = {}, creds = nil, conn = Docker.connection, &block)
credentials = creds.nil? ? Docker.creds : MultiJson.dump(creds)
headers = credentials && Docker::Util.build_auth_header(credentials) || {}
body = ''
body = +''
conn.post(
'/images/create',
opts,
Expand Down Expand Up @@ -168,7 +170,7 @@ def save(names, filename = nil, conn = Docker.connection)
end
nil
else
string = ''
string = +''
save_stream(names, {}, conn, &response_block_for_save(string))
string
end
Expand Down Expand Up @@ -196,7 +198,7 @@ def save_stream(names, opts = {}, conn = Docker.connection, &block)
def load(tar, opts = {}, conn = Docker.connection, creds = nil, &block)
headers = build_headers(creds)
io = tar.is_a?(String) ? File.open(tar, 'rb') : tar
body = ""
body = +""
conn.post(
'/images/load',
opts,
Expand Down Expand Up @@ -267,7 +269,7 @@ def import_stream(options = {}, connection = Docker.connection, &block)

# Given a Dockerfile as a string, builds an Image.
def build(commands, opts = {}, connection = Docker.connection, &block)
body = ""
body = +""
connection.post(
'/build', opts,
:body => Docker::Util.create_tar('Dockerfile' => commands),
Expand All @@ -288,7 +290,7 @@ def build_from_tar(tar, opts = {}, connection = Docker.connection,
headers = build_headers(creds)

# The response_block passed to Excon will build up this body variable.
body = ""
body = +""
connection.post(
'/build', opts,
:headers => headers,
Expand Down Expand Up @@ -340,7 +342,7 @@ def path_for(resource)
# Convience method to get the Dockerfile for a file hash and a path to
# output to.
def dockerfile_for(file_hash, output_path)
dockerfile = "from #{self.id}\n"
dockerfile = +"from #{self.id}\n"

file_hash.keys.each do |basename|
dockerfile << "add #{basename} #{output_path}\n"
Expand Down
2 changes: 2 additions & 0 deletions lib/docker/messages.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

# This class represents all the messages either received by chunks from attach
class Docker::Messages

Expand Down
2 changes: 2 additions & 0 deletions lib/docker/messages_stack.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

# This class represents a messages stack
class Docker::MessagesStack

Expand Down
2 changes: 2 additions & 0 deletions lib/docker/network.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

# This class represents a Docker Network.
class Docker::Network
include Docker::Base
Expand Down
2 changes: 2 additions & 0 deletions lib/docker/rake_task.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

# This class allows image-based tasks to be created.
class Docker::ImageTask < Rake::Task
def self.scope_name(_scope, task_name)
Expand Down
2 changes: 2 additions & 0 deletions lib/docker/util.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'set'

# This module holds shared logic that doesn't really belong anywhere else in the
Expand Down
2 changes: 2 additions & 0 deletions lib/docker/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Docker
# The version of the docker-api gem.
VERSION = '2.3.0'
Expand Down
2 changes: 2 additions & 0 deletions lib/docker/volume.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

# class represents a Docker Volume
class Docker::Volume
include Docker::Base
Expand Down
2 changes: 2 additions & 0 deletions lib/excon/middlewares/hijack.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Excon
module Middleware
# Hijack is an Excon middleware which parses response headers and then
Expand Down
2 changes: 2 additions & 0 deletions spec/cov_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'spec_helper'

SingleCov.not_covered!
Expand Down
2 changes: 2 additions & 0 deletions spec/docker/connection_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'spec_helper'

SingleCov.covered! uncovered: 12
Expand Down
2 changes: 2 additions & 0 deletions spec/docker/container_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'spec_helper'

SingleCov.covered! uncovered: 39
Expand Down
2 changes: 2 additions & 0 deletions spec/docker/event_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'spec_helper'

SingleCov.covered! uncovered: 5
Expand Down
2 changes: 2 additions & 0 deletions spec/docker/exec_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'spec_helper'

SingleCov.covered! uncovered: 5
Expand Down
12 changes: 7 additions & 5 deletions spec/docker/image_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'spec_helper'

SingleCov.covered! uncovered: 16
Expand Down Expand Up @@ -464,7 +466,7 @@
end

context 'with a block capturing create output' do
let(:create_output) { "" }
let(:create_output) { +"" }
let(:block) { Proc.new { |chunk| create_output << chunk } }

before do
Expand Down Expand Up @@ -537,7 +539,7 @@
let(:non_streamed) do
Docker.connection.get('/images/get', 'names' => image)
end
let(:streamed) { '' }
let(:streamed) { +'' }
let(:tar_files) do
proc do |string|
Gem::Package::TarReader
Expand Down Expand Up @@ -723,7 +725,7 @@
end

context 'with a block capturing build output' do
let(:build_output) { "" }
let(:build_output) { +"" }
let(:block) { Proc.new { |chunk| build_output << chunk } }
let!(:image) { subject.build("FROM debian:stable\n", &block) }

Expand Down Expand Up @@ -775,7 +777,7 @@
end

context 'with a block capturing build output' do
let(:build_output) { "" }
let(:build_output) { +"" }
let(:block) { Proc.new { |chunk| build_output << chunk } }

it 'calls the block and passes build output' do
Expand All @@ -784,7 +786,7 @@
end

context 'uses a cached version the second time' do
let(:build_output_two) { "" }
let(:build_output_two) { +"" }
let(:block_two) { Proc.new { |chunk| build_output_two << chunk } }
let(:image_two) { subject.build_from_dir(dir, opts, &block_two) }

Expand Down
2 changes: 2 additions & 0 deletions spec/docker/messages_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'spec_helper'

SingleCov.covered! uncovered: 4
Expand Down
2 changes: 2 additions & 0 deletions spec/docker/messages_stack.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'spec_helper'

SingleCov.covered!
Expand Down
2 changes: 2 additions & 0 deletions spec/docker/network_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'spec_helper'

unless ::Docker.podman?
Expand Down
2 changes: 2 additions & 0 deletions spec/docker/util_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'spec_helper'
require 'tempfile'
require 'fileutils'
Expand Down
2 changes: 2 additions & 0 deletions spec/docker/volume_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'spec_helper'

SingleCov.covered! uncovered: 1
Expand Down
Loading

0 comments on commit 60f2c78

Please sign in to comment.