Skip to content
This repository has been archived by the owner on Jan 18, 2023. It is now read-only.

Update ice cookbook #31

Merged
merged 8 commits into from
Jul 15, 2015
Merged
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
59 changes: 54 additions & 5 deletions .kitchen.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<%
# To keep the YAML as simple as possible, some values are computed here
AWS_ACCESS_KEY_ID = ENV['ICE_AWS_ACCESS_KEY_ID'] ||'ice_billing_aws_access_key_id'
AWS_ACCESS_KEY_ID = ENV['ICE_AWS_ACCESS_KEY_ID'] || 'ice_billing_aws_access_key_id'
AWS_ACCESS_KEY_SECRET = ENV['ICE_AWS_ACCESS_KEY_SECRET'] || 'ice_billing_aws_secret_key'
%>
---
Expand All @@ -19,15 +19,18 @@ provisioner:
platforms:
- name: ubuntu-14.04
- name: ubuntu-12.04
- name: centos-6.4
- name: centos-7.1
- name: centos-6.6

suites:
- name: default
- name: tomcat6
run_list:
- recipe[minitest-handler]
- recipe[ice]
- recipe[ice_cookbook_test]
attributes:
tomcat:
base_version: 6
keytool: /usr/lib/jvm/default-java/bin/keytool
ice:
version: 0.0.4
war_url: https://s3.amazonaws.com/dl.imedidata.net/ice
Expand All @@ -40,4 +43,50 @@ suites:
work_s3_bucket_name: kitchen-tests
billing_s3_bucket_prefix: ice-cookbook-tests-billing-<%= ENV['USER'] %>/
work_s3_bucket_prefix: ice-cookbook-tests-work-<%= ENV['USER'] %>/
start_millis: 1369886400000
includes:
- ubuntu-12.04
- ubuntu-14.04
- name: tomcat6-rhel
run_list:
- recipe[minitest-handler]
- recipe[ice]
attributes:
tomcat:
base_version: 6
keytool: /usr/lib/jvm/java-1.6.0/bin/keytool
ice:
version: 0.0.4
war_url: https://s3.amazonaws.com/dl.imedidata.net/ice
skip_manifest_check: true
checksum: eb9e7503585553bdebf9d93016bcbe7dc033c21e2b1b2f0df0978ca2968df047
company_name: Your Company
billing_aws_access_key_id: <%= AWS_ACCESS_KEY_ID %>
billing_aws_secret_key: <%= AWS_ACCESS_KEY_SECRET %>
billing_s3_bucket_name: kitchen-tests
work_s3_bucket_name: kitchen-tests
billing_s3_bucket_prefix: ice-cookbook-tests-billing-<%= ENV['USER'] %>/
work_s3_bucket_prefix: ice-cookbook-tests-work-<%= ENV['USER'] %>/
includes:
- centos-6.6
- name: tomcat7-rhel
run_list:
- recipe[minitest-handler]
- recipe[ice]
attributes:
tomcat:
base_version: 7
keytool: /usr/lib/jvm/java-1.6.0/bin/keytool
ice:
version: 0.0.4
war_url: https://s3.amazonaws.com/dl.imedidata.net/ice
skip_manifest_check: true
checksum: eb9e7503585553bdebf9d93016bcbe7dc033c21e2b1b2f0df0978ca2968df047
company_name: Your Company
billing_aws_access_key_id: <%= AWS_ACCESS_KEY_ID %>
billing_aws_secret_key: <%= AWS_ACCESS_KEY_SECRET %>
billing_s3_bucket_name: kitchen-tests
work_s3_bucket_name: kitchen-tests
billing_s3_bucket_prefix: ice-cookbook-tests-billing-<%= ENV['USER'] %>/
work_s3_bucket_prefix: ice-cookbook-tests-work-<%= ENV['USER'] %>/
includes:
- centos-7.1
7 changes: 7 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
language: ruby
cache: bundler
rvm:
- 2.2.0
branches:
only:
- master
3 changes: 2 additions & 1 deletion Berksfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
source 'https://supermarket.getchef.com'
source 'https://supermarket.chef.io'

