upserve / docker-api

A lightweight Ruby client for the Docker Remote API
MIT License
1.09k stars 288 forks source link

Dependency 'json' missing? #519

Closed apophizzz closed 4 years ago

apophizzz commented 6 years ago

Hi,

When executing my serverspec tests within an Alpine-based Docker container with Ruby 2.4 installed, my tests always failed and I got the following stack trace:

1) Dockerfile has go package installed
     Failure/Error: @image = Docker::Image.build_from_dir('./variants/go')
     NameError:
       uninitialized constant Docker::Util::JSON

     # /home/jenkins/.gem/ruby/2.4.0/gems/docker-api-1.34.0/lib/docker/util.rb:244:in `build_config_header'
     # /home/jenkins/.gem/ruby/2.4.0/gems/docker-api-1.34.0/lib/docker/image.rb:308:in `build_headers'
     # /home/jenkins/.gem/ruby/2.4.0/gems/docker-api-1.34.0/lib/docker/image.rb:270:in `build_from_tar'
     # /home/jenkins/.gem/ruby/2.4.0/gems/docker-api-1.34.0/lib/docker/image.rb:293:in `build_from_dir'
     # ./spec/go/Dockerfile_spec.rb:12:in `block (2 levels) in <top (required)>

This first happened after I added the following line in my Dockerfile_spec.rb, which serves the purpose of doing a login to my private Docker registry:

Docker.authenticate!('username' => ENV['DOCKER_USERNAME'], 'password' => ENV['DOCKER_PASSWD'], 'serveraddress' => ENV['DOCKER_REGISTRY'])

I finally succeeded in fixing this by explicitly pulling the json gem in my project's Gemfile:

source 'https://rubygems.org'

gem 'docker-api', :require => 'docker'
gem 'serverspec'
gem 'io-console'

gem 'json' # This line fixed my issue

Shouldn't this dependency be declared on your side?

Cheers, Patrick

tlunter commented 6 years ago

Ah, darn, we converted to MultiJson but must've missed one use of JSON. Will fix.