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

Perform the true Chef run in Travis CI (linux and mac environments) #32

Closed
wants to merge 5 commits into from
Closed
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: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ Berksfile.lock
.ruby-gemset
.rubocop_todo.yml
.rspec

.idea
2 changes: 1 addition & 1 deletion .kitchen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ driver:

provisioner:
name: chef_solo
require_chef_omnibus: 11.14
require_chef_omnibus: latest

platforms:

Expand Down
28 changes: 23 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,25 @@
os:
- linux
- osx
language: ruby
sudo: false
rvm:
- 2.0
- 2
bundler_args: --without integration
cache: bundler
- 2.2.2
env:
- BERKSHELF_PATH=/tmp/
before_install:
- git clone https://github.com/sstephenson/bats.git
- sudo ./bats/install.sh /usr/local
- curl -L https://www.chef.io/chef/install.sh | sudo bash
- gem install bundler
install:
- bundle install --without integration
- bundle exec berks vendor /tmp/cookbooks
- cp tests/support/dummy-validation.pem /tmp/validation.pem
- cp tests/support/client.rb /tmp/client.rb
- cp tests/support/dna.json /tmp/dna.json
script:
- rvm reset # To use the embedded ruby in chef-client
- sudo chef-client -z -c /tmp/client.rb -j /tmp/dna.json # Run chef in zero mode
- '[ -f ~/.bash_profile ] && source ~/.bash_profile || source ~/.profile && source /etc/profile' # Apply new env vars
- rvm use ruby-2.2.2 # To use the rvm ruby and custom gems
- bundle exec rake # Test all
2 changes: 1 addition & 1 deletion Berksfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
site :opscode
source 'https://supermarket.chef.io'

metadata

Expand Down
10 changes: 5 additions & 5 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ source 'https://rubygems.org'

gem 'rake'
gem 'tailor'
gem 'chefspec', '~> 1.3.0'
gem 'chefspec', '~> 4.7'
gem 'foodcritic', '>= 5.0.0'
gem 'chef', '~> 11.14'
gem 'chef', '~> 12.11'
gem 'rubocop'
gem 'berkshelf', '~> 4.3'

group :integration do
gem 'berkshelf', '~> 3.3.0'
gem 'test-kitchen', '~> 1.4.2'
gem 'kitchen-vagrant', '~> 0.19.0'
gem 'test-kitchen', '~> 1.10'
gem 'kitchen-vagrant', '~> 0.20.0'
end
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ The **default** recipe of this Chef cookbook will:

* Download and install/upgrade Android SDK (not ADT)
* Update SDK dependencies to install *some* Android platforms (`--filter` list can be customized in cookbook attributes)
* Define a default `ANDROID_HOME` environment variable (via `/etc/profile.d/...` mechanism)
* Add `ANDROID_HOME/tools` and `ANDROID_HOME/platform-tools` to default `PATH` environment variable (via `/etc/profile.d/...` mechanism)
* Define a default `ANDROID_HOME` environment variable
* Add `ANDROID_HOME/tools` and `ANDROID_HOME/platform-tools` to default `PATH` environment variable

Requirements
------------

* Depends on **opscode/ark** and **opscode/java** cookbooks
* This cookbook currently supports Ubuntu 12.04+ and CentOS 6.6+, but more Linux distributions are welcome (depending on community interests)
* Depends on **ark**, **java**, **homebrew**, **chef-sugar** and **bash** cookbooks
* This cookbook currently supports Ubuntu 12.04+ and CentOS 6.6+, Mac OS X

Attributes
----------
Expand All @@ -24,7 +24,7 @@ TODO (work in progress)
Installation and Usage
----------------------

This cookbook is released at http://community.opscode.com/cookbooks/android-sdk and its original git repository is https://github.com/gildegoma/chef-android-sdk.
This cookbook is released at https://supermarket.chef.io/cookbooks/android-sdk and its original git repository is https://github.com/gildegoma/chef-android-sdk.

