diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..73955be --- /dev/null +++ b/.gitignore @@ -0,0 +1,15 @@ +*~ +*# +.#* +\#*# +.*.sw[a-z] +*.un~ + +Berksfile.lock +Gemfile.lock +.vagrant +Vagrantfile +.bundle +.coverage +.kitchen +.kitchen.local.yml \ No newline at end of file diff --git a/.kitchen.yml b/.kitchen.yml new file mode 100644 index 0000000..411dbbd --- /dev/null +++ b/.kitchen.yml @@ -0,0 +1,16 @@ +--- +driver_plugin: vagrant +driver_config: + require_chef_omnibus: true + +platforms: + - name: ubuntu-12.04 + driver_config: + box: opscode-ubuntu-12.04 + box_url: https://opscode-vm-bento.s3.amazonaws.com/vagrant/opscode_ubuntu-12.04_provisionerless.box + +suites: + - name: default + run_list: + - recipe[gpac::default] + attributes: \ No newline at end of file diff --git a/.rubocop.yml b/.rubocop.yml new file mode 100644 index 0000000..ed9be0c --- /dev/null +++ b/.rubocop.yml @@ -0,0 +1,23 @@ +AlignParameters: + Enabled: false + +FileName: + Enabled: false + +Encoding: + Enabled: false + +LineLength: + Max: 200 + +HashSyntax: + EnforcedStyle: hash_rockets + +RedundantBegin: + Enabled: false + +UselessAssignment: + Enabled: false + +MethodLength: + Enabled: false \ No newline at end of file diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..91be52b --- /dev/null +++ b/.travis.yml @@ -0,0 +1,20 @@ +language: ruby + +rvm: + - 1.9.3 + - 2.0.0 + - 2.1.0 + +before_script: + - bundle exec berks install + +script: + - bundle exec rake travis + +branches: + only: + - master + +notifications: + email: + - dev@escapestudios.com \ No newline at end of file diff --git a/Berksfile b/Berksfile new file mode 100644 index 0000000..77e0838 --- /dev/null +++ b/Berksfile @@ -0,0 +1,3 @@ +source "https://api.berkshelf.com" + +metadata \ No newline at end of file diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..e34de22 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,15 @@ +Contributing +========= + +1. Fork it +2. Create your feature branch (`git checkout -b my-new-feature`) +3. Commit your changes (`git commit -am 'Add some feature'`) +4. [Add tests for your changes](https://github.com/escapestudios-cookbooks/gpac/blob/master/TESTING.md) +4. Push your changes to your feature branch (`git push origin my-new-feature`) +5. Create a new Pull Request (PR) + +## Testing +Contributions will only be accepted if they are fully tested as specified in [TESTING.md](https://github.com/escapestudios-cookbooks/gpac/blob/master/TESTING.md). + +## metadata.rb +Please do not modify the version number in the metadata.rb; not all changes to the cookbook may be merged and released in the same version. We will handle the version updates during the release process. \ No newline at end of file diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..535d0b3 --- /dev/null +++ b/Gemfile @@ -0,0 +1,23 @@ +source 'https://rubygems.org' + +gem 'rake' + +group :lint do + gem 'rubocop', '~> 0.18' + gem 'foodcritic', '~> 3.0' +end + +group :unit, :integration do + gem 'berkshelf', '~> 3.0' +end + +group :unit do + gem 'chefspec', '~> 3.1' + gem 'rspec-expectations', '~> 2.14.0' +end + +group :integration do + gem 'test-kitchen', '~> 1.2' + gem 'kitchen-vagrant', '~> 0.11' + gem 'serverspec', '~> 1.0' +end \ No newline at end of file diff --git a/README.md b/README.md index 1facfb2..565d9d8 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,5 @@ +[![Build Status](https://secure.travis-ci.org/escapestudios-cookbooks/gpac.png)](http://travis-ci.org/escapestudios-cookbooks/gpac) + Description =========== @@ -44,9 +46,9 @@ References License and Authors =================== -Author: David Joos +Author: David Joos Author: Escape Studios Development -Copyright: 2012-2013, Escape Studios +Copyright: 2012-2014, Escape Studios Unless otherwise noted, all files are released under the MIT license, possible exceptions will contain licensing information in them. diff --git a/Rakefile b/Rakefile new file mode 100644 index 0000000..7c888d6 --- /dev/null +++ b/Rakefile @@ -0,0 +1,47 @@ +require 'rspec/core/rake_task' + +# syntax/lint checks: RuboCop & Foodcritic +namespace :lint do + require 'rubocop/rake_task' + require 'foodcritic' + + desc 'Run Ruby syntax/lint checks' + RuboCop::RakeTask.new(:ruby) + + desc 'Run Chef syntax/lint checks' + FoodCritic::Rake::LintTask.new(:chef) do |task| + task.options = { + :fail_tags => ['any'] + } + end +end + +desc 'Run all syntax/lint checks' +task :lint => ['lint:ruby', 'lint:chef'] + +# unit testing: ChefSpec +desc 'Run RSpec and ChefSpec unit tests' +RSpec::Core::RakeTask.new(:unit) + +# integration testing: Test Kitchen +namespace :integration do + require 'kitchen' + + desc 'Run Test Kitchen integration tests with Vagrant' + task :vagrant do + Kitchen.logger = Kitchen.default_file_logger + Kitchen::Config.new.instances.each do |instance| + instance.test(:always) + end + end +end + +desc 'Run all integration tests' +task :integration => ['integration:vagrant'] + +# Travic CI +desc 'Run tests on Travis CI' +task :travis => [:lint, :unit] + +# the default rake task should just run it all +task :default => [:lint, :unit, :integration] diff --git a/TESTING.md b/TESTING.md new file mode 100644 index 0000000..273db0d --- /dev/null +++ b/TESTING.md @@ -0,0 +1,47 @@ +Testing the cookbook +==================== + +Contributions to this cookbook will only be accepted if all tests pass successfully: + +* Ruby syntax/lint checks: [RuboCop](http://batsov.com/rubocop/) +* Chef syntax/lint checks: [Foodcritic](http://acrmp.github.io/foodcritic/) +* Unit tests: [ChefSpec](http://code.sethvargo.com/chefspec/) +* Integration tests: [Test Kitchen](http://kitchen.ci/) + +Setting up the test environment +------------------------------- + +Install the latest version of [Vagrant](http://www.vagrantup.com/downloads.html) and [VirtualBox](https://www.virtualbox.org/wiki/Downloads) (free) or [VMWare Fusion](http://www.vmware.com/products/fusion) (paid). + +Clone the latest version of the cookbook from the repository. + + git clone git@github.com:escapestudios-cookbooks/gpac.git + cd gpac + +Install the gems used for testing: + + bundle install + +Install the berkshelf plugin for vagrant: + + vagrant plugin install vagrant-berkshelf + +Running syntax/lint checks +-------------------------- + + bundle exec rake lint + +Running unit tests +------------------ + + bundle exec rake unit + +Running integration tests +------------------------- + + bundle exec rake integration + +Running all checks/tests +------------------------ + + bundle exec rake \ No newline at end of file diff --git a/Thorfile b/Thorfile new file mode 100644 index 0000000..70d3cf5 --- /dev/null +++ b/Thorfile @@ -0,0 +1,90 @@ +# encoding: utf-8 + +require 'bundler' +require 'bundler/setup' +require 'berkshelf/thor' + +class Default < Thor + attr_reader :cookbook_name + attr_reader :cookbook_category + + def initialize(*args) + @cookbook_name = "gpac" + @cookbook_category = "Utilities" + + super(*args) + end + + class_option :verbose, + :type => :boolean, + :aliases => "-v", + :default => false + + method_option :knife_config, + :type => :string, + :aliases => "-c", + :desc => "Path to your knife configuration file", + :default => "~/.chef/knife.rb" + + desc "release", "Create a tag from metadata version and push to the community site." + def release + unless clean? + say "Sorry, there are files that need to be committed first.", :red + exit 1 + end + + tag_version{ publish_cookbook(options) } + end + + private + def current_version + Berkshelf::CachedCookbook.from_path(source_root).version + end + + def clean? + sh_with_excode("git diff --exit-code")[1] == 0 + end + + def tag_version + sh "git tag -a -m \"#{current_version}\" #{current_version}" + say "Tagged: #{current_version}", :green + yield if block_given? + sh "git push --tags" + rescue => e + say "Untagging: #{current_version} due to error", :red + sh_with_excode "git tag -d #{current_version}" + say e , :red + say "Please increase the version in metadata.rb", :red + exit 1 + end + + def publish_cookbook(options) + cmd = "knife cookbook site share #{cookbook_name} \"#{cookbook_category}\" -o #{source_root.join("..")} -c #{options[:knife_config]}" + cmd << " -V" if options[:verbose] + sh cmd + say "Version #{current_version} of the #{cookbook_name} cookbook has been uploaded to the Opscode community site.", :green + end + + def source_root + Pathname.new File.dirname(File.expand_path(__FILE__)) + end + + def sh(cmd, dir = source_root, &block) + out, code = sh_with_excode(cmd, dir, &block) + code == 0 ? out : raise(out.empty? ? "Running `#{cmd}` failed. Run this command directly for more detailed output." : out) + end + + def sh_with_excode(cmd, dir = source_root, &block) + cmd << " 2>&1" + outbuf = '' + + Dir.chdir(dir) { + outbuf = `#{cmd}` + if $? == 0 + block.call(outbuf) if block + end + } + + [ outbuf, $? ] + end +end diff --git a/attributes/default.rb b/attributes/default.rb index 5807aea..de8b3a7 100644 --- a/attributes/default.rb +++ b/attributes/default.rb @@ -2,50 +2,50 @@ # Cookbook Name:: gpac # Attributes:: default # -# Copyright 2012-2013, Escape Studios +# Copyright 2012-2014, Escape Studios # default[:gpac][:install_method] = :source -default[:gpac][:prefix] = "/usr/local" -default[:gpac][:svn_repository] = "svn://svn.code.sf.net/p/gpac/code/trunk/gpac" -default[:gpac][:svn_revision] = "HEAD" +default[:gpac][:prefix] = '/usr/local' +default[:gpac][:svn_repository] = 'svn://svn.code.sf.net/p/gpac/code/trunk/gpac' +default[:gpac][:svn_revision] = 'HEAD' default[:gpac][:compile_flags] = [] case node[:platform] - when "debian", "ubuntu" - default[:gpac][:dependencies] = [ - "zlib1g-dev", - "xulrunner-1.9.2-dev", - "libfreetype6-dev", - "libjpeg62-dev", - "libpng12-dev", - "libopenjpeg-dev", - "libmad0-dev", - "libfaad-dev", - "libogg-dev", - "libvorbis-dev", - "libtheora-dev", - "liba52-0.7.4-dev", - "libavcodec-dev", - "libavformat-dev", - "libavutil-dev", - "libswscale-dev", - "libxv-dev", - "x11proto-video-dev", - "libgl1-mesa-dev", - "x11proto-gl-dev", - "linux-sound-base", - "libxvidcore-dev", - "libwxbase2.8-dev", - "libwxgtk2.8-dev", - "wx2.8-headers", - "libssl-dev", - "libjack-dev", - "libasound2-dev", - "libpulse-dev", - "libsdl1.2-dev", - "dvb-apps" - ] - else - default[:gpac][:dependencies] = [] -end \ No newline at end of file +when 'debian', 'ubuntu' + default[:gpac][:dependencies] = [ + 'zlib1g-dev', + 'xulrunner-1.9.2-dev', + 'libfreetype6-dev', + 'libjpeg62-dev', + 'libpng12-dev', + 'libopenjpeg-dev', + 'libmad0-dev', + 'libfaad-dev', + 'libogg-dev', + 'libvorbis-dev', + 'libtheora-dev', + 'liba52-0.7.4-dev', + 'libavcodec-dev', + 'libavformat-dev', + 'libavutil-dev', + 'libswscale-dev', + 'libxv-dev', + 'x11proto-video-dev', + 'libgl1-mesa-dev', + 'x11proto-gl-dev', + 'linux-sound-base', + 'libxvidcore-dev', + 'libwxbase2.8-dev', + 'libwxgtk2.8-dev', + 'wx2.8-headers', + 'libssl-dev', + 'libjack-dev', + 'libasound2-dev', + 'libpulse-dev', + 'libsdl1.2-dev', + 'dvb-apps' + ] +else + default[:gpac][:dependencies] = [] +end diff --git a/chefignore b/chefignore new file mode 100644 index 0000000..a6de142 --- /dev/null +++ b/chefignore @@ -0,0 +1,96 @@ +# Put files/directories that should be ignored in this file when uploading +# or sharing to the community site. +# Lines that start with '# ' are comments. + +# OS generated files # +###################### +.DS_Store +Icon? +nohup.out +ehthumbs.db +Thumbs.db + +# SASS # +######## +.sass-cache + +# EDITORS # +########### +\#* +.#* +*~ +*.sw[a-z] +*.bak +REVISION +TAGS* +tmtags +*_flymake.* +*_flymake +*.tmproj +.project +.settings +mkmf.log + +## COMPILED ## +############## +a.out +*.o +*.pyc +*.so +*.com +*.class +*.dll +*.exe +*/rdoc/ + +# Testing # +########### +.watchr +.rspec +spec/* +spec/fixtures/* +test/* +features/* +Guardfile +Procfile + +# SCM # +####### +.git +*/.git +.gitignore +.gitmodules +.gitconfig +.gitattributes +.svn +*/.bzr/* +*/.hg/* +*/.svn/* + +# Berkshelf # +############# +Berksfile +Berksfile.lock +cookbooks/* +tmp + +# Cookbooks # +############# +CONTRIBUTING +CHANGELOG* + +# Strainer # +############ +Colanderfile +Strainerfile +.colander +.strainer + +# Vagrant # +########### +.vagrant +Vagrantfile + +# Travis # +########## +.travis.yml diff --git a/libraries/helpers.rb b/libraries/helpers.rb index 0001a08..6c2a959 100644 --- a/libraries/helpers.rb +++ b/libraries/helpers.rb @@ -2,22 +2,28 @@ # Cookbook Name:: gpac # Library:: helpers # -# Copyright 2012-2013, Escape Studios +# Copyright 2012-2014, Escape Studios # +# GPAC module module GPAC - module Helpers - #Returns an array of package names that will install GPAC on a node. - #Package names returned are determined by the platform running this recipe. - def gpac_packages - value_for_platform( - [ "ubuntu" ] => { "default" => [ "gpac" ] }, - "default" => [ "gpac" ] - ) - end - end + # helpers module + module Helpers + # Returns an array of package names that will install GPAC on a node. + # Package names returned are determined by the platform running this recipe. + def gpac_packages + value_for_platform( + ['ubuntu'] => { 'default' => ['gpac'] }, + 'default' => ['gpac'] + ) + end + end end -class Chef::Recipe - include GPAC::Helpers -end \ No newline at end of file +# Chef class +class Chef + # Recipe class + class Recipe + include GPAC::Helpers + end +end diff --git a/metadata.rb b/metadata.rb index c6d4b5c..5e2f717 100644 --- a/metadata.rb +++ b/metadata.rb @@ -1,18 +1,18 @@ -name "gpac" -maintainer "Escape Studios" -maintainer_email "dev@escapestudios.com" -license "MIT" -description "Installs/Configures gpac" +name 'gpac' +maintainer 'Escape Studios' +maintainer_email 'dev@escapestudios.com' +license 'MIT' +description 'Installs/Configures gpac' long_description IO.read(File.join(File.dirname(__FILE__), 'README.md')) -version "0.1.0" +version '0.1.0' -%w{ debian ubuntu }.each do |os| -supports os +%w( debian ubuntu ).each do |os| + supports os end -depends "build-essential" -depends "subversion" +depends 'build-essential' +depends 'subversion' -recipe "gpac", "Installs gpac." -recipe "gpac::package", "Installs gpac using packages." -recipe "gpac::source", "Installs gpac from source." \ No newline at end of file +recipe 'gpac', 'Installs gpac.' +recipe 'gpac::package', 'Installs gpac using packages.' +recipe 'gpac::source', 'Installs gpac from source.' diff --git a/recipes/default.rb b/recipes/default.rb index 01cbc33..8db2582 100644 --- a/recipes/default.rb +++ b/recipes/default.rb @@ -2,19 +2,19 @@ # Cookbook Name:: gpac # Recipe:: default # -# Copyright 2012-2013, Escape Studios +# Copyright 2012-2014, Escape Studios # -#install dependencies +# install dependencies node[:gpac][:dependencies].each do |pkg| - package pkg do - action :upgrade - end + package pkg do + action :upgrade + end end case node[:gpac][:install_method] - when :source - include_recipe "gpac::source" - when :package - include_recipe "gpac::package" -end \ No newline at end of file +when :source + include_recipe 'gpac::source' +when :package + include_recipe 'gpac::package' +end diff --git a/recipes/package.rb b/recipes/package.rb index 5bf8a46..8041873 100644 --- a/recipes/package.rb +++ b/recipes/package.rb @@ -2,11 +2,11 @@ # Cookbook Name:: gpac # Recipe:: package # -# Copyright 2012-2013, Escape Studios +# Copyright 2012-2014, Escape Studios # gpac_packages.each do |pkg| - package pkg do - action :upgrade - end -end \ No newline at end of file + package pkg do + action :upgrade + end +end diff --git a/recipes/source.rb b/recipes/source.rb index 33bb3d7..e511612 100644 --- a/recipes/source.rb +++ b/recipes/source.rb @@ -2,43 +2,43 @@ # Cookbook Name:: gpac # Recipe:: source # -# Copyright 2012-2013, Escape Studios +# Copyright 2012-2014, Escape Studios # -include_recipe "build-essential" -include_recipe "subversion" +include_recipe 'build-essential' +include_recipe 'subversion' creates = "#{node[:gpac][:prefix]}/bin/MP4Box" -file "#{creates}" do - action :nothing +file creates do + action :nothing end -subversion "gpac" do - repository node[:gpac][:svn_repository] - revision node[:gpac][:svn_revision] - destination "#{Chef::Config[:file_cache_path]}/gpac" - action :sync - notifies :delete, "file[#{creates}]", :immediately +subversion 'gpac' do + repository node[:gpac][:svn_repository] + revision node[:gpac][:svn_revision] + destination "#{Chef::Config[:file_cache_path]}/gpac" + action :sync + notifies :delete, "file[#{creates}]", :immediately end -#write the flags used to compile to disk +# write the flags used to compile to disk template "#{Chef::Config[:file_cache_path]}/gpac-compiled_with_flags" do - source "compiled_with_flags.erb" - owner "root" - group "root" - mode 0600 - variables( - :compile_flags => node[:gpac][:compile_flags] - ) - notifies :delete, "file[#{creates}]", :immediately + source 'compiled_with_flags.erb' + owner 'root' + group 'root' + mode 0600 + variables( + :compile_flags => node[:gpac][:compile_flags] + ) + notifies :delete, "file[#{creates}]", :immediately end -bash "compile_gpac" do - cwd "#{Chef::Config[:file_cache_path]}/gpac" - code <<-EOH - ./configure --prefix=#{node[:gpac][:prefix]} #{node[:gpac][:compile_flags].join(' ')} - make clean && make && make install - EOH - creates "#{creates}" -end \ No newline at end of file +bash 'compile_gpac' do + cwd "#{Chef::Config[:file_cache_path]}/gpac" + code <<-EOH + ./configure --prefix=#{node[:gpac][:prefix]} #{node[:gpac][:compile_flags].join(' ')} + make clean && make && make install + EOH + creates creates +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb new file mode 100644 index 0000000..4e00004 --- /dev/null +++ b/spec/spec_helper.rb @@ -0,0 +1,4 @@ +require 'chefspec' +require 'chefspec/berkshelf' + +at_exit { ChefSpec::Coverage.report! } diff --git a/spec/unit/default_spec.rb b/spec/unit/default_spec.rb new file mode 100644 index 0000000..a725fa9 --- /dev/null +++ b/spec/unit/default_spec.rb @@ -0,0 +1,5 @@ +require 'spec_helper' + +describe 'gpac::default' do + let(:chef_run) { ChefSpec::Runner.new.converge(described_recipe) } +end