Skip to content

Commit

Permalink
Use Travis ENV variables and new DO driver
Browse files Browse the repository at this point in the history
  • Loading branch information
hartmantis committed Aug 29, 2014
1 parent 24d3ac8 commit f525174
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 71 deletions.
14 changes: 4 additions & 10 deletions .kitchen.travis.yml
@@ -1,13 +1,7 @@
---
driver:
name: digitalocean
digitalocean_client_id: <%= ENV['DIGITALOCEAN_CLIENT_ID'] %>
digitalocean_api_key: <%= ENV['DIGITALOCEAN_API_KEY'] %>
ssh_key: <%= ChefDk::Helpers.private_key_file %>
ssh_key_ids: <%= ChefDk::Helpers.ssh_key_ids %>
suites:
- name: default
run_list:
- recipe[chef-dk]
attributes:
excludes: ['macosx-10.9']
platforms:
- name: ubuntu-14-04-x64
- name: ubuntu-12-04-x64
- name: centos-6-5-x64
11 changes: 3 additions & 8 deletions .travis.yml
Expand Up @@ -2,22 +2,17 @@ language: ruby

install:
- curl -L https://www.opscode.com/chef/install.sh | sudo bash -s -- -P chefdk
- chef exec /opt/chefdk/embedded/bin/bundle install --without=development integration
- chef exec bundle install --without=development integration

before_script:
- ssh-keygen -f $DIGITALOCEAN_SSH_KEY_FILE -b 768 -P ''
# Pending ENV support in Kitchen's Rake tasks and not just the CLI
- cp .kitchen.travis.yml .kitchen.local.yml
- chef exec /opt/chefdk/embedded/bin/rake upload_key
- echo $SSH_KEY_BODY > ~/.ssh/id_rsa

script: chef exec /opt/chefdk/embedded/bin/rake
script: chef exec rake

after_script:
- chef exec /opt/chefdk/embedded/bin/rake delete_key

env:
global:
# - KITCHEN_LOCAL_YAML=.kitchen.travis.yml
- DIGITALOCEAN_SSH_KEY_FILE=~/.ssh/id_rsa
- secure: e+tF3YK130IfBn16zEw0DLeuU03PehR1WRdzLHVj1g5FWbcCzxQyyX7/y3AzoAkuRHsnyv1kLWVk3ynguJB628iOI6XLKzp3U6leeYIjXDGxT+SXZfEkbAyj6xVZHN+CfcJIX6zvRuGeVETzPbLT2F2/Zef1IxZB5PbR1fpQ0q8=
- secure: C7cVqYVlL/OfIpQQI9KfsKr/PIFGoa2MmiiEPavxmkZ86+bAlICYqsHZid/9W8wz1sJXGcxaNJ6TcVYpIx3cOF83FxonXbmcQESZPwI+c38IebxoOQjD6eWn+PFEt39vx1w7ssL4OOuPayrnmXTyjKofHW+Ea5KOIxsH52vbFds=
53 changes: 0 additions & 53 deletions Rakefile
Expand Up @@ -10,59 +10,6 @@ require 'foodcritic'
require 'kitchen/rake_tasks'
require 'stove/rake_task'

module ChefDk
# Helper methods for uploading and deleting DigitalOcean build keys
#
# @author Jonathan Hartman <j@p4nt5.com>
class Helpers
def self.compute
require 'fog'
Fog::Compute.new(provider: 'DigitalOcean',
digitalocean_client_id: ENV['DIGITALOCEAN_CLIENT_ID'],
digitalocean_api_key: ENV['DIGITALOCEAN_API_KEY'])
end

def self.key_name
"chef-dk-chef-kitchen-#{ENV['TRAVIS_BUILD_NUMBER']}"
end

def self.private_key_file
File.expand_path(ENV['DIGITALOCEAN_SSH_KEY_FILE'])
end

def self.public_key_file
"#{private_key_file}.pub"
end

def self.ssh_key_ids
keys = compute.ssh_keys.map do |k|
k.id if k.name == key_name
end.compact
keys.empty? ? 'TBD' : keys.join(', ')
end

def self.upload_key_to_digitalocean!
unless compute.ssh_keys.index { |k| k.name == key_name }
compute.ssh_keys.create(name: key_name,
ssh_pub_key: File.open(public_key_file).read)
end
ssh_key_ids
end

def self.delete_key_from_digitalocean!
compute.ssh_keys.each { |k| k.destroy if k.name == key_name }
end
end
end

task :upload_key do
ChefDk::Helpers.upload_key_to_digitalocean!
end

task :delete_key do
ChefDk::Helpers.delete_key_from_digitalocean!
end

Cane::RakeTask.new

RuboCop::RakeTask.new
Expand Down

0 comments on commit f525174

Please sign in to comment.