* Find your favourite way ([Berkhelf](http://berkshelf.com/), [Librarian-Chef](https://github.com/applicationsonline/librarian#readme), knife-github-cookbooks, Git submodule, Opscode community API or even tarball download) to install this cookbook (and its dependency).
* Include the `android-sdk::default` recipe to your run list or inside your cookbook.
Expand All @@ -35,15 +35,15 @@ Quality Assurance

### Continous Integration

This Cookbook is being _tasted_ by Travis CI: [![Build Status](https://secure.travis-ci.org/gildegoma/chef-android-sdk.png?branch=master)](https://travis-ci.org/gildegoma/chef-android-sdk)
This Cookbook is being _tested_ by Travis CI: [![Build Status](https://secure.travis-ci.org/gildegoma/chef-android-sdk.png?branch=master)](https://travis-ci.org/gildegoma/chef-android-sdk)

Automated validations are following:
* Static Analysis of Ruby code with [tailor](https://github.com/turboladen/tailor#readme) lint tool
* Static Analysis of Chef Cookbooks with [foodcritic](http://acrmp.github.com/foodcritic/) lint tool
* `knife cookbook test` in a very basic sandbox
* _PENDING:_ Expectations described with RSpec examples with [ChefSpec](https://github.com/acrmp/chefspec)
* _PENDING:_ [ServerSpec](http://serverspec.org/) integration testing
* _PENDING:_ Run true chef (matrix) on travis VM!
* Run true chef (matrix) on travis VM with Bats test

### Development and Testing

Expand Down
15 changes: 13 additions & 2 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ require 'rubocop/rake_task'
require 'rspec/core/rake_task'

# TODO: add chefspec
task default: [:tailor, :rubocop, :foodcritic, :knife]
task default: [:bats, :tailor, :rubocop, :foodcritic, :knife]

desc 'Lint Ruby code'
task :tailor do
Expand Down Expand Up @@ -39,7 +39,7 @@ end
RuboCop::RakeTask.new

FoodCritic::Rake::LintTask.new do |t|
t.options = { fail_tags: ['any'], tags: ['~FC041'] }
t.options = { fail_tags: ['any'], tags: ['~FC041', '~FC053'] }
end

RSpec::Core::RakeTask.new
Expand Down Expand Up @@ -76,6 +76,13 @@ task :prepare_sandbox do
end
end

desc 'Check node using bats test'
task :bats do
Dir.chdir(bats_test_path) do
sh 'bats --tap default.bats'
end
end

begin
require 'kitchen/rake_tasks'
Kitchen::RakeTasks.new
Expand Down Expand Up @@ -104,3 +111,7 @@ end
def knife_rb
File.join(sandbox_root, 'knife.rb')
end

def bats_test_path
File.join(File.dirname(__FILE__), %w(tests integration default bats))
end
11 changes: 7 additions & 4 deletions attributes/default.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
default['android-sdk']['name'] = 'android-sdk'
default['android-sdk']['owner'] = 'root'
default['android-sdk']['group'] = 'root'
default['android-sdk']['setup_root'] = nil # ark defaults (/usr/local) is used if this attribute is not defined
default['android-sdk']['with_symlink'] = true # use ark's :install action when true; use ark's :put action when false
default['android-sdk']['backup_archive'] = false # The number of backups to be kept in /var/chef/backup. To prevent backups set to false.
default['android-sdk']['setup_root'] = nil # ark defaults (/usr/local) is used if this attribute is not defined
default['android-sdk']['with_symlink'] = true # use ark's :install action when true; use ark's :put action when false
default['android-sdk']['set_environment_variables'] = true

default['android-sdk']['version'] = '24.4'
default['android-sdk']['checksum'] = 'f2bb546534d16e2004665257ee530060338c684adad14a49cd4bbde08098d8a4'
default['android-sdk']['download_url'] = "http://dl.google.com/android/android-sdk_r#{node['android-sdk']['version']}-linux.tgz"
default['android-sdk']['checksum']['linux'] = 'f2bb546534d16e2004665257ee530060338c684adad14a49cd4bbde08098d8a4'
default['android-sdk']['checksum']['mac_os_x'] = 'a1cb0c9b2036d597e18986de1bd43918b6113373ff3bf6fdb81b6cce4ec3efd7'
default['android-sdk']['download_url']['linux'] = "http://dl.google.com/android/android-sdk_r#{node['android-sdk']['version']}-linux.tgz"
default['android-sdk']['download_url']['mac_os_x'] = "https://dl.google.com/android/android-sdk_r#{node['android-sdk']['version']}-macosx.zip"

#
# List of Android SDK components to preinstall:
Expand Down
16 changes: 12 additions & 4 deletions metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,27 @@
maintainer_email '[email protected]'
license 'Apache 2.0'
description 'Installs Google Android SDK'
long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
issues_url 'https://github.com/gildegoma/chef-android-sdk/issues'
source_url 'https://github.com/gildegoma/chef-android-sdk'
version '0.2.0'

%w(java ark).each do |dep|
depends dep
end
depends 'java'
depends 'ark', '>= 1.1.0'
depends 'homebrew', '>= 2.1.0'
depends 'bash', '~> 0.1.2'
depends 'chef-sugar', '>= 3.3.0'

# TODO: maybe put maven into depends section
recommends 'maven' # Maven 3.1.1+ is required by android-sdk::maven-rescue recipe

supports 'ubuntu', '>= 12.04'
supports 'centos', '>= 6.6'
supports 'mac_os_x'

# Support for more platforms is on the road (e.g. Debian, CentOS,...).
# Please watch or help on https://github.com/gildegoma/chef-android-sdk/issues/5

recipe 'android-sdk::default', 'Install and update Google Android SDK'
recipe 'android-sdk::maven_rescue', 'Install missing dependencies with Maven Android SDK Deployer'
recipe 'android-sdk::maven_rescue', 'Install missing dependencies with Maven '\
'Android SDK Deployer'
69 changes: 47 additions & 22 deletions recipes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.

include_recipe 'chef-sugar::default'
include_recipe 'java' unless node['android-sdk']['java_from_system']

setup_root = node['android-sdk']['setup_root'].to_s.empty? ? node['ark']['prefix_home'] : node['android-sdk']['setup_root']
Expand Down Expand Up @@ -53,15 +54,26 @@
#
# Download and setup android-sdk tarball package
#
if linux?
sdk_url = node['android-sdk']['download_url']['linux']
sdk_checksum = node['android-sdk']['checksum']['linux']
elsif mac_os_x?
sdk_url = node['android-sdk']['download_url']['mac_os_x']
sdk_checksum = node['android-sdk']['checksum']['mac_os_x']
else
Chef::Log.error('Platform not supported!')
end

ark node['android-sdk']['name'] do
url node['android-sdk']['download_url']
url sdk_url
path node['android-sdk']['setup_root']
checksum node['android-sdk']['checksum']
checksum sdk_checksum
version node['android-sdk']['version']
prefix_root node['android-sdk']['setup_root']
prefix_home node['android-sdk']['setup_root']
owner node['android-sdk']['owner']
group node['android-sdk']['group']
group node['android-sdk']['group'] unless mac_os_x?
backup node['android-sdk']['backup_archive']
action node['android-sdk']['with_symlink'] ? :install : :put
end

Expand All @@ -70,41 +82,54 @@
#
%w(add-ons platforms tools).each do |subfolder|
directory File.join(android_home, subfolder) do
mode 0755
mode '0755'
end
end
# TODO: find a way to handle 'chmod stuff' below with own chef resource (idempotence stuff...)
execute 'Grant all users to read android files' do
command "chmod -R a+r #{android_home}/*"
user node['android-sdk']['owner']
group node['android-sdk']['group']
group node['android-sdk']['group'] unless mac_os_x?
end
execute 'Grant all users to execute android tools' do
command "chmod -R a+X #{File.join(android_home, 'tools')}/*"
user node['android-sdk']['owner']
group node['android-sdk']['group']
group node['android-sdk']['group'] unless mac_os_x?
end

#
# Configure environment variables (ANDROID_HOME and PATH)
#
template "/etc/profile.d/#{node['android-sdk']['name']}.sh" do
source 'android-sdk.sh.erb'
mode 0644
owner node['android-sdk']['owner']
group node['android-sdk']['group']
variables(
android_home: android_home
)
only_if { node['android-sdk']['set_environment_variables'] }
if linux?
template "/etc/profile.d/#{node['android-sdk']['name']}.sh" do
source 'android-sdk.sh.erb'
mode '0644'
owner node['android-sdk']['owner']
group node['android-sdk']['group'] unless mac_os_x?
variables(
android_home: android_home
)
only_if { node['android-sdk']['set_environment_variables'] }
end
elsif mac_os_x?
bash_profile 'profile.android_sdk' do
user node['android-sdk']['owner']
content <<-EOH
export ANDROID_HOME=#{android_home}
export PATH=$PATH:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools
EOH
end
else
Chef::Log.error('Platform not supported!')
end

package 'expect'

#
# Install, Update (a.k.a. re-install) Android components
#

homebrew_tap 'homebrew/dupes' if mac_os_x?
package 'expect'

# KISS: use a basic idempotent guard, waiting for https://github.com/gildegoma/chef-android-sdk/issues/12
unless File.exist?("#{setup_root}/#{node['android-sdk']['name']}/temp")

Expand All @@ -118,7 +143,7 @@
environment 'ANDROID_HOME' => android_home
path [File.join(android_home, 'tools')]
user node['android-sdk']['owner']
group node['android-sdk']['group']
group node['android-sdk']['group'] unless mac_os_x?
# TODO: use --force or not?
code <<-EOF
spawn #{android_bin} update sdk --no-ui --all --filter #{sdk_component}
Expand Down Expand Up @@ -151,16 +176,16 @@
cookbook_file File.join(node['android-sdk']['scripts']['path'], android_helper_script) do
source android_helper_script
owner node['android-sdk']['scripts']['owner']
group node['android-sdk']['scripts']['group']
mode 0755
group node['android-sdk']['scripts']['group'] unless mac_os_x?
mode '0755'
end
end
%w(android-update-sdk).each do |android_helper_script|
template File.join(node['android-sdk']['scripts']['path'], android_helper_script) do
source "#{android_helper_script}.erb"
owner node['android-sdk']['scripts']['owner']
group node['android-sdk']['scripts']['group']
mode 0755
group node['android-sdk']['scripts']['group'] unless mac_os_x?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the limit on mac_os_x ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had some trouble to set properly group on mac, but now it doesn't occurs. I will remove unless mac_os_x? today and recommit to branch.

mode '0755'
end
end

Expand Down
8 changes: 4 additions & 4 deletions recipes/maven_rescue.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
#
directory maven_android_sdk_deployer_home do
user node['android-sdk']['owner']
group node['android-sdk']['group']
mode 00755
group node['android-sdk']['group'] unless mac_os_x?
mode '0755'
action :create
end
git maven_android_sdk_deployer_home do
Expand All @@ -19,7 +19,7 @@
checkout_branch "deploy_#{node['android-sdk']['maven-android-sdk-deployer']['version']}"
action :sync
user node['android-sdk']['owner']
group node['android-sdk']['group']
group node['android-sdk']['group'] unless mac_os_x?
end

#
Expand All @@ -35,7 +35,7 @@
execute 'Execute maven-android-sdk-deployer' do
command "mvn clean install -Dmaven.repo.local=#{node['android-sdk']['maven-local-repository']} --fail-never -B"
user node['android-sdk']['owner']
group node['android-sdk']['group']
group node['android-sdk']['group'] unless mac_os_x?
cwd maven_android_sdk_deployer_home

# FIXME: setting HOME might be required (if $HOME used in node['android-sdk']['maven-local-repository'],
Expand Down
9 changes: 9 additions & 0 deletions tests/integration/default/bats/default.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env bats

@test "Check that the android is available" {
command -v android
}

@test "Check that the adb is available" {
command -v adb
}
10 changes: 10 additions & 0 deletions tests/support/client.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
node_name 'ci-travis'
cookbook_path ['/tmp/cookbooks']
data_bag_path '/tmp/data_bags'
environment_path '/tmp/environments'
node_path '/tmp/nodes'
role_path '/tmp/roles'
client_path '/tmp/clients'
validation_key '/tmp/validation.pem'
client_key '/tmp/client.pem'
chef_server_url 'http://127.0.0.1:8889'
Loading