Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
AntonyBlakey committed Feb 4, 2009
0 parents commit 306c2f5
Show file tree
Hide file tree
Showing 19 changed files with 811 additions and 0 deletions.
74 changes: 74 additions & 0 deletions Rakefile
@@ -0,0 +1,74 @@
# Not enough time right now to do this

MODULES = %w(memetic spidermonkey icu erlang pcre lighttpd couchdb)

desc "Build all of the modules"
task :build do
# TODO: read some docs to find a better way to do this
# when I have some time.
MODULES.each do |m|
Dir.chdir("modules/#{m}")
begin
sh "rake"
ensure
Dir.chdir('../..')
end
end
end

desc "Remove the test-db"
task :remove_test_db do
sh 'rm -rf test-db'
end

desc "Start CouchDB using gems"
task :start_couchdb do
require "rubygems"
require "memetic-couchdb"
db = Memetic::CouchDB.new("#{Dir.pwd}/test-db")
puts db.start
end

desc "Get status of running CouchDB using gems"
task :status_couchdb do
require "rubygems"
require "memetic-couchdb"
db = Memetic::CouchDB.new("#{Dir.pwd}/test-db")
puts db.status
end

desc "Stop CouchDB using gems"
task :stop_couchdb do
require "rubygems"
require "memetic-couchdb"
db = Memetic::CouchDB.new("#{Dir.pwd}/test-db")
puts db.stop
end


task :live_modules do
MODULES.each do |m|
$LOAD_PATH << File.join(Dir.getwd, "modules", m, "lib")
end
end

desc "Start CouchDB using the live modules i.e. not gems"
task :start_live_couchdb => [ :live_modules ] do
require "memetic-couchdb"
db = Memetic::CouchDB.new("#{Dir.pwd}/test-db")
puts db.start
end

desc "Get status of running CouchDB using the live modules i.e. not gems"
task :status_live_couchdb => [ :live_modules ] do
require "memetic-couchdb"
db = Memetic::CouchDB.new("#{Dir.pwd}/test-db")
puts db.status
end

desc "Stop CouchDB using the live modules i.e. not gems"
task :stop_live_couchdb => [ :live_modules ] do
require "memetic-couchdb"
db = Memetic::CouchDB.new("#{Dir.pwd}/test-db")
puts db.stop
end
8 changes: 8 additions & 0 deletions application-template/install.sh
@@ -0,0 +1,8 @@
#!/bin/bash

