From 9d8b93d118e2f1c9dd35604b5975bd88415bb7b9 Mon Sep 17 00:00:00 2001 From: Jens Braeuer Date: Tue, 11 Feb 2014 15:36:16 +0100 Subject: [PATCH] Add 'attributes/customize.rb'. This file is added to enable improved user experience when overriding attributes. Today customers often override the complete file, which will back-fire when OpsWorks introduces new attributes. By moving out customer attribute changes to separate files, we make it easier for the customer to keep track of their changes. It is also easier for OpsWorks to improve the cookbooks. Once agreed, all cookbooks would have a 'attributes/customize.rb'. --- Rakefile | 30 +++++++++++++++++++++++++++++- apache2/attributes/apache.rb | 24 ++++++++++++++++++------ apache2/attributes/customize.rb | 12 ++++++++++++ 3 files changed, 59 insertions(+), 7 deletions(-) create mode 100644 apache2/attributes/customize.rb diff --git a/Rakefile b/Rakefile index 824620d7e8..e465446cea 100644 --- a/Rakefile +++ b/Rakefile @@ -1,5 +1,7 @@ #/usr/bin/env rake +require 'fileutils' + Encoding.default_external = Encoding::UTF_8 unless RUBY_VERSION.start_with? "1.8" Encoding.default_internal = Encoding::UTF_8 unless RUBY_VERSION.start_with? "1.8" @@ -100,5 +102,31 @@ task :validate_best_practises do end end +desc 'Check that all cookbooks include a customize.rb' +task :validate_customize do + errors = [] + Dir.glob("*/attributes/*.rb").map do |file| + next if File.basename(file) == "customize.rb" + + found = false + IO.readlines(file).each do |line| + # loads/includes attributes + if line.match(/include_attribute [\'\"](\w+)::(\w+)?[\'\"]/) + if $1 == file.split('/').first && $2 == "customize" + found = true + end + end + end + + errors << file unless found + puts "OK: #{file}" if found + end + + if errors.any? + errors.each { |e| warn "Does not include customize.rb: #{e}" } + exit 1 + end +end + desc 'run all checks' -task :default => [:validate_syntax, :validate_literal_includes, :validate_best_practises, :validate_attribute_dependencies] +task :default => [:validate_syntax, :validate_literal_includes, :validate_best_practises, :validate_attribute_dependencies, :validate_customize] diff --git a/apache2/attributes/apache.rb b/apache2/attributes/apache.rb index ff70420c6f..a27816bd50 100644 --- a/apache2/attributes/apache.rb +++ b/apache2/attributes/apache.rb @@ -17,7 +17,22 @@ # limitations under the License. # -# Where the various parts of apache are +### +# Do not use this file to override the apache2 cookbook's default +# attributes. Instead, please use the customize.rb attributes file, +# which will keep your adjustments separate from the AWS OpsWorks +# codebase and make it easier to upgrade. +# +# However, you should not edit customize.rb directly. Instead, create +# "apache2/attributes/customize.rb" in your cookbook repository and +# put the overrides in YOUR customize.rb file. +# +# Do NOT create an 'apache2/attributes/apache.rb' in your cookbooks. Doing so +# would completely override this file and might cause upgrade issues. +# +# See also: http://docs.aws.amazon.com/opsworks/latest/userguide/customizing.html +### + case node[:platform] when 'redhat','centos','fedora','amazon' default[:apache][:dir] = '/etc/httpd' @@ -51,11 +66,6 @@ raise 'Bailing out, unknown platform.' end -### -# These settings need the unless, since we want them to be tunable, -# and we don't want to override the tunings. -### - # General settings default[:apache][:listen_ports] = [ '80','443' ] default[:apache][:contact] = 'ops@example.com' @@ -103,3 +113,5 @@ default[:apache][:logrotate][:mode] = '640' default[:apache][:logrotate][:owner] = 'root' default[:apache][:logrotate][:group] = 'adm' + +include_attribute 'apache2::customize' diff --git a/apache2/attributes/customize.rb b/apache2/attributes/customize.rb new file mode 100644 index 0000000000..38aa59ca06 --- /dev/null +++ b/apache2/attributes/customize.rb @@ -0,0 +1,12 @@ +### +# This is the place to override the apache2 cookbook's default attributes. +# +# Do not edit THIS file directly. Instead, create +# "apache2/attributes/customize.rb" in your cookbook repository and +# put the overrides in YOUR customize.rb file. +### + +# The following shows how to override the Apache contact and timeout settings: +# +#normal[:apache][:contact] = 'you@your-site.com' +#normal[:apache][:timeout] = 60