Skip to content

Commit

Permalink
Add everything for a basic app resource and OS X provider
Browse files Browse the repository at this point in the history
  • Loading branch information
hartmantis committed May 28, 2015
1 parent 4269667 commit 352819a
Show file tree
Hide file tree
Showing 25 changed files with 573 additions and 48 deletions.
5 changes: 5 additions & 0 deletions .kitchen.travis.yml
@@ -1,3 +1,8 @@
---
driver:
name: digitalocean

platforms:
- name: macosx
driver:
name: localhost
12 changes: 8 additions & 4 deletions .kitchen.yml
Expand Up @@ -6,13 +6,17 @@ provisioner:
name: chef_zero

platforms:
- name: ubuntu-14.04
- name: ubuntu-12.04
- name: centos-6.5
- name: centos-5.11
- name: macosx-10.10
driver:
box: roboticcheese/macosx-10.10
ssh:
insert_key: false

suites:
- name: default
run_list:
- recipe[steam]
attributes:
- name: uninstall
run_list:
- recipe[steam_test::uninstall]
4 changes: 2 additions & 2 deletions .travis.yml
@@ -1,4 +1,4 @@
language: ruby
language: objective-c

install:
- curl -L https://www.chef.io/chef/install.sh | sudo bash -s -- -P chefdk
Expand All @@ -10,7 +10,7 @@ before_script:
- echo -e $DIGITALOCEAN_SSH_KEY_BODY > ~/.ssh/id_rsa

script:
- chef exec rake
- chef exec rake && chef exec kitchen test macosx

after_script:

Expand Down
2 changes: 2 additions & 0 deletions Berksfile
Expand Up @@ -3,3 +3,5 @@
source 'https://supermarket.chef.io'

metadata

cookbook 'steam_test', path: 'test/fixtures/cookbooks/steam_test'
1 change: 1 addition & 0 deletions Gemfile
Expand Up @@ -24,6 +24,7 @@ group :test do
gem 'fauxhai'
gem 'test-kitchen'
gem 'kitchen-digitalocean', '>= 0.8.0'
gem 'kitchen-localhost'
gem 'kitchen-vagrant'
end

Expand Down
48 changes: 23 additions & 25 deletions README.md
Expand Up @@ -10,65 +10,63 @@ Steam Cookbook
[codeclimate]: https://codeclimate.com/github/RoboticCheese/steam-chef
[coveralls]: https://coveralls.io/r/RoboticCheese/steam-chef

TODO: Enter the cookbook description here.
A Chef cookbook for installing Steam.

Requirements
============

TODO: Describe cookbook dependencies.
This cookbook currently supports OS X only. Windows and Ubuntu support is
coming.

Usage
=====

TODO: Describe how to use the cookbook.
Either add the default recipe to your run_list or implement the resource
directly in a recipe of your own.

Recipes
=======

***default***

TODO: Describe each component recipe.

Attributes
==========

***default***

TODO: Describe any noteworthy attributes.
Installs Steam.

Resources
=========

***steam***
***steam_app***

TODO: Describe each included resource.
Used to install or remove the Steam app.

Syntax:

steam 'my_resource' do
attribute1 'value1'
action :create
steam_app 'default' do
action :install
end

Actions:

| Action | Description |
|---------|--------------|
| action1 | Do something |
| Action | Description |
|------------|-----------------|
| `:install` | Install Steam |
| `:remove` | Uninstall Steam |

Attributes:

| Attribute | Default | Description |
|------------|----------------|----------------------|
| attribute1 | `'some_value'` | Do something |
| action | `:create` | Action(s) to perform |
| Attribute | Default | Description |
|------------|------------|----------------------|
| action | `:install` | Action(s) to perform |

Providers
=========

TODO: Describe each included provider
***Chef::Provider::SteamApp::MacOsX***

Provider for the Mac OS X platform.

***Chef::Provider::SteamApp***

***Chef::Provider::SomeProvider***
A parent provider for all the platform-specific providers to subclass.

Contributing
============
Expand Down
2 changes: 1 addition & 1 deletion Rakefile
Expand Up @@ -30,4 +30,4 @@ Kitchen::RakeTasks.new

Stove::RakeTask.new