pushd ${0%/*} > /dev/null
export GEM_HOME=$(pwd)/gems
popd > /dev/null

# Use a defined gem source
gem install -V --source http://localhost/~antony/GEM_SERVER/ my-app
7 changes: 7 additions & 0 deletions application-template/run.sh
@@ -0,0 +1,7 @@
#!/bin/bash

pushd ${0%/*} > /dev/null
export GEM_HOME=$(pwd)/gems
popd > /dev/null

ruby -e 'require "my-app"' -e 'MyApp.start'
9 changes: 9 additions & 0 deletions application-template/update.sh
@@ -0,0 +1,9 @@
#!/bin/bash

pushd ${0%/*} > /dev/null
export GEM_HOME=$(pwd)/gems
popd > /dev/null

# Use a defined gem source
gem update --source http://localhost/~antony/GEM_SERVER my-app
gem clean
112 changes: 112 additions & 0 deletions modules/couchdb/Rakefile
@@ -0,0 +1,112 @@
file "couchdb" => [] do
sh 'git clone git://github.com/halorgium/couchdb.git'
end

desc "Update to the latest version of git://github.com/halorgium/couchdb.git"
task :git_update do
Dir.chdir('couchdb')
begin
sh 'git pull'
ensure
Dir.chdir('..')
end
end

desc "Clean up as though this were a fresh distribution"
task :dist_clean => [ :clean ] do
sh 'rm -rf couchdb'
end

desc "Start from scratch"
task :clean do
sh 'rm -rf BUILD pkg'
end

directory "BUILD"

root = `( cd .. ; pwd )`.split[0]
icu = "#{root}/icu/BUILD"
erlang = "#{root}/erlang/BUILD"
spidermonkey = "#{root}/spidermonkey/BUILD"

env = "export ERLANG_ROOT='#{erlang}' ; "
env << "PATH=#{erlang}/bin:#{icu}/bin:/usr/bin:/bin:/usr/sbin:/sbin ; "
if RUBY_PLATFORM =~ /linux/
env << "export LD_LIBRARY_PATH='#{icu}/lib:#{spidermonkey}/lib' ; "
elsif RUBY_PLATFORM =~ /darwin/
env << "export DYLD_LIBRARY_PATH='#{icu}/lib:#{spidermonkey}/lib' ; "
end

prefix = Dir.getwd + "/BUILD"
desc "Build CouchDB"
task :build => [ :configure, :make ] do |t|
end

desc "Configure CouchDB"
task :configure => [ "BUILD", "couchdb" ] do |t|
Dir.chdir('couchdb')
begin
sh "#{env} ./bootstrap"
sh "#{env} ./configure --prefix=#{prefix} --with-js-include=#{spidermonkey}/include/js --with-js-lib=#{spidermonkey}/lib --with-erlang=#{erlang}/lib/erlang/usr/include"
ensure
Dir.chdir('..')
end
end

desc "Build CouchDB"
task :make => [ "BUILD" ] do |t|
Dir.chdir('couchdb')
begin
sh "#{env} make"
sh "#{env} make install"
ensure
Dir.chdir('..')
end

sh 'rm -rf BUILD/Library BUILD/etc/logrotate.d'

[ 'bin/couchdb', 'bin/couchjs', 'etc/couchdb/default.ini'].each do |f|
str = IO.read("#{prefix}/#{f}")
str.gsub!(prefix, ".")
str.gsub!("`#{icu}/bin/icu-config --invoke`", "")
str.gsub!("#{erlang}/bin/", "")
File.open("#{prefix}/#{f}", "w") do |io|
io.write(str)
end
end
end

desc "Run in-situ CouchDB"
task :run do
sh "#{env} ERLANG_ROOT=#{erlang} ; ( cd #{prefix} ; bin/couchdb )"
end

require 'rake/gempackagetask'

gem_spec = Gem::Specification.new do |s|
s.name = 'memetic-couchdb'
s.version = "0.8.#{Time.new.strftime('%Y%m%d')}"
s.summary = 'Memetic packaging of Couchdb'
s.platform = Gem::Platform::CURRENT
s.authors = ["Antony Blakey", "http://couchdb.org"]
s.files = FileList["Rakefile", "{BUILD,lib}/**/*"]
s.require_path = "lib"
# I'm going to presume that pcre versioning is rational
s.add_dependency("memetic", "~> 1.0")
s.add_dependency("memetic-erlang", "~> 5.6")
s.add_dependency("memetic-spidermonkey", ">= 1.7", "< 1.8")
s.add_dependency("memetic-icu", "~> 4.0")
end

desc "Create the gem"
Rake::GemPackageTask.new(gem_spec) do |pkg|
pkg.need_zip = false
pkg.need_tar = false
end

directory "../../GEM_SERVER/gems/"

desc "Build the gem, move to ../../GEM_SERVER/gems/"
task :default => [ :build, :gem, "../../GEM_SERVER/gems/"] do
sh "mv pkg/*.gem ../../GEM_SERVER/gems/"
end
84 changes: 84 additions & 0 deletions modules/couchdb/lib/memetic-couchdb.rb
@@ -0,0 +1,84 @@
require 'memetic'
require 'memetic-erlang'
require 'memetic-spidermonkey'
require 'memetic-icu'

module Memetic

class CouchDB

DIRECTORY = %x{cd #{File.dirname(File.dirname(__FILE__)) + "/BUILD"} ; pwd}.split()[0]

def CouchDB.configure_environment(env)
Erlang.configure_environment(env)
Spidermonkey.configure_environment(env)
ICU.configure_environment(env)
end

# TODO: set a port to enable multiple concurrent instances
def initialize(local_directory)
@local_directory = local_directory
Dir.mkdir(@local_directory) unless File.exists?(@local_directory)

@log_directory = "#{@local_directory}/log"
Dir.mkdir(@log_directory) unless File.exists?(@log_directory)

@data_directory = "#{@local_directory}/data"
Dir.mkdir(@data_directory) unless File.exists?(@data_directory)

File.open("#{@local_directory}/configuration.ini", "w") do |f|
f << configuration()
end
end

def start
env = Environment.new
CouchDB.configure_environment(env)
cmd = env.as_command_prefix
cmd << "( cd '#{DIRECTORY}' ; "
cmd << "./bin/couchdb -b "
cmd << "-o '#{@log_directory}/couchdb.stdout' "
cmd << "-e '#{@log_directory}/couchdb.stderr' "
cmd << "-p '#{@local_directory}/pid' "
cmd << "-c './etc/couchdb/default.ini' "
cmd << "-c '#{@local_directory}/configuration.ini' "
cmd << " )"
s = ""
IO.popen(cmd) do |p|
s = p.gets
s.chomp if s
end
end

def status
env = Environment.new
CouchDB.configure_environment(env)
IO.popen("#{env.as_command_prefix} #{DIRECTORY}/bin/couchdb -p #{@local_directory}/pid -s") do |p|
s = p.gets
s.chomp if s
end
end

def stop
env = Environment.new
CouchDB.configure_environment(env)
IO.popen("#{env.as_command_prefix} #{DIRECTORY}/bin/couchdb -p #{@local_directory}/pid -d") do |p|
s = p.gets
s.chomp if s
end
end

def configuration
return <<END_OF_STRING
[couchdb]
database_dir = #{@data_directory}
[log]
file = #{@log_directory}/couch.log
level = debug
END_OF_STRING
end

end

end
80 changes: 80 additions & 0 deletions modules/erlang/Rakefile
@@ -0,0 +1,80 @@
raise "I can't handle this platform: #{RUBY_PLATFORM}" unless RUBY_PLATFORM =~ /darwin|linux/


file "otp_src_R12B-5.tar.gz" => [] do
sh 'curl -O http://www.erlang.org/download/otp_src_R12B-5.tar.gz'
end

file "otp_src_R12B-5_OTP-7738.patch" => [] do
sh 'curl -O http://www.erlang.org/download/patches/otp_src_R12B-5_OTP-7738.patch'
end

file "otp_src_R12B-5" => [ "otp_src_R12B-5.tar.gz", "otp_src_R12B-5_OTP-7738.patch" ] do |t|
sh "tar zxf otp_src_R12B-5.tar.gz"
sh "patch -ZNp0 < otp_src_R12B-5_OTP-7738.patch"
end

desc "Clean up as though this were a fresh distribution"
task :dist_clean => [ :clean ] do
sh 'rm otp_src_R12B-5.tar.gz otp_src_R12B-5_OTP-7738.patch'
end

desc "Clean everything"
task :clean do
sh 'rm -rf otp_src_R12B-5 BUILD pkg'
end

directory "BUILD"

desc "Build Erlang"
task :build => [ "otp_src_R12B-5", "BUILD" ] do |t|
env = "PATH=/usr/bin:/bin:/usr/sbin:/sbin ; "
if RUBY_PLATFORM =~ /darwin/
env << "DYLD_LIBRARY_PATH='' ; "
end
prefix = Dir.getwd + "/BUILD"
Dir.chdir("otp_src_R12B-5")
begin
sh "#{env} ./configure --prefix=#{prefix}"
sh "#{env} make"
sh "#{env} make install"
ensure
Dir.chdir('..')
end

# Now patch the built result to enable binary paths to be controlled by an environment variable
[ 'bin/erl', 'bin/start', 'erts-5.6.5/bin/erl', 'erts-5.6.5/bin/start', 'releases/RELEASES'].each do |f|
str = IO.read("BUILD/lib/erlang/#{f}")
str.gsub!(prefix, "$ERLANG_ROOT")
File.open("BUILD/lib/erlang/#{f}", "w") do |io|
io.write(str)
end
end

end

require 'rake/gempackagetask'

gem_spec = Gem::Specification.new do |s|
s.name = 'memetic-erlang'
s.version = '5.6.5'
s.summary = 'Memetic packaging of Erlang'
s.platform = Gem::Platform::CURRENT
s.authors = ["Antony Blakey", "http://www.erlang.org/"]
s.files = FileList["Rakefile", "lib/**/*", "BUILD/lib/**/*"]
s.require_path = "lib"
s.add_dependency("memetic", "~> 1.0")
end

desc "Create the gem"
Rake::GemPackageTask.new(gem_spec) do |pkg|
pkg.need_zip = false
pkg.need_tar = false
end

directory "../../GEM_SERVER/gems/"

desc "Build the gem, move to ../../GEM_SERVER/gems/"
task :default => [ :build, :gem, "../../GEM_SERVER/gems/"] do
sh "mv pkg/*.gem ../../GEM_SERVER/gems/"
end

0 comments on commit 306c2f5

Please sign in to comment.