Commit 1f81d0f5 authored by Matt Wrock's avatar Matt Wrock
Browse files

revert back to install.ps1 instead of direct nupkg and use...

revert back to install.ps1 instead of direct nupkg and use chocolateyProxyLocation variable to set proxy
parent b44574df
# Changelog for Chocolatey cookbook
### Unreleased
* Refactored install script (and .kitchen.yml) to support installing Chocolatey
in test-kitchen behind a proxy.
* Remove `node['chocolatey']['Uri']` attribute. Instead, install by downloading
the chocolatey.nupkg directly via Chef's `remote_file` resource. This lets users
install via Chef client.rb proxy settings instead of inheriting Internet Explorer
proxy settings.
### v0.5.0 (2015-11-06)
* Refactored install script (and .kitchen.yml) to support installing Chocolatey in test-kitchen behind a proxy.
* Download `node['chocolatey']['Uri']` via `remote_file` resource instead of .net web client
* Set `chocolateyProxyLocation` environment variable to `Chef::Config['https_proxy']` if one is set before chocolatey install
* Changed helpers module namespacing from: `ChocolateyHelpers` to `Chocolatey::Helpers`
* Add ChefSpec unit tests
* Add ServerSpec integration tests
......
......@@ -26,7 +26,7 @@ More information can be gotten from the [Chocolateywiki](https://github.com/choc
# Attributes
* `node['chocolatey']['nupkg']['url']` - Defaults to `'https://chocolatey.org/api/v2/package/chocolatey/'`
* `node['chocolatey']['url']` - Defaults to `'https://chocolatey.org/install.ps1'`
* `node['chocolatey']['upgrade']` - Defaults to `true`.
# Recipes
......
default['chocolatey']['nupkg']['url'] = 'https://chocolatey.org/api/v2/package/chocolatey/'
default['chocolatey']['url'] = 'https://chocolatey.org/install.ps1'
default['chocolatey']['upgrade'] = true
......@@ -4,7 +4,7 @@ maintainer_email 'guilhem.lettron@youscribe.com'
license 'Apache 2.0'
description 'Install chocolatey and packages on Windows'
long_description 'Installs the Chocolatey package manager for Windows and provides a Chef resource for installing nuget packages from https://chocolatey.org/'
version '0.4.1'
version '1.0.0'
source_url 'https://github.com/chocolatey/chocolatey-cookbook'
issues_url 'https://github.com/chocolatey/chocolatey-cookbook/issues'
......
......@@ -22,40 +22,27 @@ unless node['platform_family'] == 'windows'
return "Chocolatey install not supported on #{node['platform_family']}"
end
Chef::Resource::RubyBlock.send(:include, Chocolatey::Helpers)
Chef::Resource::RemoteFile.send(:include, Chocolatey::Helpers)
Chef::Resource.send(:include, Chocolatey::Helpers)
NUGET_PKG = 'chocolatey.nupkg'
nuget_package_path = File.join(Chef::Config['file_cache_path'], NUGET_PKG)
extract_dir = File.join(ENV['TEMP'], 'chocolatey')
install_ps1 = File.join(Chef::Config['file_cache_path'], 'install.ps1')
install_ps1 = File.join(extract_dir, 'tools', 'chocolateyInstall.ps1')
remote_file nuget_package_path do
source node['chocolatey']['nupkg']['url']
remote_file install_ps1 do
source node['chocolatey']['url']
backup false
notifies :unzip, "windows_zipfile[#{extract_dir}]", :immediately
notifies :run, 'ruby_block[set proxy]', :immediately
notifies :run, 'powershell_script[Install Chocolatey]', :immediately
notifies :run, 'ruby_block[Ensure chocolatey.nupkg is in chocolatey/lib/chocolatey/]', :immediately
not_if { chocolatey_installed? && (node['chocolatey']['upgrade'] == false) }
end
windows_zipfile extract_dir do
ruby_block 'set proxy' do
action :nothing
source nuget_package_path
overwrite true
block do
ENV['chocolateyProxyLocation'] = Chef::Config['https_proxy'] if Chef::Config['https_proxy']
end
end
powershell_script 'Install Chocolatey' do
action :nothing
cwd File.join(extract_dir, 'tools')
cwd Chef::Config['file_cache_path']
code install_ps1
end
ruby_block 'Ensure chocolatey.nupkg is in chocolatey/lib/chocolatey/' do
action :nothing
block do
require 'fileutils'
FileUtils.cp(nuget_package_path, chocolatey_lib_dir)
end
end
......@@ -3,7 +3,6 @@ RSpec.describe 'chocolatey::default' do
cached(:windows_node) do
# use call original as per http://www.relishapp.com/rspec/rspec-mocks/v/3-3/docs/configuring-responses/calling-the-original-implementation#%60and-call-original%60-can-configure-a-default-response-that-can-be-overriden-for-specific-args
allow(ENV).to receive(:[]).and_call_original
allow(ENV).to receive(:[]).with('TEMP').and_return('c:/windows/temp')
allow(ENV).to receive(:fetch).with('ChocolateyInstall').and_return('C:\ProgramData\chocolatey')
ChefSpec::SoloRunner.new(
......@@ -11,63 +10,43 @@ RSpec.describe 'chocolatey::default' do
).converge(described_recipe)
end
let(:nuget_package_path) do
let(:install_ps1) do
File.join(
Chef::Config['file_cache_path'], 'chocolatey.nupkg'
Chef::Config['file_cache_path'], 'install.ps1'
)
end
let(:downloaded_package) { windows_node.remote_file(nuget_package_path) }
let(:extract_dir) { 'c:/windows/temp/chocolatey' }
let(:windows_zipfile) { windows_node.windows_zipfile(extract_dir) }
let(:downloaded_package) { windows_node.remote_file(install_ps1) }
let(:powershell_script) { windows_node.powershell_script('Install Chocolatey') }
let(:ruby_block) { windows_node.ruby_block('Ensure chocolatey.nupkg is in chocolatey/lib/chocolatey/') }
let(:ruby_block) { windows_node.ruby_block('set proxy') }
it 'Downloads the latest chocolatey.nupkg to the file_cache_path' do
expect(windows_node).to create_remote_file(nuget_package_path).with(
source: 'https://chocolatey.org/api/v2/package/chocolatey/',
it 'Downloads the chocolatey install.ps1 to the file_cache_path' do
expect(windows_node).to create_remote_file(install_ps1).with(
source: 'https://chocolatey.org/install.ps1',
backup: false
)
end
it 'remote_file notifies windows_zipfile to unzip the downloaded Chocolatey package' do
expect(downloaded_package).to notify("windows_zipfile[#{extract_dir}]").to(:unzip).immediately
end
it 'remote_file notifies powershell_script to run the Chocolatey install script' do
expect(downloaded_package).to notify('powershell_script[Install Chocolatey]').to(:run).immediately
end
it 'remote_file notifies ruby_block to mv chocolatey.nupkg to lib/chocolatey/' do
it 'remote_file notifies ruby_block to set chocolatey proxy variables' do
expect(downloaded_package).to notify(
'ruby_block[Ensure chocolatey.nupkg is in chocolatey/lib/chocolatey/]'
'ruby_block[set proxy]'
).to(:run).immediately
end
it 'windows_zipfile does not unzip the Chocolatey package unless notified' do
expect(windows_zipfile).to do_nothing
end
it 'windows_zipfile overwrites the extract directory' do
expect(windows_zipfile.overwrite).to eql(true)
end
it "windows_zipfile extracts from Chef's file_cache_path to %TEMP%/chocolatey directory" do
expect(windows_zipfile.source).to eq('c:/chef/cache/chocolatey.nupkg')
expect(windows_zipfile.path).to eq('c:/windows/temp/chocolatey')
end
it 'powershell_script does not install Chocolatey unless a new chocolatey.nupkg has been downloaded' do
it 'powershell_script does not install Chocolatey unless a new install.ps1 has been downloaded' do
expect(powershell_script).to do_nothing
end
it 'runs the chocolateyInstall.ps1 script from the extracted Chocolatey tools directory' do
expect(powershell_script.cwd).to eq('c:/windows/temp/chocolatey/tools')
expect(powershell_script.code).to eq('c:/windows/temp/chocolatey/tools/chocolateyInstall.ps1')
it 'runs the install.ps1 script from the chef file cache directory' do
expect(powershell_script.cwd).to eq('c:/chef/cache')
expect(powershell_script.code).to eq('c:/chef/cache/install.ps1')
end
it 'ruby_block does not run chocolatey.nupkg file mv unless notified' do
it 'ruby_block does not set proxy unless notified' do
expect(ruby_block).to do_nothing
end
end
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment