Skip to content

Commit

Permalink
Ready For Review, Docker support added whereas docker support is the …
Browse files Browse the repository at this point in the history
…same as vagrant (#38)

* Adding support for docker, we are using the vagrant provider, chef-sugar allows us a construct for detecting docker and using the right provider. 
* updated travis to use kitchen-dokken
  • Loading branch information
rshade authored Mar 6, 2017
1 parent 07f504f commit 5aa0710
Show file tree
Hide file tree
Showing 32 changed files with 251 additions and 41 deletions.
131 changes: 131 additions & 0 deletions .kitchen.dokken.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
driver:
name: dokken
privileged: true # because Docker and SystemD/Upstart
chef_version: 12.16.42

transport:
name: dokken

provisioner:
name: dokken

verifier:
name: inspec

platforms:
- name: debian-8
driver:
image: debian:8
pid_one_command: /bin/systemd
intermediate_instructions:
- RUN /usr/bin/apt-get update
- RUN /usr/bin/apt-get install apt-transport-https lsb-release procps net-tools -y

- name: centos-6
driver:
image: centos:6
platform: rhel
pid_one_command: /sbin/init
intermediate_instructions:
- RUN yum -y install which initscripts net-tools wget

- name: centos-7
driver:
image: centos:7
platform: rhel
pid_one_command: /usr/lib/systemd/systemd
intermediate_instructions:
- RUN yum -y install lsof which systemd-sysv initscripts wget net-tools

- name: fedora-latest
driver:
image: fedora:latest
pid_one_command: /usr/lib/systemd/systemd
intermediate_instructions:
- RUN dnf -y install yum which systemd-sysv initscripts wget net-tools

- name: ubuntu-12.04
driver:
image: ubuntu-upstart:12.04
pid_one_command: /sbin/init
intermediate_instructions:
- RUN /usr/bin/apt-get update
- RUN /usr/bin/apt-get install apt-transport-https lsb-release procps net-tools -y

- name: ubuntu-14.04
driver:
image: ubuntu-upstart:14.04
pid_one_command: /sbin/init
intermediate_instructions:
- RUN /usr/bin/apt-get update
- RUN /usr/bin/apt-get install apt-transport-https lsb-release procps net-tools -y

- name: ubuntu-16.04
driver:
image: ubuntu:16.04
pid_one_command: /bin/systemd
intermediate_instructions:
- RUN /usr/bin/apt-get update
- RUN /usr/bin/apt-get install apt-transport-https lsb-release procps net-tools -y

- name: opensuse-13.2
driver:
image: opensuse:13.2
pid_one_command: /bin/systemd
intermediate_instructions:
- RUN zypper --non-interactive install aaa_base perl-Getopt-Long-Descriptive which net-tools

- name: opensuse-leap
driver:
image: opensuse:leap
pid_one_command: /bin/systemd
intermediate_instructions:
- RUN zypper --non-interactive install aaa_base perl-Getopt-Long-Descriptive which hostname
#
suites:
- name: default
run_list:
- recipe[machine_tag]
- recipe[fake]
attributes:
apt:
compile_time_update: true
- name: create
run_list:
- recipe[machine_tag]
- recipe[fake::create_tags]
attributes:
apt:
compile_time_update: true
cloud:
provider: vagrant
- name: delete
run_list:
- recipe[machine_tag]
- recipe[fake::create_tags]
- recipe[fake::delete_tags]
attributes:
apt:
compile_time_update: true
cloud:
provider: vagrant
- name: list
run_list:
- recipe[machine_tag]
- recipe[fake::create_tags]
- recipe[fake::list_tags]
attributes:
apt:
compile_time_update: true
cloud:
provider: vagrant
- name: search
run_list:
- recipe[machine_tag]
- recipe[fake::create_tags]
- recipe[fake::search_tags]
attributes:
apt:
compile_time_update: true
cloud:
provider: vagrant
68 changes: 59 additions & 9 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,63 @@
language: ruby
rvm:
- 2.3.1
before_install:
- curl -L https://www.getchef.com/chef/install.sh | sudo bash -s -- -P chefdk -v 1.0.3
- gem install bundler -v 1.11.2
install:
sudo: required
dist: trusty

# install the pre-release chef-dk. Use chef-stable-trusty to install the stable release
addons:
apt:
sources:
- chef-stable-trusty
packages:
- chefdk

# Don't `bundle install` which takes about 1.5 mins
install: echo "skip bundle install"

branches:
only:
- master

services: docker

env:
matrix:
- INSTANCE=default-ubuntu-1404
- INSTANCE=default-ubuntu-1204
- INSTANCE=default-centos-6
- INSTANCE=default-centos-7
- INSTANCE=create-ubuntu-1404
- INSTANCE=create-ubuntu-1204
- INSTANCE=create-centos-6
- INSTANCE=create-centos-7
- INSTANCE=delete-ubuntu-1404
- INSTANCE=delete-ubuntu-1204
- INSTANCE=delete-centos-6
- INSTANCE=delete-centos-7
- INSTANCE=list-ubuntu-1404
- INSTANCE=list-ubuntu-1204
- INSTANCE=list-centos-6
- INSTANCE=list-centos-7
- INSTANCE=search-ubuntu-1404
- INSTANCE=search-ubuntu-1204
- INSTANCE=search-centos-6
- INSTANCE=search-centos-7
before_script:
- sudo iptables -L DOCKER || ( echo "DOCKER iptables chain missing" ; sudo iptables -N DOCKER )
- eval "$(/opt/chefdk/bin/chef shell-init bash)"
- /opt/chefdk/embedded/bin/chef --version
- /opt/chefdk/embedded/bin/cookstyle --version
- /opt/chefdk/embedded/bin/foodcritic --version
- sudo chef gem install kitchen-dokken
- chef exec bundle install --jobs=3 --retry=3
before_script: chef exec rake setup_test_environment
script: ./.travis_install.sh

script: KITCHEN_LOCAL_YAML=.kitchen.dokken.yml /opt/chefdk/embedded/bin/chef exec kitchen verify ${INSTANCE}

matrix:
include:
- script:
- chef exec rake setup_test_environment
- "./.travis_install.sh"
env: UNIT_AND_LINT=1

notifications:
slack:
secure: O3w/D2xUxgWwKY6aRiLP0KvRnUDXS7t9bGzQELo+d6KxGXRhf3mo32FeKKI2MdIVnZJf+nV+/5eIskH7VtcaW+EgS71npLs4NQBrqM5TR3J0gkRoYXGvH8f7VgXtHc3NbrHwc2eCLsacEam4BFHlJQqACRfWLbnS/186gEoLb3o=
1 change: 1 addition & 0 deletions Berksfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
source 'https://supermarket.chef.io'

metadata
Expand Down
17 changes: 7 additions & 10 deletions Berksfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,20 @@ DEPENDENCIES
metadata: true

GRAPH
apt (5.0.0)
compat_resource (>= 12.14.7)
build-essential (7.0.2)
compat_resource (>= 12.14)
apt (6.0.1)
build-essential (8.0.0)
mingw (>= 1.1)
seven_zip (>= 0.0.0)
compat_resource (12.16.2)
chef-sugar (3.4.0)
fake (0.0.0)
machine_tag (>= 0.0.0)
machine_tag (2.0.1)
machine_tag (2.0.3)
apt (>= 0.0.0)
build-essential (>= 0.0.0)
mingw (1.2.4)
compat_resource (>= 0.0.0)
chef-sugar (>= 0.0.0)
mingw (2.0.0)
seven_zip (>= 0.0.0)
ohai (4.2.3)
compat_resource (>= 12.14.7)
ohai (5.0.0)
seven_zip (2.0.2)
windows (>= 1.2.2)
windows (2.1.1)
Expand Down
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
source 'https://rubygems.org'

gem 'right_api_client'
Expand Down
3 changes: 2 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
require 'rspec/core/rake_task'
require 'foodcritic'
require 'kitchen'
Expand Down Expand Up @@ -77,7 +78,7 @@ desc 'runs foodcritic linttask'
task :fc_new do
FoodCritic::Rake::LintTask.new(:chef) do |t|
t.options = {
fail_tags: ['any']
fail_tags: ['any'],
}
end
end
Expand Down
17 changes: 9 additions & 8 deletions Vagrantfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
# -*- mode: ruby -*-
# vi: set ft=ruby :

Expand Down Expand Up @@ -81,16 +82,16 @@ Vagrant.configure('2') do |config|
:mysql => {
server_root_password: 'rootpass',
server_debian_password: 'debpass',
server_repl_password: 'replpass'
server_repl_password: 'replpass',
},
'rs-db' => {
'application' => { 'password' => 'apppass' }
}
'application' => { 'password' => 'apppass' },
},
}
chef.run_list = [
'recipe[machine_tag]',
'recipe[fake::create_tags]',
'recipe[fake::list_tags]'
'recipe[fake::list_tags]',
]
end
end
Expand All @@ -107,16 +108,16 @@ Vagrant.configure('2') do |config|
:mysql => {
server_root_password: 'rootpass',
server_debian_password: 'debpass',
server_repl_password: 'replpass'
server_repl_password: 'replpass',
},
'rs-db' => {
'application' => { 'password' => 'apppass' }
}
'application' => { 'password' => 'apppass' },
},
}
chef.run_list = [
'recipe[machine_tag]',
'recipe[fake::search_tags]',
'recipe[fake::delete_tags]'
'recipe[fake::delete_tags]',
]
end
end
Expand Down
1 change: 1 addition & 0 deletions libraries/machine_tag_base.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
#
# Cookbook Name:: machine_tag
# Library:: machine_tag_base
Expand Down
5 changes: 3 additions & 2 deletions libraries/machine_tag_helper.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
#
# Cookbook Name:: machine_tag
# Library:: machine_tag_helper
Expand Down Expand Up @@ -43,15 +44,15 @@ def self.factory(node)
raise e, "'machine_tag' gem is not installed!" \
" Run the 'machine_tag::default' recipe first to install this gem."
end