metadata

cookbook 'nginx', '~> 2.7.4'
cookbook 'minitest-handler'
19 changes: 13 additions & 6 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
source 'https://rubygems.org'

gem 'berkshelf'
gem 'test-kitchen', group: :integration
gem 'kitchen-vagrant', group: :integration
gem 'kitchen-ec2', group: :integration
gem 'foodcritic', group: :integration
gem 'chef', '~> 11.4.2'
gem 'knife-ec2', '~> 0.6.4'
gem 'chef'
gem 'knife-ec2'

group :integration do
gem 'test-kitchen'
gem 'kitchen-vagrant'
gem 'kitchen-ec2'
gem 'foodcritic'
end

group :testing do
gem 'rubocop'
end
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ Tested on

* Ubuntu 14.04
* Ubuntu 12.04
* Centos 6.4
* Centos 7.1
* Centos 6.6

Other Debian and RHEL family distributions are assumed to work but YMMV.

Expand Down
29 changes: 29 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
require 'rubocop/rake_task'
require 'foodcritic'

desc 'RuboCop compliancy checks'
RuboCop::RakeTask.new(:rubocop)

FoodCritic::Rake::LintTask.new do |t|
t.options = {
tags: %w(
~solo
~FC019
),
fail_tags: ['any']
}
end

desc 'Install berkshelf cookbooks locally'
task :berkshelf do
require 'berkshelf'
require 'berkshelf/berksfile'
current_dir = File.expand_path('../', __FILE__)
berksfile_path = File.join(current_dir, 'Berksfile')
cookbooks_path = File.join(current_dir, 'vendor')
FileUtils.rm_rf(cookbooks_path)
berksfile = Berkshelf::Berksfile.from_file(berksfile_path)
berksfile.vendor(cookbooks_path)
end

task default: [:foodcritic, :rubocop]
6 changes: 6 additions & 0 deletions attributes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,12 @@
# proxy on Ice readers/UI nodes.
node.default['ice']['public_hostname'] = nil

# Setup Nginx.
node.default['ice']['nginx_enabled'] = true

# Disable Nginx default site.
node.default['ice']['nginx_disable_default_site'] = true

# Nginx port configuration.
node.default['ice']['nginx_port'] = 80

Expand Down
54 changes: 11 additions & 43 deletions recipes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
java_options = "#{node['tomcat']['java_options']} -Dice.s3AccessKeyId=#{node['ice']['billing_aws_access_key_id']} -Dice.s3SecretKey=#{node['ice']['billing_aws_secret_key']}"

node.override['tomcat']['java_options'] = java_options
node.override['nginx']['default_site_enabled'] = false

artifact_deploy 'ice' do
version node['ice']['version']
Expand Down Expand Up @@ -86,57 +85,26 @@
}

restart proc {
service "tomcat#{node['tomcat']['base_version']}" do
service node['tomcat']['base_instance'] do
action :restart
end
}
end

# Allow httpd to connect to tomcat for proxy
execute 'selinux httpd_can_network_connect' do
command '/usr/sbin/setsebool httpd_can_network_connect true'
only_if { %w(rhel fedora).include?(node['platform_family']) }
end

# Configure logrotate
logrotate_app "tomcat#{node['tomcat']['base_version']}" do
logrotate_app node['tomcat']['base_instance'] do
cookbook 'logrotate'
path "/var/log/tomcat#{node['tomcat']['base_version']}/catalina.out"
path "#{node['tomcat']['log_dir']}/catalina.out"
frequency node['ice']['logrotate_frequency']
rotate node['ice']['logrotate_rotate']
create "640 tomcat#{node['tomcat']['base_version']} adm"
create "640 #{node['tomcat']['base_instance']} adm"
options %w( copytruncate compress missingok )
end

if node['ice']['reader']['enabled'] == true
# Ugly hack to fix this issue: https://github.com/miketheman/nginx/issues/248
node.default['nginx']['pid'] = '/run/nginx.pid' if ubuntu_trusty?

