diff --git a/lib/buildpack/compile/dnu.rb b/lib/buildpack/compile/dnu.rb index 42423585f..efd4f3a19 100644 --- a/lib/buildpack/compile/dnu.rb +++ b/lib/buildpack/compile/dnu.rb @@ -22,6 +22,7 @@ def initialize(shell) def restore(dir, out) @shell.env['HOME'] = dir + @shell.path << '/app/mono/bin' cmd = "bash -c 'source #{dir}/.dnx/dnvm/dnvm.sh; dnvm use default -r mono -a x64; cd #{dir}; dnu restore'" @shell.exec(cmd, out) end diff --git a/lib/buildpack/compile/dnx_installer.rb b/lib/buildpack/compile/dnx_installer.rb index 671e61186..f7efda505 100644 --- a/lib/buildpack/compile/dnx_installer.rb +++ b/lib/buildpack/compile/dnx_installer.rb @@ -28,6 +28,7 @@ def initialize(shell) def install(dir, out) @shell.env['HOME'] = dir + @shell.path << '/app/mono/bin' version = dnx_version(dir, out) @shell.exec("bash -c 'source #{dir}/.dnx/dnvm/dnvm.sh; dnvm install #{version} -p -r mono'", out) end diff --git a/lib/buildpack/compiler.rb b/lib/buildpack/compiler.rb index 22a56511e..ff1933c82 100644 --- a/lib/buildpack/compiler.rb +++ b/lib/buildpack/compiler.rb @@ -79,12 +79,17 @@ def copy_nowin(out) end def install_mozroot_certs(out) - mozroots.import(out) + dest_dir = File.join(build_dir, '..') + unless File.exist? File.join(dest_dir, '.config', '.mono', 'certs') + mozroots.import(out) + copier.cp(File.join(Dir.home, '.config', '.mono', 'certs'), File.join(dest_dir, '.config', '.mono'), out) + end end def restore_cache(out) copier.cp(File.join(cache_dir, '.dnx'), build_dir, out) if File.exist? File.join(cache_dir, '.dnx') copier.cp(File.join(cache_dir, 'mono'), File.join('/', 'app'), out) if File.exist? File.join(cache_dir, 'mono') + copier.cp(File.join(cache_dir, 'certs'), File.join(build_dir, '..', '.config', '.mono'), out) if File.exist? File.join(cache_dir, 'certs') end def install_dnvm(out) @@ -106,6 +111,7 @@ def move_to_app_dir(out) def save_cache(out) copier.cp(File.join(build_dir, '.dnx'), cache_dir, out) copier.cp(File.join('/app', 'mono'), cache_dir, out) unless File.exists? File.join(cache_dir, 'mono') + copier.cp(File.join(Dir.home, '.config', '.mono', 'certs'), cache_dir, out) unless File.exists? File.join(cache_dir, 'certs') end def write_release_yml(out) diff --git a/spec/buildpack/compile/compile_spec.rb b/spec/buildpack/compile/compile_spec.rb index d8369b4eb..015a73c5c 100644 --- a/spec/buildpack/compile/compile_spec.rb +++ b/spec/buildpack/compile/compile_spec.rb @@ -154,8 +154,17 @@ it 'imports the certificates' do expect(mozroots).to receive(:import) + expect(copier).to receive(:cp).with(File.join(Dir.home, '.config', '.mono', 'certs'), File.join(build_dir, '..', '.config', '.mono'), anything) compiler.compile end + + context 'when the certificates are already downloaded' do + it 'does not re-download then' do + allow(File).to receive(:exist?).and_return(true) + expect(copier).not_to receive(:cp).with(File.join(Dir.home, '.config', '.mono', 'certs'), anything) + compiler.compile + end + end end describe 'Installing DNVM' do @@ -181,11 +190,13 @@ before(:each) do Dir.mkdir(File.join(cache_dir, '.dnx')) Dir.mkdir(File.join(cache_dir, 'mono')) + FileUtils.mkdir_p(File.join(cache_dir, 'certs')) end it 'restores all files from the cache to build dir' do expect(copier).to receive(:cp).with(File.join(cache_dir, '.dnx'), build_dir, anything) expect(copier).to receive(:cp).with(File.join(cache_dir, 'mono'), '/app', anything) + expect(copier).to receive(:cp).with(File.join(cache_dir, 'certs'), File.join(build_dir, '..', '.config', '.mono'), anything) compiler.compile end end @@ -215,12 +226,15 @@ it 'copies .dnx and mono to cache dir' do expect(copier).to receive(:cp).with("#{build_dir}/.dnx", cache_dir, anything) expect(copier).to receive(:cp).with('/app/mono', cache_dir, anything) + expect(copier).to receive(:cp).with(File.join(Dir.home, '.config', '.mono', 'certs'), cache_dir, anything) compiler.compile end - context 'when mono is already cached' do + context 'when the cache already exists' do before(:each) do + Dir.mkdir(File.join(cache_dir, '.dnx')) Dir.mkdir(File.join(cache_dir, 'mono')) + FileUtils.mkdir_p(File.join(cache_dir, '.config', '.mono', 'certs')) end it 'copies only .dnx to cache dir' do expect(copier).to receive(:cp).with("#{build_dir}/.dnx", cache_dir, anything) diff --git a/spec/buildpack/compile/dnu_spec.rb b/spec/buildpack/compile/dnu_spec.rb index 0fd30be4c..4892028f4 100644 --- a/spec/buildpack/compile/dnu_spec.rb +++ b/spec/buildpack/compile/dnu_spec.rb @@ -19,7 +19,7 @@ describe AspNet5Buildpack::DNU do let(:shell) do - double(:shell, env: {}) + double(:shell, env: {}, path: []) end let(:out) do @@ -37,6 +37,12 @@ expect(shell.env).to include('HOME' => 'app-dir') end + it 'adds /app/mono/bin to the path' do + allow(shell).to receive(:exec) + dnu.restore('app-dir', out) + expect(shell.path).to include('/app/mono/bin') + end + it 'adds dnu to the PATH' do allow(shell).to receive(:exec) expect(shell).to receive(:exec).with(match('dnvm use default'), out) @@ -54,4 +60,5 @@ expect(shell).to receive(:exec).with(match('dnu restore'), out) dnu.restore('app-dir', out) end + end diff --git a/spec/buildpack/compile/dnx_install_spec.rb b/spec/buildpack/compile/dnx_install_spec.rb index ccca55fc6..1484f8628 100644 --- a/spec/buildpack/compile/dnx_install_spec.rb +++ b/spec/buildpack/compile/dnx_install_spec.rb @@ -20,7 +20,7 @@ describe AspNet5Buildpack::DnxInstaller do let(:shell) do - double(:shell, env: {}) + double(:shell, env: {}, path: []) end let(:out) do @@ -41,6 +41,12 @@ expect(shell.env).to include('HOME' => dir) end + it 'adds /app/mono/bin to the path' do + allow(shell).to receive(:exec) + installer.install(dir, out) + expect(shell.path).to include('/app/mono/bin') + end + it 'sources the dnvm script' do allow(shell).to receive(:exec) expect(shell).to receive(:exec).with(match("source #{dir}/.dnx/dnvm/dnvm.sh"), out)