task default: %w(cane rubocop loc foodcritic spec kitchen:all)
task default: %w(cane rubocop loc foodcritic spec)
29 changes: 29 additions & 0 deletions libraries/matchers.rb
@@ -0,0 +1,29 @@
# Encoding: UTF-8
#
# Cookbook Name:: steam
# Library:: matchers
#
# Copyright 2015 Jonathan Hartman
#
# 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.
#

if defined?(ChefSpec)
ChefSpec.define_matcher(:steam_app)

[:install, :remove].each do |a|
define_method("#{a}_steam_app") do |name|
ChefSpec::Matchers::ResourceMatcher.new(:steam_app, a, name)
end
end
end
36 changes: 36 additions & 0 deletions libraries/provider_mapping.rb
@@ -0,0 +1,36 @@
# Encoding: UTF-8
#
# Cookbook Name:: steam
# Library:: provider_mapping
#
# Copyright 2015 Jonathan Hartman
#
# 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 'chef/dsl'
require 'chef/platform/provider_mapping'
require_relative 'provider_steam_app'

Chef::Platform.set(platform: :mac_os_x,
resource: :steam_app,
provider: Chef::Provider::SteamApp::MacOsX)
# TODO: Chef::Platform.set(platform: :windows,
# resource: :steam_app,
# provider: Chef::Provider::SteamApp::Windows)
# TODO: Chef::Platform.set(platform: :ubuntu,
# resource: :steam_app,
# provider: Chef::Provider::SteamApp::Debian)
# TODO: Chef::Platform.set(platform: :debian,
# resource: :steam_app,
# provider: Chef::Provider::SteamApp::Debian)
85 changes: 85 additions & 0 deletions libraries/provider_steam_app.rb
@@ -0,0 +1,85 @@
# Encoding: UTF-8
#
# Cookbook Name:: steam
# Library:: provider_steam_app
#
# Copyright 2015 Jonathan Hartman
#
# 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 'chef/provider/lwrp_base'
require_relative 'resource_steam_app'
require_relative 'provider_steam_app_mac_os_x'
# TODO: require_relative 'provider_steam_app_windows'
# TODO: require_relative 'provider_steam_app_debian'

class Chef
class Provider
# A Chef provider for the Steam app.
#
# @author Jonathan Hartman <j@p4nt5.com>
class SteamApp < Provider::LWRPBase
use_inline_resources

#
# WhyRun is supported by this provider.
#
# @return [TrueClass, FalseClass]
#
def whyrun_supported?
true
end

#
# Install the app if it's not already and set the new_resource installed
# status to true.
#
action :install do
install!
new_resource.installed(true)
end

#
# Remove the app if it's installed and set the new_resource installed
# status to false.
#
action :remove do
remove!
new_resource.installed(false)
end

private

#
# Do the actual app installation.
#
# @raise [NotImplementedError] if not defined for this provider.
#
def install!
fail(NotImplementedError,
"`install!` method not implemented for #{self.class} provider")
end

#
# Do the actual app removal.
#
# @raise [NotImplementedError] if not defined for this provider.
#
def remove!
fail(NotImplementedError,
"`remove!` method not implemented for #{self.class} provider")
end
end
end
end
69 changes: 69 additions & 0 deletions libraries/provider_steam_app_mac_os_x.rb
@@ -0,0 +1,69 @@
# Encoding: UTF-8
#
# Cookbook Name:: steam
# Library:: provider_steam_app_mac_os_x
#
# Copyright 2015 Jonathan Hartman
#
# 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 'chef/provider/lwrp_base'
require_relative 'provider_steam_app'

class Chef
class Provider
class SteamApp < Provider::LWRPBase
# An provider for Steam on Mac OS X.
#
# @author Jonathan Hartman <j@p4nt5.com>
class MacOsX < SteamApp
URL ||= 'https://steamcdn-a.akamaihd.net/client/installer/steam.dmg'
PATH ||= '/Applications/Steam.app'

private

#
# Use a dmg_package resource to download and install the package. The
# dmg_resource creates an inline remote_file, so this is all that's
# needed.
#
# (see SteamApp#install!)
#
def install!
dmg_package 'Steam' do
source URL
accept_eula true
action :install
end
end

#
# (see SteamApp#remove!)
#
def remove!
[
PATH,
::File.expand_path('~/Library/Application Support/Steam'),
::File.expand_path('~/Library/Logs/Steam')
].each do |d|
directory d do
recursive true
action :delete
end
end
end
end
end
end
end

0 comments on commit 352819a

Please sign in to comment.