include_recipe 'nginx::default'

# Configure nginx site reverse proxy
if node['ice']['public_hostname'].nil?
if node.attribute?('ec2')
node.override['ice']['public_hostname'] = node['ec2']['public_hostname']
elsif node.attribute?('cloud')
node.override['ice']['public_hostname'] = node['cloud']['public_hostname']
else
node.override['ice']['public_hostname'] = node['fqdn']
end

if node['ice']['nginx_port'] != 80
node.override['ice']['public_hostname'] += ":#{node['ice']['nginx_port']}"
end
end

# Disable default site first
nginx_site 'default' do
enable false
end

# Generate nginx ice site
template "#{node['nginx']['dir']}/sites-available/ice" do
cookbook node['ice']['nginx_config_cookbook']
source node['ice']['nginx_config']
mode 0644
owner node['nginx']['user']
group node['nginx']['group']
end

# Enable ice site
nginx_site 'ice'
end
include_recipe 'ice::nginx' if node['ice']['reader']['enabled'] == true && node['ice']['nginx_enabled']
41 changes: 41 additions & 0 deletions recipes/nginx.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#
# Cookbook Name:: ice
# Recipe:: nginx
#

node.override['nginx']['default_site_enabled'] = false

include_recipe 'nginx::default'

# Configure nginx site reverse proxy
if node['ice']['public_hostname'].nil?
if node.attribute?('ec2')
node.override['ice']['public_hostname'] = node['ec2']['public_hostname']
elsif node.attribute?('cloud')
node.override['ice']['public_hostname'] = node['cloud']['public_hostname']
else
node.override['ice']['public_hostname'] = node['fqdn']
end

if node['ice']['nginx_port'] != 80
node.override['ice']['public_hostname'] += ":#{node['ice']['nginx_port']}"
end
end

# Disable default site first
nginx_site 'default' do
enable false
only_if node['ice']['nginx_disable_default_site']
end

# Generate nginx ice site
template "#{node['nginx']['dir']}/sites-available/ice" do
cookbook node['ice']['nginx_config_cookbook']
source node['ice']['nginx_config']
mode 0644
owner node['nginx']['user']
group node['nginx']['group']
end

# Enable ice site
nginx_site 'ice'
10 changes: 6 additions & 4 deletions test/integration/default/serverspec/ice_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
require_relative '../../../kitchen/data/spec_helper'

suffix = node['tomcat']['base_version'].to_i < 7 ? node['tomcat']['base_version'] : ''

describe 'should be running tomcat6 on port 8080' do
describe service('tomcat6') do
describe service("tomcat#{suffix}") do
it { should be_enabled }
it { should be_running }
end
Expand All @@ -23,19 +25,19 @@
end

describe 'should be configured to run a processer' do
describe file('/var/lib/tomcat6/webapps/releases/0.0.4/WEB-INF/classes/ice.properties') do
describe file("/var/lib/tomcat#{suffix}/webapps/releases/0.0.4/WEB-INF/classes/ice.properties") do
its(:content) { should match(/ice\.processor=true/) }
end
end

describe 'should be configured to run a reader' do
describe file('/var/lib/tomcat6/webapps/releases/0.0.4/WEB-INF/classes/ice.properties') do
describe file("/var/lib/tomcat#{suffix}/webapps/releases/0.0.4/WEB-INF/classes/ice.properties") do
its(:content) { should match(/ice\.reader=true/) }
end
end

describe 'should be configured to pull billing files from 90 days back' do
describe file('/var/lib/tomcat6/webapps/releases/0.0.4/WEB-INF/classes/ice.properties') do
describe file("/var/lib/tomcat#{suffix}/webapps/releases/0.0.4/WEB-INF/classes/ice.properties") do
processing_start_millis = (Date.today - 90).strftime('%Q')[0..-6] # drop last 6 digits
its(:content) { should match(/ice\.startmillis=#{processing_start_millis}\d+{5,5}/) }
end
Expand Down