From 5e3748249b0e3cb8aa154c3e489b0b6e4359cae7 Mon Sep 17 00:00:00 2001 From: Michael Peters Date: Fri, 29 May 2015 14:03:21 -0400 Subject: [PATCH] switch k tools to d tools --- README.md | 4 +- VERSION | 2 +- lib/buildpack.rb | 6 +- .../compile/{kre_installer.rb => dnu.rb} | 9 +- .../{kvm_installer.rb => dnvm_installer.rb} | 8 +- lib/buildpack/compile/dnx_installer.rb | 56 +++++++++ lib/buildpack/compile/kpm.rb | 28 ----- lib/buildpack/compile/mono_installer.rb | 7 +- lib/buildpack/compile/release_yml_writer.rb | 15 ++- lib/buildpack/compiler.rb | 42 +++---- lib/buildpack/copier.rb | 1 + manifest.yml | 12 +- resources/Nowin.vNext/NowinServerFactory.cs | 6 +- resources/Nowin.vNext/project.json | 10 +- spec/buildpack/compile/compile_spec.rb | 48 ++++---- .../compile/{kpm_spec.rb => dnu_spec.rb} | 28 ++--- spec/buildpack/compile/dnvm_installer_spec.rb | 54 +++++++++ spec/buildpack/compile/dnx_install_spec.rb | 108 ++++++++++++++++++ spec/buildpack/compile/kre_install_spec.rb | 42 ------- spec/buildpack/compile/kvm_installer_spec.rb | 44 ------- spec/buildpack/compile/mono_installer_spec.rb | 3 +- .../compile/release_yml_writer_spec.rb | 54 +++++++-- spec/buildpack/copier_spec.rb | 1 + 23 files changed, 369 insertions(+), 219 deletions(-) rename lib/buildpack/compile/{kre_installer.rb => dnu.rb} (73%) rename lib/buildpack/compile/{kvm_installer.rb => dnvm_installer.rb} (73%) create mode 100644 lib/buildpack/compile/dnx_installer.rb delete mode 100644 lib/buildpack/compile/kpm.rb rename spec/buildpack/compile/{kpm_spec.rb => dnu_spec.rb} (61%) create mode 100644 spec/buildpack/compile/dnvm_installer_spec.rb create mode 100644 spec/buildpack/compile/dnx_install_spec.rb delete mode 100644 spec/buildpack/compile/kre_install_spec.rb delete mode 100644 spec/buildpack/compile/kvm_installer_spec.rb diff --git a/README.md b/README.md index 5188d3393..d45b352e3 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Cloud Foundry buildpack: ASP.NET 5 -A Cloud Foundry buildpack for ASP.NET 5 ([beta3][]) apps. For more information about ASP.NET 5 see: +A Cloud Foundry buildpack for ASP.NET 5 ([beta4][]) apps. For more information about ASP.NET 5 see: * https://github.com/aspnet/home * http://docs.asp.net/en/latest/conceptual-overview/aspnet.html @@ -68,4 +68,4 @@ Open an issue on this project. [Hello World sample]: https://github.com/opiethehokie/asp.net5-helloworld -[beta3]: https://github.com/aspnet/Home/releases/tag/v1.0.0-beta3 +[beta4]: https://github.com/aspnet/Home/releases/tag/v1.0.0-beta4 diff --git a/VERSION b/VERSION index 6e8bf73aa..0ea3a944b 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.1.0 +0.2.0 diff --git a/lib/buildpack.rb b/lib/buildpack.rb index 647fd6d41..0ec3e8211 100644 --- a/lib/buildpack.rb +++ b/lib/buildpack.rb @@ -35,10 +35,10 @@ def self.compiler(build_dir, cache_dir) cache_dir, MonoInstaller.new(build_dir, shell), File.expand_path("../../resources/Nowin.vNext", __FILE__), - KvmInstaller.new(shell), + DnvmInstaller.new(shell), Mozroots.new(shell), - KreInstaller.new(shell), - KPM.new(shell), + DnxInstaller.new(shell), + DNU.new(shell), ReleaseYmlWriter.new, Copier.new, out) diff --git a/lib/buildpack/compile/kre_installer.rb b/lib/buildpack/compile/dnu.rb similarity index 73% rename from lib/buildpack/compile/kre_installer.rb rename to lib/buildpack/compile/dnu.rb index e9832b53b..80e1d4165 100644 --- a/lib/buildpack/compile/kre_installer.rb +++ b/lib/buildpack/compile/dnu.rb @@ -1,6 +1,6 @@ # Encoding: utf-8 # ASP.NET 5 Buildpack -# Copyright 2014-2015 the original author or authors. +# Copyright 2015 the original author or authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -15,13 +15,14 @@ # limitations under the License. module AspNet5Buildpack - class KreInstaller + class DNU def initialize(shell) @shell = shell end - def install(dir, out) - @shell.exec("bash -c 'source #{dir}/.k/kvm/kvm.sh; kvm install 1.0.0-beta3'", out) + def restore(dir, out) + @shell.env['HOME'] = dir + @shell.exec("bash -c 'source #{dir}/.dnx/dnvm/dnvm.sh; dnvm use default -r mono -a x64; cd #{dir}; dnu restore'", out) end end end diff --git a/lib/buildpack/compile/kvm_installer.rb b/lib/buildpack/compile/dnvm_installer.rb similarity index 73% rename from lib/buildpack/compile/kvm_installer.rb rename to lib/buildpack/compile/dnvm_installer.rb index d20b89643..edbce1c2f 100644 --- a/lib/buildpack/compile/kvm_installer.rb +++ b/lib/buildpack/compile/dnvm_installer.rb @@ -1,6 +1,6 @@ # Encoding: utf-8 # ASP.NET 5 Buildpack -# Copyright 2014-2015 the original author or authors. +# Copyright 2015 the original author or authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -15,14 +15,14 @@ # limitations under the License. module AspNet5Buildpack - class KvmInstaller + class DnvmInstaller def initialize(shell) @shell = shell end def install(dir, out) - @shell.env["KRE_USER_HOME"] = File.join(dir, ".k") - @shell.exec("curl -s https://raw.githubusercontent.com/aspnet/Home/master/kvminstall.sh | sh", out) + @shell.env['HOME'] = dir + @shell.exec('touch ~/.bashrc; curl -sSL https://raw.githubusercontent.com/aspnet/Home/dev/dnvminstall.sh | DNX_BRANCH=dev sh; rm -rf ~/.bashrc', out) end end end diff --git a/lib/buildpack/compile/dnx_installer.rb b/lib/buildpack/compile/dnx_installer.rb new file mode 100644 index 000000000..cc53ba3ec --- /dev/null +++ b/lib/buildpack/compile/dnx_installer.rb @@ -0,0 +1,56 @@ +# Encoding: utf-8 +# ASP.NET 5 Buildpack +# Copyright 2015 the original author or authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +require 'json' + +module AspNet5Buildpack + class DnxInstaller + + DNX_VERSION_FILE_NAME = 'global.json'.freeze + DEFAULT_DNX_VERSION = 'latest'.freeze + + def initialize(shell) + @shell = shell + end + + def install(dir, out) + @shell.env['HOME'] = dir + version = dnx_version(dir, out) + @shell.exec("bash -c 'source #{dir}/.dnx/dnvm/dnvm.sh; dnvm install #{version} -p -r mono'", out) + end + + private + + def dnx_version(dir, out) + dnx_version = DEFAULT_DNX_VERSION + version_file = File.expand_path(File.join(dir, DNX_VERSION_FILE_NAME)) + if File.exists?(version_file) + begin + global_props = JSON.parse(File.read(version_file, :encoding => 'bom|utf-8')) + if global_props.has_key?('sdk') + sdk = global_props['sdk'] + if sdk.has_key?('version') + dnx_version = sdk['version'] + end + end + rescue + out.warn("File #{version_file} is not valid JSON") + end + end + dnx_version + end + end +end diff --git a/lib/buildpack/compile/kpm.rb b/lib/buildpack/compile/kpm.rb deleted file mode 100644 index eb6752d4d..000000000 --- a/lib/buildpack/compile/kpm.rb +++ /dev/null @@ -1,28 +0,0 @@ -# Encoding: utf-8 -# ASP.NET 5 Buildpack -# Copyright 2014-2015 the original author or authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -module AspNet5Buildpack - class KPM - def initialize(shell) - @shell = shell - end - - def restore(dir, out) - @shell.env["HOME"] = dir - @shell.exec("bash -c 'source #{dir}/.k/kvm/kvm.sh; kvm install 1.0.0-beta3; for i in $(find -iname project.json -print0 | xargs -0 -n1 dirname); do kpm restore; done'", out) - end - end -end diff --git a/lib/buildpack/compile/mono_installer.rb b/lib/buildpack/compile/mono_installer.rb index e74e346e2..085719142 100644 --- a/lib/buildpack/compile/mono_installer.rb +++ b/lib/buildpack/compile/mono_installer.rb @@ -17,7 +17,8 @@ module AspNet5Buildpack class MonoInstaller - DEFAULT_VERSION = '3.12.1' + # really 4.0.1.44 fix release - needed for mozroots error + DEFAULT_VERSION = '4.0.1' def initialize(app_dir, shell) @app_dir = app_dir @@ -25,6 +26,7 @@ def initialize(app_dir, shell) end def extract(dest_dir, out) + out.print("Mono version: #{version}") run_common_cmd("mkdir -p #{dest_dir}; curl -L `translate_dependency_url #{dependency_name}` -s | tar zxv -C #{dest_dir} &> /dev/null", out) end @@ -39,7 +41,8 @@ def mono_tar_gz(out) private def run_common_cmd(cmd, out) - shell.exec("bash -c 'export BUILDPACK_PATH=#{buildpack_root}; source $BUILDPACK_PATH/compile-extensions/lib/common &> /dev/null; #{cmd}'", out) + commoncmd = "bash -c 'export BUILDPACK_PATH=#{buildpack_root}; source $BUILDPACK_PATH/compile-extensions/lib/common &> /dev/null; #{cmd}'" + shell.exec(commoncmd, out) end def buildpack_root diff --git a/lib/buildpack/compile/release_yml_writer.rb b/lib/buildpack/compile/release_yml_writer.rb index 7cb7a7b48..80057136f 100644 --- a/lib/buildpack/compile/release_yml_writer.rb +++ b/lib/buildpack/compile/release_yml_writer.rb @@ -14,7 +14,8 @@ # See the License for the specific language governing permissions and # limitations under the License. -require "fileutils" +require 'fileutils' +require 'json' module AspNet5Buildpack class ReleaseYmlWriter @@ -42,12 +43,12 @@ def write_yml(dirs) end def add_cfweb_command(project_json) - json = JSON.parse(IO.read(project_json)) + json = JSON.parse(IO.read(project_json, :encoding => 'bom|utf-8')) json["dependencies"] ||= {} json["dependencies"]["Nowin.vNext"] = "1.0.0-*" unless json["dependencies"]["Nowin.vNext"] json["commands"] ||= {} json["commands"]["cf-web"] = "Microsoft.AspNet.Hosting --server Nowin.vNext" - IO.write(project_json, json.to_json) + IO.write(project_json, JSON.pretty_generate(json)) end def write_startup_script(path) @@ -55,7 +56,9 @@ def write_startup_script(path) File.open(path, 'w') do |f| f.write "export PATH=/app/mono/bin:$PATH;" f.write "export HOME=/app;" - f.write "source /app/.k/kvm/kvm.sh; kvm use 1.0.0-beta3;" + f.write "source /app/.dnx/dnvm/dnvm.sh;" + f.write "dnvm use default -r mono -a x64;" + f.write "dnu restore;" end end @@ -64,7 +67,7 @@ def write_yml_for(ymlPath, web_dir, cmd) f.write < 'bom|utf-8')).fetch("commands", {}) end def project_json(dir) diff --git a/lib/buildpack/compiler.rb b/lib/buildpack/compiler.rb index 53397c170..d112ab3b7 100644 --- a/lib/buildpack/compiler.rb +++ b/lib/buildpack/compiler.rb @@ -16,9 +16,9 @@ require_relative 'compile/mozroots.rb' require_relative 'compile/mono_installer.rb' -require_relative 'compile/kre_installer.rb' -require_relative 'compile/kvm_installer.rb' -require_relative 'compile/kpm.rb' +require_relative 'compile/dnvm_installer.rb' +require_relative 'compile/dnx_installer.rb' +require_relative 'compile/dnu.rb' require_relative 'compile/release_yml_writer.rb' require_relative "version.rb" @@ -27,17 +27,17 @@ module AspNet5Buildpack class Compiler - WARNING_MESSAGE = "This is an experimental buildpack. It is not supported. Do not expect it to work reliably. Please, do not contact support about issues with this buildpack." + WARNING_MESSAGE = "This is an experimental buildpack. It is not supported. Do not expect it to work reliably. Please, do not contact support about issues with this buildpack.".freeze - def initialize(build_dir, cache_dir, mono_binary, nowin_dir, kvm_installer, mozroots, kre_installer, kpm, release_yml_writer, copier, out) + def initialize(build_dir, cache_dir, mono_binary, nowin_dir, dnvm_installer, mozroots, dnx_installer, dnu, release_yml_writer, copier, out) @build_dir = build_dir @cache_dir = cache_dir @mono_binary = mono_binary @nowin_dir = nowin_dir - @kvm_installer = kvm_installer - @kre_installer = kre_installer + @dnvm_installer = dnvm_installer + @dnx_installer = dnx_installer @mozroots = mozroots - @kpm = kpm + @dnu = dnu @release_yml_writer = release_yml_writer @copier = copier @out = out @@ -51,9 +51,9 @@ def compile step("Extracting mono", method(:extract_mono)) step("Adding Nowin.vNext", method(:copy_nowin)) step("Importing Mozilla Root Certificates", method(:install_mozroot_certs)) - step("Installing KVM", method(:install_kvm)) - step("Installing KRE with KVM", method(:install_kre)) - step("Restoring dependencies with KPM", method(:restore_dependencies)) + step("Installing DNVM", method(:install_dnvm)) + step("Installing DNX with DNVM", method(:install_dnx)) + step("Restoring dependencies with DNU", method(:restore_dependencies)) step("Moving files in to place", method(:move_to_app_dir)) step("Saving to buildpack cache", method(:save_cache)) step("Writing Release YML", method(:write_release_yml)) @@ -83,20 +83,20 @@ def install_mozroot_certs(out) end def restore_cache(out) - copier.cp(File.join(cache_dir, ".k"), build_dir, out) if File.exist? File.join(cache_dir, ".k") + 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") end - def install_kvm(out) - kvm_installer.install(build_dir, out) + def install_dnvm(out) + dnvm_installer.install(build_dir, out) end - def install_kre(out) - kre_installer.install(build_dir, out) + def install_dnx(out) + dnx_installer.install(build_dir, out) end def restore_dependencies(out) - kpm.restore(build_dir, out) + dnu.restore(build_dir, out) end def move_to_app_dir(out) @@ -104,7 +104,7 @@ def move_to_app_dir(out) end def save_cache(out) - copier.cp(File.join(build_dir, ".k"), cache_dir, 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") end @@ -128,10 +128,10 @@ def step(description, method) attr_reader :cache_dir attr_reader :mono_binary attr_reader :nowin_dir - attr_reader :kvm_installer - attr_reader :kre_installer + attr_reader :dnvm_installer + attr_reader :dnx_installer attr_reader :mozroots - attr_reader :kpm + attr_reader :dnu attr_reader :release_yml_writer attr_reader :copier attr_reader :out diff --git a/lib/buildpack/copier.rb b/lib/buildpack/copier.rb index aa9de1c80..d89bbe0e4 100644 --- a/lib/buildpack/copier.rb +++ b/lib/buildpack/copier.rb @@ -20,6 +20,7 @@ module AspNet5Buildpack class Copier def cp(from, to, out) before = files_in_dest(to) + FileUtils.mkdir_p(to) FileUtils.cp_r(from, to) after = files_in_dest(to) diff --git a/manifest.yml b/manifest.yml index 168d92069..a8fb45024 100644 --- a/manifest.yml +++ b/manifest.yml @@ -8,17 +8,17 @@ url_to_dependency_map: dependencies: - name: mono - version: 3.12.1 + version: 4.0.1 cf_stacks: - lucid64 - uri: https://github.com/cloudfoundry-community/asp.net5-buildpack/releases/download/v0.1/mono-lucid64-3.12.1.tar.gz - md5: 386e88cadea67669e7731d4238cefb53 + uri: https://github.com/cloudfoundry-community/asp.net5-buildpack/releases/download/v0.2/mono-lucid64-4.0.1.tar.gz + md5: 3d020ca4a4bc2afd6e803eeb18ff5551 - name: mono - version: 3.12.1 + version: 4.0.1 cf_stacks: - cflinuxfs2 - uri: https://github.com/cloudfoundry-community/asp.net5-buildpack/releases/download/v0.1/mono-cflinuxfs2-3.12.1.tar.gz - md5: 7f992e9d13c608487937988b465be19a + uri: https://github.com/cloudfoundry-community/asp.net5-buildpack/releases/download/v0.2/mono-cflinuxfs2-4.0.1.tar.gz + md5: 98de7244bd6a91ea4d0acc9104b82a59 exclude_files: - .git/ diff --git a/resources/Nowin.vNext/NowinServerFactory.cs b/resources/Nowin.vNext/NowinServerFactory.cs index 4117cf37c..270054be7 100644 --- a/resources/Nowin.vNext/NowinServerFactory.cs +++ b/resources/Nowin.vNext/NowinServerFactory.cs @@ -18,15 +18,17 @@ using System.Net; using System.Threading.Tasks; using Microsoft.AspNet.Builder; +using Microsoft.AspNet.FeatureModel; using Microsoft.AspNet.Hosting.Server; using Microsoft.AspNet.Owin; using Microsoft.Framework.ConfigurationModel; +using Nowin; namespace Nowin.vNext { public class NowinServerFactory : IServerFactory { - private Func _callback; + private Func _callback; private Task HandleRequest(IDictionary env) { @@ -44,7 +46,7 @@ public IServerInformation Initialize(IConfiguration configuration) return new NowinServerInformation(builder); } - public IDisposable Start(IServerInformation serverInformation, Func application) + public IDisposable Start(IServerInformation serverInformation, Func application) { var information = (NowinServerInformation)serverInformation; _callback = application; diff --git a/resources/Nowin.vNext/project.json b/resources/Nowin.vNext/project.json index 06114f4e0..3568d1096 100644 --- a/resources/Nowin.vNext/project.json +++ b/resources/Nowin.vNext/project.json @@ -2,7 +2,11 @@ "version": "1.0.0-*", "dependencies": { "Nowin": "0.11.0", - "Microsoft.AspNet.Owin": "1.0.0-beta3", - "Microsoft.AspNet.Hosting": "1.0.0-beta3" + "Microsoft.AspNet.Owin": "1.0.0-beta4", + "Microsoft.AspNet.Hosting": "1.0.0-beta4" + }, + "frameworks": { + "dnx451": { }, + "dnxcore50": { } } -} \ No newline at end of file +} diff --git a/spec/buildpack/compile/compile_spec.rb b/spec/buildpack/compile/compile_spec.rb index 4bb51f779..caef3900a 100644 --- a/spec/buildpack/compile/compile_spec.rb +++ b/spec/buildpack/compile/compile_spec.rb @@ -21,7 +21,7 @@ describe AspNet5Buildpack::Compiler do subject(:compiler) do - AspNet5Buildpack::Compiler.new(buildDir, cacheDir, mono_binary, nowinDir, kvm_installer, mozroots, kre_installer, kpm, release_yml_writer, copier, out) + AspNet5Buildpack::Compiler.new(buildDir, cacheDir, mono_binary, nowinDir, dnvm_installer, mozroots, dnx_installer, dnu, release_yml_writer, copier, out) end before do @@ -36,16 +36,16 @@ double(:copier, :cp => nil) end - let(:kvm_installer) do - double(:kvm_installer, :install => nil) + let(:dnvm_installer) do + double(:dnvm_installer, :install => nil) end - let(:kre_installer) do - double(:kre_installer, :install => nil) + let(:dnx_installer) do + double(:dnx_installer, :install => nil) end - let(:kpm) do - double(:kpm, :restore => nil) + let(:dnu) do + double(:dnu, :restore => nil) end let(:mozroots) do @@ -132,7 +132,7 @@ end context "when mono is already extracted because it was cached" do - it "copies only .k to cache dir" do + it "copies only .dnx to cache dir" do allow(File).to receive(:exist?).and_return(true) expect(mono_binary).not_to receive(:extract).with("/app", anything) compiler.compile @@ -150,7 +150,7 @@ end describe "Importing Certificates" do - it_behaves_like "A Step", "Importing Mozilla Root Certificates", :install_mozroot_certs, :install_kvm + it_behaves_like "A Step", "Importing Mozilla Root Certificates", :install_mozroot_certs, :install_dnvm it "imports the certificates" do expect(mozroots).to receive(:import) @@ -158,17 +158,17 @@ end end - describe "Installing KVM" do - it_behaves_like "A Step", "Installing KVM", :install_kvm, :install_kre + describe "Installing DNVM" do + it_behaves_like "A Step", "Installing DNVM", :install_dnvm, :install_dnx - it "installs kvm" do - expect(kvm_installer).to receive(:install).with(buildDir, anything) + it "installs dnvm" do + expect(dnvm_installer).to receive(:install).with(buildDir, anything) compiler.compile end end describe "Restoring Cache" do - it_behaves_like "A Step", "Restoring files from buildpack cache", :restore_cache, :install_kvm + it_behaves_like "A Step", "Restoring files from buildpack cache", :restore_cache, :install_dnvm context "when the cache does not exist" do it "does not try copying" do @@ -179,23 +179,23 @@ context "when the cache exists" do before(:each) do - Dir.mkdir(File.join(cacheDir, ".k")) + Dir.mkdir(File.join(cacheDir, ".dnx")) Dir.mkdir(File.join(cacheDir, "mono")) end it "restores all files from the cache to build dir" do - expect(copier).to receive(:cp).with(File.join(cacheDir, ".k"), buildDir, anything) + expect(copier).to receive(:cp).with(File.join(cacheDir, ".dnx"), buildDir, anything) expect(copier).to receive(:cp).with(File.join(cacheDir, "mono"), "/app", anything) compiler.compile end end end - describe "Installing KRE with KVM" do - it_behaves_like "A Step", "Installing KRE with KVM", :install_kre, :restore_dependencies + describe "Installing DNX with DNVM" do + it_behaves_like "A Step", "Installing DNX with DNVM", :install_dnx, :restore_dependencies - it "installs kre" do - expect(kre_installer).to receive(:install).with(buildDir, anything) + it "installs dnx" do + expect(dnx_installer).to receive(:install).with(buildDir, anything) compiler.compile end end @@ -212,8 +212,8 @@ describe "Saving to buildpack cache" do it_behaves_like "A Step", "Saving to buildpack cache", :save_cache, :write_release_yml - it "copies .k and mono to cache dir" do - expect(copier).to receive(:cp).with("#{buildDir}/.k", cacheDir, anything) + it "copies .dnx and mono to cache dir" do + expect(copier).to receive(:cp).with("#{buildDir}/.dnx", cacheDir, anything) expect(copier).to receive(:cp).with("/app/mono", cacheDir, anything) compiler.compile end @@ -222,8 +222,8 @@ before(:each) do Dir.mkdir(File.join(cacheDir, "mono")) end - it "copies only .k to cache dir" do - expect(copier).to receive(:cp).with("#{buildDir}/.k", cacheDir, anything) + it "copies only .dnx to cache dir" do + expect(copier).to receive(:cp).with("#{buildDir}/.dnx", cacheDir, anything) compiler.compile end end diff --git a/spec/buildpack/compile/kpm_spec.rb b/spec/buildpack/compile/dnu_spec.rb similarity index 61% rename from spec/buildpack/compile/kpm_spec.rb rename to spec/buildpack/compile/dnu_spec.rb index b2b541508..db627a118 100644 --- a/spec/buildpack/compile/kpm_spec.rb +++ b/spec/buildpack/compile/dnu_spec.rb @@ -17,7 +17,7 @@ require "rspec" require_relative "../../../lib/buildpack.rb" -describe AspNet5Buildpack::KPM do +describe AspNet5Buildpack::DNU do let(:shell) do double(:shell, :env => {}) end @@ -26,32 +26,32 @@ double(:out) end - subject(:kpm) do - AspNet5Buildpack::KPM.new(shell) + subject(:dnu) do + AspNet5Buildpack::DNU.new(shell) end - it "sets HOME env variable to build dir so that .kpm packages are stored in /app/.kpm" do + it "sets HOME env variable to build dir so that packages are stored in /app/.dnx" do allow(shell).to receive(:exec) - kpm.restore("app-dir", out) + dnu.restore("app-dir", out) expect(shell.env).to include("HOME" => "app-dir") end - it "adds kpm to the PATH" do + it "adds dnu to the PATH" do allow(shell).to receive(:exec) - expect(shell).to receive(:exec).with(match("kvm install"), out) - kpm.restore("app-dir", out) + expect(shell).to receive(:exec).with(match("dnvm use default"), out) + dnu.restore("app-dir", out) end - it "sources /kvm.sh script" do + it "sources dnvm.sh script" do allow(shell).to receive(:exec) - expect(shell).to receive(:exec).with(match("bash -c 'source app-dir/.k/kvm/kvm.sh"), out) - kpm.restore("app-dir", out) + expect(shell).to receive(:exec).with(match("source app-dir/.dnx/dnvm/dnvm.sh"), out) + dnu.restore("app-dir", out) end - it "restores dependencies with kpm" do + it "restores dependencies with dnu" do allow(shell).to receive(:exec) - expect(shell).to receive(:exec).with(match("kpm restore"), out) - kpm.restore("app-dir", out) + expect(shell).to receive(:exec).with(match("dnu restore"), out) + dnu.restore("app-dir", out) end end diff --git a/spec/buildpack/compile/dnvm_installer_spec.rb b/spec/buildpack/compile/dnvm_installer_spec.rb new file mode 100644 index 000000000..3db5bd135 --- /dev/null +++ b/spec/buildpack/compile/dnvm_installer_spec.rb @@ -0,0 +1,54 @@ +# Encoding: utf-8 +# ASP.NET 5 Buildpack +# Copyright 2014-2015 the original author or authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +require 'rspec' +require_relative '../../../lib/buildpack.rb' + +describe AspNet5Buildpack::DnvmInstaller do + let(:shell) do + double(:shell, :env => {}) + end + + let(:out) do + double(:out) + end + + subject(:installer) do + AspNet5Buildpack::DnvmInstaller.new(shell) + end + + it 'creates .bashrc so dnvminstall.sh does not complain' do + expect(shell).to receive(:exec).with(match('touch ~/.bashrc'), out) + installer.install('passed-directory', out) + end + + it 'runs the dnvm web installer' do + expect(shell).to receive(:exec).with(match('curl -sSL https://raw.githubusercontent.com/aspnet/Home/dev/dnvminstall.sh | DNX_BRANCH=dev sh'), out) + installer.install('passed-directory', out) + end + + it 'deletes .bashrc because dnvminstall.sh updated it with temporary paths' do + expect(shell).to receive(:exec).with(match('rm -rf ~/.bashrc'), out) + installer.install('passed-directory', out) + end + + it 'sets HOME based on passed directory' do + allow(shell).to receive(:exec) + installer.install('passed-directory', out) + + expect(shell.env).to include('HOME' => 'passed-directory') + end +end diff --git a/spec/buildpack/compile/dnx_install_spec.rb b/spec/buildpack/compile/dnx_install_spec.rb new file mode 100644 index 000000000..6818272ac --- /dev/null +++ b/spec/buildpack/compile/dnx_install_spec.rb @@ -0,0 +1,108 @@ +# Encoding: utf-8 +# ASP.NET 5 Buildpack +# Copyright 2014-2015 the original author or authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +require 'rspec' +require 'tmpdir' +require_relative '../../../lib/buildpack.rb' + +describe AspNet5Buildpack::DnxInstaller do + let(:shell) do + double(:shell, :env => {}) + end + + let(:out) do + double(:out) + end + + let(:dir) do + Dir.mktmpdir + end + + subject(:installer) do + AspNet5Buildpack::DnxInstaller.new(shell) + end + + it 'sets HOME env variable to build dir so that runtimes are stored in /app/.dnx' do + allow(shell).to receive(:exec) + installer.install(dir, out) + expect(shell.env).to include('HOME' => dir) + 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) + installer.install(dir, out) + end + + describe 'dnvm installer' do + context 'global.json does not exist' do + it 'installs the latest version' do + allow(shell).to receive(:exec) + expect(shell).to receive(:exec).with(match('dnvm install latest -p -r mono'), out) + installer.install(dir, out) + end + end + + context 'global.json exists' do + before do + json = '{ "sdk": { "version": "1.0.0-beta1" } }' + IO.write(File.join(dir, 'global.json'), json) + end + it 'installs the specified version' do + allow(shell).to receive(:exec) + expect(shell).to receive(:exec).with(match('dnvm install 1.0.0-beta1 -p -r mono'), out) + installer.install(dir, out) + end + end + + context 'global.json exists with a BOM from Visual Studio in it' do + before do + json = "\uFEFF{ \"sdk\": { \"version\": \"1.0.0-beta1\" } }" + IO.write(File.join(dir, 'global.json'), json) + end + it 'installs the specified version' do + allow(shell).to receive(:exec) + expect(shell).to receive(:exec).with(match('dnvm install 1.0.0-beta1 -p -r mono'), out) + installer.install(dir, out) + end + end + + context 'invalid global.json exists' do + before do + json = '"version": "1.0.0-beta1"' + IO.write(File.join(dir, 'global.json'), json) + end + it 'warns and installs the latest version' do + allow(shell).to receive(:exec) + expect(shell).to receive(:exec).with(match('dnvm install latest -p -r mono'), out) + expect(out).to receive(:warn).with("File #{dir}/global.json is not valid JSON") + installer.install(dir, out) + end + end + + context 'global.json exists but does not include a version' do + before do + json = '{ "projects": [ "src", "test" ] }' + IO.write(File.join(dir, 'global.json'), json) + end + it 'installs the latest version' do + allow(shell).to receive(:exec) + expect(shell).to receive(:exec).with(match('dnvm install latest -p -r mono'), out) + installer.install(dir, out) + end + end + end +end diff --git a/spec/buildpack/compile/kre_install_spec.rb b/spec/buildpack/compile/kre_install_spec.rb deleted file mode 100644 index fc3eea55b..000000000 --- a/spec/buildpack/compile/kre_install_spec.rb +++ /dev/null @@ -1,42 +0,0 @@ -# Encoding: utf-8 -# ASP.NET 5 Buildpack -# Copyright 2014-2015 the original author or authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -require "rspec" -require_relative "../../../lib/buildpack.rb" - -describe AspNet5Buildpack::KreInstaller do - let(:shell) do - double(:shell, :exec => nil) - end - - let(:out) do - double(:out) - end - - subject(:installer) do - AspNet5Buildpack::KreInstaller.new(shell) - end - - it "sources the kvm script" do - expect(shell).to receive(:exec).with(match("^bash -c 'source the-app-dir/.k/kvm/kvm.sh"), out) - installer.install("the-app-dir", out) - end - - it "runs the kvm web installer" do - expect(shell).to receive(:exec).with(match("kvm install 1.0.0-beta3"), out) - installer.install("the-app-dir", out) - end -end diff --git a/spec/buildpack/compile/kvm_installer_spec.rb b/spec/buildpack/compile/kvm_installer_spec.rb deleted file mode 100644 index 00f075014..000000000 --- a/spec/buildpack/compile/kvm_installer_spec.rb +++ /dev/null @@ -1,44 +0,0 @@ -# Encoding: utf-8 -# ASP.NET 5 Buildpack -# Copyright 2014-2015 the original author or authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -require "rspec" -require_relative "../../../lib/buildpack.rb" - -describe AspNet5Buildpack::KvmInstaller do - let(:shell) do - double(:shell, :env => {}) - end - - let(:out) do - double(:out) - end - - subject(:installer) do - AspNet5Buildpack::KvmInstaller.new(shell) - end - - it "runs the kvm web installer" do - expect(shell).to receive(:exec).with("curl -s https://raw.githubusercontent.com/aspnet/Home/master/kvminstall.sh | sh", out) - installer.install("passed-directory", out) - end - - it "sets KRE_USER_HOME based on passed directory" do - allow(shell).to receive(:exec) - installer.install("passed-directory", out) - - expect(shell.env).to include("KRE_USER_HOME" => File.join("passed-directory",".k")) - end -end diff --git a/spec/buildpack/compile/mono_installer_spec.rb b/spec/buildpack/compile/mono_installer_spec.rb index 88b08e967..a7b6b05f5 100644 --- a/spec/buildpack/compile/mono_installer_spec.rb +++ b/spec/buildpack/compile/mono_installer_spec.rb @@ -41,7 +41,7 @@ describe "mono version" do context "when no version is specified" do it "uses default version" do - expect(subject.version).to eq('3.12.1') + expect(subject.version).to eq('4.0.1') end end @@ -99,6 +99,7 @@ expect(cmd).to match(/translate_dependency_url/) expect(cmd).to match(/tar/) end + expect(out).to receive(:print).with(/Mono version/) subject.extract(dir, out) end end diff --git a/spec/buildpack/compile/release_yml_writer_spec.rb b/spec/buildpack/compile/release_yml_writer_spec.rb index efa7d7cae..9c6fc3df1 100644 --- a/spec/buildpack/compile/release_yml_writer_spec.rb +++ b/spec/buildpack/compile/release_yml_writer_spec.rb @@ -49,16 +49,24 @@ File.join(buildDir, "foo").tap { |f| Dir.mkdir(f) } end - it "should add /app/mono/bin to the path" do + it "should add /app/mono/bin to the PATH" do expect(profile_d_script).to include("export PATH=/app/mono/bin:$PATH;") end - it "should set HOME to /app (so that dependencies are picked up from /app/.kre etc" do + it "should set HOME to /app (so that dependencies are picked up from /app/.dnx)" do expect(profile_d_script).to include("export HOME=/app") end - it "should source kvm script" do - expect(profile_d_script).to include("source /app/.k/kvm/kvm.sh") + it "should source dnvm script" do + expect(profile_d_script).to include("source /app/.dnx/dnvm/dnvm.sh") + end + + it "should add the runtime to the PATH" do + expect(profile_d_script).to include("dnvm use default") + end + + it "should re-run package restore" do + expect(profile_d_script).to include("dnu restore") end end @@ -75,6 +83,28 @@ end end + context "when there is a directory with a project.json file containing a BOM" do + let(:web_dir) do + File.join(buildDir, "foo").tap { |f| Dir.mkdir(f) } + end + + let(:project_json) do + "{}" + end + + before do + File.open(File.join(web_dir, "project.json"), 'w') do |f| + f.write "\uFEFF" + f.write project_json + end + end + + it "writes a release yml" do + subject.write_release_yml(buildDir, out) + expect(File).to exist(File.join(buildDir, "aspnet5-buildpack-release.yml")) + end + end + context "when there is a directory with a project.json file" do let(:web_dir) do File.join(buildDir, "foo").tap { |f| Dir.mkdir(f) } @@ -114,8 +144,8 @@ expect(web_process).to match("cd foo;") end - it "runs 'k cf-web'" do - expect(web_process).to match("k cf-web") + it "runs 'dnx . cf-web'" do + expect(web_process).to match("dnx . cf-web") end context "and if the cf-web command is empty" do @@ -192,8 +222,8 @@ expect(web_process).to match("cd foo-cfweb;") end - it "runs 'k cf-web'" do - expect(web_process).to match("k cf-web") + it "runs 'dnx . cf-web'" do + expect(web_process).to match("dnx . cf-web") end end @@ -212,8 +242,8 @@ expect(web_process).to match("cd foo-cfweb;") end - it "runs 'k cf-web'" do - expect(web_process).to match("k cf-web") + it "runs 'dnx . cf-web'" do + expect(web_process).to match("dnx . cf-web") end end @@ -236,8 +266,8 @@ expect(web_process).to match("cd foo-cfweb;") end - it "runs 'k cf-web'" do - expect(web_process).to match("k cf-web") + it "runs 'dnx . cf-web'" do + expect(web_process).to match("dnx . cf-web") end end end diff --git a/spec/buildpack/copier_spec.rb b/spec/buildpack/copier_spec.rb index cfa3156b9..fdfa99344 100644 --- a/spec/buildpack/copier_spec.rb +++ b/spec/buildpack/copier_spec.rb @@ -16,6 +16,7 @@ require 'rspec' require 'tmpdir' +require_relative "../../lib/buildpack.rb" describe AspNet5Buildpack::Copier do let(:src) do