a bunch of updates, especially to the rake apache:create task
This commit is contained in:
parent
0926ca1887
commit
d373738451
@ -1,17 +1,29 @@
|
|||||||
#!/usr/bin/env ruby
|
#!/usr/bin/env ruby
|
||||||
|
|
||||||
require 'fileutils'
|
require 'fileutils'
|
||||||
|
require 'rubygems'
|
||||||
|
require 'rainbow'
|
||||||
|
|
||||||
if !ARGV[0]
|
if !ARGV[0]
|
||||||
puts "Directory name required."
|
puts "Directory name required.".foreground(:red)
|
||||||
exit 1
|
exit 1
|
||||||
end
|
end
|
||||||
|
|
||||||
if File.directory?(ARGV[0])
|
if File.directory?(ARGV[0])
|
||||||
puts "You can't overwrite an existing directory."
|
puts "You can't overwrite an existing directory.".foreground(:red)
|
||||||
exit 1
|
exit 1
|
||||||
end
|
end
|
||||||
|
|
||||||
|
puts "Copying skel files...".foreground(:green)
|
||||||
FileUtils.cp_r File.expand_path(File.join(File.dirname(__FILE__), '..', 'skel')), ARGV[0]
|
FileUtils.cp_r File.expand_path(File.join(File.dirname(__FILE__), '..', 'skel')), ARGV[0]
|
||||||
|
|
||||||
|
puts "Making config directories...".foreground(:green)
|
||||||
FileUtils.mkdir_p File.join(ARGV[0], 'source')
|
FileUtils.mkdir_p File.join(ARGV[0], 'source')
|
||||||
|
FileUtils.mkdir_p File.join(ARGV[0], 'conf.d-original')
|
||||||
FileUtils.mkdir_p File.join(ARGV[0], 'conf.d')
|
FileUtils.mkdir_p File.join(ARGV[0], 'conf.d')
|
||||||
|
|
||||||
|
print "Complete! ".bright.foreground(:green)
|
||||||
|
print "cd #{ARGV[0]}".bright.foreground(:yellow)
|
||||||
|
print " and run ".foreground(:green)
|
||||||
|
print "bundle exec rake -T ".bright.foreground(:yellow)
|
||||||
|
puts "to get started.".foreground(:green)
|
||||||
|
@ -94,6 +94,7 @@ module Apache
|
|||||||
|
|
||||||
FileUtils.mkdir_p File.split(target).first
|
FileUtils.mkdir_p File.split(target).first
|
||||||
File.open(target, 'w') { |file| file.puts generate_config_file(config) * "\n" }
|
File.open(target, 'w') { |file| file.puts generate_config_file(config) * "\n" }
|
||||||
|
@was_written = true
|
||||||
|
|
||||||
config
|
config
|
||||||
end
|
end
|
||||||
@ -103,6 +104,14 @@ module Apache
|
|||||||
@is_disabled = true
|
@is_disabled = true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def disabled?
|
||||||
|
@is_disabled
|
||||||
|
end
|
||||||
|
|
||||||
|
def written?
|
||||||
|
@was_written
|
||||||
|
end
|
||||||
|
|
||||||
def generate_config_file(config)
|
def generate_config_file(config)
|
||||||
output = [ "# Generated by apache-config-generator #{Time.now.to_s}", config ]
|
output = [ "# Generated by apache-config-generator #{Time.now.to_s}", config ]
|
||||||
output.unshift('# disabled') if @is_disabled
|
output.unshift('# disabled') if @is_disabled
|
||||||
@ -114,6 +123,7 @@ module Apache
|
|||||||
@config = []
|
@config = []
|
||||||
@line_indent = 0
|
@line_indent = 0
|
||||||
@is_disabled = false
|
@is_disabled = false
|
||||||
|
@was_written = false
|
||||||
end
|
end
|
||||||
|
|
||||||
# Indent the string by the current @line_indent level
|
# Indent the string by the current @line_indent level
|
||||||
|
8
lib/apache/hash.rb
Normal file
8
lib/apache/hash.rb
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
class Hash
|
||||||
|
def to_sym_keys
|
||||||
|
Hash[self.collect { |key, value|
|
||||||
|
value = value.to_sym_keys if value.kind_of?(Hash)
|
||||||
|
[ key.to_sym, value ]
|
||||||
|
}]
|
||||||
|
end
|
||||||
|
end
|
@ -5,6 +5,15 @@ include Apache::Rake::Support
|
|||||||
|
|
||||||
task :default => 'apache:create'
|
task :default => 'apache:create'
|
||||||
|
|
||||||
|
def capture_stdout
|
||||||
|
buffer = StringIO.new
|
||||||
|
$stdout = buffer
|
||||||
|
yield
|
||||||
|
$stdout = STDOUT
|
||||||
|
buffer.rewind
|
||||||
|
buffer.read
|
||||||
|
end
|
||||||
|
|
||||||
namespace :apache do
|
namespace :apache do
|
||||||
desc "Create all defined configs for the specified environment"
|
desc "Create all defined configs for the specified environment"
|
||||||
task :create, :environment do |t, args|
|
task :create, :environment do |t, args|
|
||||||
@ -21,12 +30,22 @@ namespace :apache do
|
|||||||
FileUtils.mkdir_p config[:destination_path]
|
FileUtils.mkdir_p config[:destination_path]
|
||||||
Dir.chdir config[:destination_path]
|
Dir.chdir config[:destination_path]
|
||||||
|
|
||||||
# using CONFIG is deprecated
|
|
||||||
CONFIG = config
|
CONFIG = config
|
||||||
|
|
||||||
|
ENVIRONMENT_CONFIG = (config[:environments][APACHE_ENV] rescue nil)
|
||||||
|
|
||||||
Dir[File.join(config[:source_path], '**', '*.rb')].each do |file|
|
Dir[File.join(config[:source_path], '**', '*.rb')].each do |file|
|
||||||
puts file.foreground(:green)
|
Apache::Config.reset!
|
||||||
require file
|
output = capture_stdout { require file }
|
||||||
|
|
||||||
|
if Apache::Config.written?
|
||||||
|
if Apache::Config.disabled?
|
||||||
|
puts file.foreground(:blue)
|
||||||
|
else
|
||||||
|
puts file.foreground(:green)
|
||||||
|
end
|
||||||
|
puts output
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
symlink_configs!
|
symlink_configs!
|
||||||
|
@ -1,12 +1,13 @@
|
|||||||
require 'yaml'
|
require 'yaml'
|
||||||
require 'fileutils'
|
require 'fileutils'
|
||||||
|
require 'apache/hash'
|
||||||
|
|
||||||
module Apache
|
module Apache
|
||||||
module Rake
|
module Rake
|
||||||
module Support
|
module Support
|
||||||
def config
|
def config
|
||||||
if !@config
|
if !@config
|
||||||
@config = Hash[YAML.load_file('config.yml').collect { |k,v| [ k.to_sym, v ] }]
|
@config = YAML.load_file('config.yml').to_sym_keys
|
||||||
config_paths!
|
config_paths!
|
||||||
|
|
||||||
class << @config
|
class << @config
|
||||||
|
5
skel/Gemfile
Normal file
5
skel/Gemfile
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
source :rubygems
|
||||||
|
|
||||||
|
gem 'apache-config-generator', '>= 0.2.7'
|
||||||
|
gem 'rake'
|
||||||
|
|
@ -1,4 +1 @@
|
|||||||
require 'rubygems'
|
require 'apache/rake/apache/create'
|
||||||
|
|
||||||
require 'apache-config-generator'
|
|
||||||
require 'apache/rake/create'
|
|
||||||
|
@ -36,12 +36,14 @@ describe Apache::Config, "builds configurations" do
|
|||||||
describe '.disable_symlink!' do
|
describe '.disable_symlink!' do
|
||||||
context 'is enabled by default' do
|
context 'is enabled by default' do
|
||||||
it { apache.instance_variable_get(:@is_disabled).should be_false }
|
it { apache.instance_variable_get(:@is_disabled).should be_false }
|
||||||
|
it { apache.disabled?.should be_false }
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'disable' do
|
context 'disable' do
|
||||||
before { apache.disable_symlink! }
|
before { apache.disable_symlink! }
|
||||||
|
|
||||||
it { apache.instance_variable_get(:@is_disabled).should be_true }
|
it { apache.instance_variable_get(:@is_disabled).should be_true }
|
||||||
|
it { apache.disabled?.should be_true }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -110,9 +112,13 @@ describe Apache::Config, "builds configurations" do
|
|||||||
end
|
end
|
||||||
|
|
||||||
it "should handle a build" do
|
it "should handle a build" do
|
||||||
|
apache.written?.should be_false
|
||||||
|
|
||||||
FileUtils.mkdir_p 'test'
|
FileUtils.mkdir_p 'test'
|
||||||
apache.build('test/fake.conf') { my_test "this" }.should == [ 'MyTest "this"' ]
|
apache.build('test/fake.conf') { my_test "this" }.should == [ 'MyTest "this"' ]
|
||||||
FileUtils.rm 'test/fake.conf'
|
FileUtils.rm 'test/fake.conf'
|
||||||
|
|
||||||
|
apache.written?.should be_true
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should handle building if the environment is correct" do
|
it "should handle building if the environment is correct" do
|
||||||
|
36
spec/apache/hash_spec.rb
Normal file
36
spec/apache/hash_spec.rb
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
require 'spec_helper'
|
||||||
|
require 'lib/apache/hash'
|
||||||
|
|
||||||
|
describe Hash do
|
||||||
|
describe '#to_sym_keys' do
|
||||||
|
subject { test_hash.to_sym_keys }
|
||||||
|
|
||||||
|
context 'no nested hashes' do
|
||||||
|
let(:test_hash) { {
|
||||||
|
'hello' => 'goodbye',
|
||||||
|
:other => 'this'
|
||||||
|
} }
|
||||||
|
|
||||||
|
it { should == {
|
||||||
|
:hello => 'goodbye',
|
||||||
|
:other => 'this'
|
||||||
|
} }
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'nested hash' do
|
||||||
|
let(:test_hash) { {
|
||||||
|
'hello' => 'goodbye',
|
||||||
|
:other => {
|
||||||
|
'this' => 'that'
|
||||||
|
}
|
||||||
|
} }
|
||||||
|
|
||||||
|
it { should == {
|
||||||
|
:hello => 'goodbye',
|
||||||
|
:other => {
|
||||||
|
:this => 'that'
|
||||||
|
}
|
||||||
|
} }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in New Issue
Block a user