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

Verify cache support works #275

Merged
merged 1 commit into from
Apr 29, 2015
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
29 changes: 27 additions & 2 deletions lib/docker/util.rb
Original file line number Diff line number Diff line change
Expand Up @@ -138,15 +138,40 @@ def create_relative_dir_tar(directory, output)
next unless stat.file?

unprefixed_file_name = prefixed_file_name[directory.length..-1]
tar.add_file_simple(
unprefixed_file_name, stat.mode, stat.size
add_file_to_tar(
tar, unprefixed_file_name, stat.mode, stat.size, stat.mtime
) do |tar_file|
IO.copy_stream(File.open(prefixed_file_name, 'rb'), tar_file)
end
end
end
end

def add_file_to_tar(tar, name, mode, size, mtime)
tar.check_closed

io = tar.instance_variable_get(:@io)

name, prefix = tar.split_name(name)

header = Gem::Package::TarHeader.new(:name => name, :mode => mode,
:size => size, :prefix => prefix,
:mtime => mtime).to_s

io.write header
os = Gem::Package::TarWriter::BoundedStream.new io, size

yield os if block_given?

min_padding = size - os.written
io.write("\0" * min_padding)

remainder = (512 - (size % 512)) % 512
io.write("\0" * remainder)

tar
end

def create_temp_file
tempfile_name = Dir::Tmpname.create('out') {}
File.open(tempfile_name, 'wb+')
Expand Down
32 changes: 27 additions & 5 deletions spec/docker/image_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -564,30 +564,37 @@
Docker::Container.create('Image' => image.id,
'Cmd' => %w[cat /Dockerfile])
end
let!(:output) {
container.tap(&:start).streaming_logs(stdout: true)
}
let(:output) { container.streaming_logs(stdout: true) }

after(:each) do
container.tap(&:wait).remove
image.remove(:noprune => true)
end

context 'with no query parameters' do
it 'builds the image', :vcr do
container.wait
container.tap(&:wait).start
expect(output).to eq(docker_file.read)
end

after do
container.remove
end
end

context 'with specifying a repo in the query parameters' do
let(:opts) { { "t" => "#{ENV['DOCKER_API_USER']}/debian:from_dir" } }
it 'builds the image and tags it', :vcr do
container.tap(&:wait).start
expect(output).to eq(docker_file.read)
image.refresh!
expect(image.info["RepoTags"]).to eq(
["#{ENV['DOCKER_API_USER']}/debian:from_dir"]
)
end

after do
container.remove
end
end

context 'with a block capturing build output' do
Expand All @@ -598,6 +605,21 @@
image # Create the image variable, which is lazy-loaded by Rspec
expect(build_output).to match(/Step 0 : FROM debian:wheezy/)
end

context 'uses a cached version the second time' do
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) }

it 'calls the block and passes build output', :vcr do
image # Create the image variable, which is lazy-loaded by Rspec
expect(build_output).to match(/Step 0 : FROM debian:wheezy/)
expect(build_output).to_not match(/Using cache/)

image_two # Create the image_two variable, which is lazy-loaded by Rspec
expect(build_output_two).to match(/Using cache/)
end
end
end

context 'with credentials passed' do
Expand Down
2 changes: 1 addition & 1 deletion spec/support/vcr.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

VCR.configure do |c|
c.allow_http_connections_when_no_cassette = false
c.filter_sensitive_data('<DOCKER_HOST>') { Docker.url.sub(/tcp\:/, 'https:') }
c.filter_sensitive_data('<DOCKER_HOST>') { Docker.url }
c.filter_sensitive_data('<USERNAME>') { ENV['DOCKER_API_USER'] }
c.filter_sensitive_data('<PASSWORD>') { ENV['DOCKER_API_PASS'] }
c.filter_sensitive_data('<EMAIL>') { ENV['DOCKER_API_EMAIL'] }
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.