Skip to content
Open
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@ bin/*

.kitchen/
.kitchen.local.yml

.idea
46 changes: 46 additions & 0 deletions .kitchen.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
---
driver:
name: vagrant

provisioner:
name: chef_zero
require_chef_omnibus: latest

platforms:
- name: mac_osx_elcapitan
os_type: mac_os_x
driver:
provision: true
network:
- ["private_network", {ip: "192.168.33.33"}]
gui: false
box: jhcook/osx-elcapitan-10.11

suites:
- name: xcode_dmg_installer
run_list:
- recipe[xcode_test::default]
attributes:
xcode:
url: "http://192.168.33.1/Xcode_7.3.1.dmg"
checksum: "bb0dedf613e86ecb46ced945913fa5069ab716a0ade1035e239d70dee0b2de1b"
last_gm_license: "EA1327"
version: "7.3.1"
cli:
url: "http://192.168.33.1/Command_Line_Tools_OS_X_10.11_for_Xcode_7.3.1.dmg"
checksum: "0c80753d207fa2254bcc1c880d4d8907071241f3f2e092c7caa87e340245835a"
package_name: "Command Line Tools (OS X 10.11)"

- name: xcode_xip_archive
run_list:
- recipe[xcode_test::default]
attributes:
xcode:
url: "http://192.168.33.1/Xcode_8.1.xip"
checksum: "30378e76f7d1adcf3573fc990bd7b46e0939b466b83338ba8f4290444462e5da"
last_gm_license: "8B62"
version: "8.1"
cli:
url: "http://192.168.33.1/Command_Line_Tools_macOS_10.12_for_Xcode_8.1.dmg"
checksum: "d1697a3f76a1241f32793dee24166415dd64bfbac07dbbf84b02b0b59bf713c5"
package_name: "Command Line Tools (macOS 10.12)"
2 changes: 2 additions & 0 deletions Berksfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
source 'https://supermarket.chef.io'

metadata

cookbook 'xcode_test', path: 'test/fixtures/cookbooks/xcode_test', group: 'test'
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,23 @@ Just include `xcode` in your node's `run_list` and set the attributes above.
}
```

Test
----
Prerequisites:
- HTTP server which provides `Xcode` installers.
If the host machine has installed python, just run in the directory where `Xcode` installers are:
```
python -m SimpleHTTPServer 80
```
- Vagrant 1.8.6
- VirtualBox 5.1.10 + ExtensionPack
- ChefDK latest

This cookbook use the test-kitchen tool for developing infrastructure code. To verify cookbook execute command in terminal
```
kitchen test
```

Bugs
----

Expand Down
2 changes: 2 additions & 0 deletions metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@
long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
version '1.3.1'
supports 'mac_os_x'

depends 'dmg'
depends 'homebrew'
97 changes: 89 additions & 8 deletions recipes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,93 @@
# limitations under the License.
#

dmg_package "Xcode" do
source node['xcode']['url']
checksum node['xcode']['checksum']
action :install
file_basename = ::File.basename(node['xcode']['url'])
installer_path = "#{Chef::Config[:file_cache_path]}/#{file_basename}"
installer_extension = ::File.extname installer_path

if ::Dir.exist? '/Applications/Xcode.app'
Chef::Log.info('Xcode already installed.')
else
remote_file "Download #{file_basename}" do
backup false
path installer_path
source node['xcode']['url']
checksum node['xcode']['checksum']
not_if { ::File.exist? installer_path }
end

case installer_extension
when '.dmg'
dmg_package 'Xcode' do
file installer_path
action :install
end
when '.xip'
include_recipe 'homebrew'
package 'xz'

remote_file 'Download PBZX v2 unpacker' do
backup false
path "#{Chef::Config[:file_cache_path]}/parse_pbzx2.py"
source 'https://gist.githubusercontent.com/pudquick/ff412bcb29c9c1fa4b8d/raw/24b25538ea8df8d0634a2a6189aa581ccc6a5b4b/parse_pbzx2.py'
not_if { ::File.exist? "#{Chef::Config[:file_cache_path]}/Content" }
end

execute 'Verify the signature and certificate chain that signed the archive' do
command "pkgutil --check-signature #{installer_path}"
cwd Chef::Config[:file_cache_path]
end

execute 'Extract the PBZX stream from the archive' do
command "xar -xf #{file_basename} Content -C ./"
cwd Chef::Config[:file_cache_path]
end

execute 'Unpack PBZX archive' do
command 'python parse_pbzx2.py Content'
cwd Chef::Config[:file_cache_path]
end

file "#{Chef::Config[:file_cache_path]}/Content" do
backup false
action :delete
only_if { ::File.exist? "#{Chef::Config[:file_cache_path]}/Content" }
end

execute 'Decompress the archive' do
command 'xz -d Content.part00.cpio.xz'
cwd Chef::Config[:file_cache_path]
end

execute 'Unpack the CPIO archive' do
command 'cpio --quiet -idm < ./Content.part00.cpio'
cwd Chef::Config[:file_cache_path]
end

file "#{Chef::Config[:file_cache_path]}/Content.part00.cpio" do
backup false
action :delete
only_if { ::File.exist? "#{Chef::Config[:file_cache_path]}/Content.part00.cpio" }
end

execute 'Move the resulting Xcode app bundle into /Applications' do
command 'mv Xcode.app /Applications/Xcode.app'
cwd Chef::Config[:file_cache_path]
end

file installer_path do
backup false
action :delete
only_if { ::Dir.exist? installer_path }
end
else
Chef::Log.error("Not supported file extension: '#{installer_extension}'.")
end
end

execute 'Switch Xcode' do
command 'xcode-select --switch /Applications/Xcode.app/Contents/Developer'
not_if { system('xcodebuild -version > /dev/null 2>&1') }
end

dmg_package node['xcode']['cli']['package_name'] do
Expand All @@ -32,10 +115,8 @@
action :install
end

template "/Library/Preferences/com.apple.dt.Xcode.plist" do
source "com.apple.dt.Xcode.plist.erb"
owner "root"
group "wheel"
template '/Library/Preferences/com.apple.dt.Xcode.plist' do
source 'com.apple.dt.Xcode.plist.erb'
mode 00644
variables({
:last_gm_license => node['xcode']['last_gm_license'],
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/cookbooks/xcode_test/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This is a test cookbook for use by chefspec and test-kitchen
10 changes: 10 additions & 0 deletions test/fixtures/cookbooks/xcode_test/metadata.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name 'xcode_test'
maintainer 'Urbandecoder Labs'
maintainer_email 'jdunn@aquezada.com'
license 'Apache 2.0'
description 'Installs Apple XCode and command-line tools'
long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
version '0.1.0'

depends 'xcode'

1 change: 1 addition & 0 deletions test/fixtures/cookbooks/xcode_test/recipes/default.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include_recipe 'xcode'
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
shared_examples 'simple installation of xcode with CLI' do
describe 'Check Xcode CLI' do
describe command('xcode-select -p') do
its(:exit_status) { should eq 0 }
end

describe command('gcc -v') do
its(:exit_status) { should eq 0 }
end

describe command('make -v') do
its(:exit_status) { should eq 0 }
end
end

describe 'Check xcodebuild' do
describe command('xcodebuild -version') do
its(:exit_status) { should eq 0 }
its(:stdout) { should contain('Xcode') }
its(:stdout) { should contain('Build version') }
end
end
end
5 changes: 5 additions & 0 deletions test/integration/helpers/serverspec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
require 'serverspec'

set :backend, :exec

::Dir[::File.join(::File.dirname(__FILE__), 'shared_examples/*.rb')].sort.each { |f| require f }
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
require 'spec_helper'

describe 'Xcode.dmg installer' do
it_behaves_like 'simple installation of xcode with CLI'
end
5 changes: 5 additions & 0 deletions test/integration/xcode_xip_archive/serverspec/default_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
require 'spec_helper'

describe 'Xcode.xip installer' do
it_behaves_like 'simple installation of xcode with CLI'
end