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

Support specifying a build path when building images from a string #13

Merged
merged 1 commit into from
Jul 2, 2017
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
9 changes: 8 additions & 1 deletion lib/dockerspec/builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ class Builder
# environment variable and uses `'.'` if it is not set.
# @option opts [String] :string Use this string as *Dockerfile* instead of
# `:path`. Not set by default.
# @option opts [String] :string_build_path Used to specify the path that is
# used for the docker build of a string *Dockerfile*. This enables ADD
# statements in the Dockerfile to access files that are outside of .
# Not set by default and overrides the default '.'
# @option opts [String] :template Use this [Erubis]
# (http://www.kuwata-lab.com/erubis/users-guide.html) template file as
# *Dockerfile*.
Expand Down Expand Up @@ -274,13 +278,16 @@ def build_block
#
# @param string [String] The Dockerfile content.
# @param dir [String] The directory to copy the files from. Files that are
# required by the Dockerfile passed in *string*.
# required by the Dockerfile passed in *string*. If not passed, then
# the 'string_build_path' option is used. If that is not used, '.' is
# assumed.
#
# @return void
#
# @api private
#
def build_from_string(string, dir = '.')
dir = @options[:string_build_path] if @options[:string_build_path]
Dir.mktmpdir do |tmpdir|
FileUtils.cp_r("#{dir}/.", tmpdir)
dockerfile = File.join(tmpdir, 'Dockerfile')
Expand Down
16 changes: 16 additions & 0 deletions spec/integration/dockerfiles/from_string_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,5 +94,21 @@
end
end
end
context 'With string_build_path' do
Dir.mktmpdir do |dir|
File.write("#{dir}/test", 'rspec integration tests')
dockerfile_string = "FROM nginx:1.9\nADD test /test"
describe docker_build(
string: dockerfile_string,
string_build_path: dir) do
describe docker_run(described_image) do
describe command('cat /test') do
its(:stdout) { should match(/rspec integration tests/) }
its(:exit_status) { should eq 0 }
end
end
end
end
end
end
end
17 changes: 17 additions & 0 deletions spec/unit/builder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,23 @@
subject.build
end
end

context 'string_build_path option' do
let(:subject) do
described_class.new(string: string, string_build_path: '/tmp')
end

it 'Handles build with string_build_path specified' do
expect(FileUtils).to receive(:cp_r).with('/tmp/.', tmpdir)
subject.build
end

it 'Uses the current directory if no value is passed' do
subject = described_class.new(string: string)
expect(FileUtils).to receive(:cp_r).with('./.', tmpdir)
subject.build
end
end
end

context 'passing a file to the path option' do
Expand Down