require 'chef/sugar'
if shell_out('which', 'rs_tag').exitstatus == 0
# This is a RightScale environment
Chef::MachineTagRightscale.new
elsif shell_out('which', 'rightlink').exitstatus == 0 &&
shell_out('rightlink', '-version').stdout =~ /^RightLink 10/
# This is a RightLink 10 environment
Chef::MachineTagRl10.new
elsif node['cloud'] && node['cloud']['provider'] == 'vagrant'
elsif (node['cloud'] && node['cloud']['provider'] == 'vagrant') || Chef::Sugar::Docker.docker?(node)
# This is a Vagrant environment
hostname, cache_dir = vagrant_params_from_node(node)
Chef::MachineTagVagrant.new(hostname, cache_dir)
Expand Down
1 change: 1 addition & 0 deletions libraries/machine_tag_rightscale.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
#
# Cookbook Name:: machine_tag
# Library:: machine_tag_rightscale
Expand Down
3 changes: 2 additions & 1 deletion libraries/machine_tag_rl10.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
#
# Cookbook Name:: machine_tag
# Library:: machine_tag_rightscale
Expand Down Expand Up @@ -86,7 +87,7 @@ def do_query(query_tags, options = {})
next unless api_client.resource(link['href']).state == 'operational'
resource_tags = api_client.tags.by_resource(resource_hrefs: [link['href']]) # .first.tags
tags_hash[link['href']] = {
'tags' => resource_tags.first.tags.map { |tag| tag['name'] }
'tags' => resource_tags.first.tags.map { |tag| tag['name'] },
}
end
end
Expand Down
3 changes: 2 additions & 1 deletion libraries/machine_tag_vagrant.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
#
# Cookbook Name:: machine_tag
# Library:: machine_tag_vagrant
Expand Down Expand Up @@ -25,7 +26,7 @@ class Chef
class MachineTagVagrant < MachineTagBase
# File in the VM where machine tags will be stored
#
TAGS_JSON_FILE = 'tags.json'.freeze unless const_defined?(:TAGS_JSON_FILE)
TAGS_JSON_FILE = 'tags.json' unless const_defined?(:TAGS_JSON_FILE)

# Creates a tag on the VM by adding the tag to its tags cache file
# if it does not exist.
Expand Down
1 change: 1 addition & 0 deletions libraries/matcher.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
#
# Cookbook Name:: machine_tag
# Library:: matchers
Expand Down
1 change: 1 addition & 0 deletions libraries/provider_machine_tag.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
#
# Cookbook Name:: machine_tag
# Library:: provider_machine_tag
Expand Down
1 change: 1 addition & 0 deletions libraries/resource_machine_tag.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
#
# Cookbook Name:: machine_tag
# Library:: resource_machine_tag
Expand Down
Loading

0 comments on commit 5aa0710

Please sign in to comment.