Skip to content

Commit

Permalink
First. No hooks.
Browse files Browse the repository at this point in the history
  • Loading branch information
jbarnette committed Sep 12, 2010
0 parents commit 976d7bd
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
@@ -0,0 +1,4 @@
config/apache.conf
config/htpasswd
projects
public
70 changes: 70 additions & 0 deletions Rakefile
@@ -0,0 +1,70 @@
desc "Add a new repo."
task :add, [:repo, :name] => %w(env add:before)

desc "Start over."
task :clean do
File.read(".gitignore").split("\n").each { |f| rm_rf f }
end

desc "Remove a repo."
task :rm, [:name] => %w(env rm:before)

task :default do
puts "Hi! Read the README."
end

# No public tasks below here. If you're not using Passenger (or basic
# auth or whatever) you're probably going to want to start hacking
# somewhere around the :env and :templates tasks.

task "add:before", [:repo, :name] do |_, args|
repo = args.repo || abort("Need repo!")
name = args.name || File.basename(repo, ".git")
tasks = Rake::Task[:add].prerequisites

directory a("projects/#{name}/public")

file a("projects/#{name}/repo/.git") do |t|
mkdir_p dest = File.dirname(t.name)
sh "git clone #{repo} #{dest}"
end

file a("projects/#{name}/config.ru") do |t|
ln_s File.expand_path("config/config.ru"), t.name
end

file a("public/#{name}") do |t|
ln_s File.expand_path("projects/#{name}/public"), t.name
end

a :templates
end

task "rm:before", [:name] => :env do |_, args|
name = args.name || abort("Need name!")
%W(projects/#{name} public/#{name}).each { |n| rm_rf n }
Rake::Task[:rm].prerequisites << :templates
end

task :env => %w(config/htpasswd projects public)

task :templates do
require "erb"

@htpasswd = File.expand_path("config/htpasswd")
@projects = Dir["projects/*"].map { |d| File.basename d }

r "config/templates/apache.conf.erb", "config/apache.conf"
r "config/templates/index.html.erb", "public/index.html"
end

directory "projects"
directory "public"

file "config/htpasswd" do |t|
puts "Creating #{t.name} entry for #{ENV['USER']}."
sh "htpasswd -c config/htpasswd #{ENV['USER']}"
end

def a *t; Rake::Task[:add].prerequisites.concat t; t.first end
def r s, t; File.open(t,"wb"){|f|f<< ERB.new(File.read(s)).result} end
Empty file added config/config.ru
Empty file.
19 changes: 19 additions & 0 deletions config/templates/apache.conf.erb
@@ -0,0 +1,19 @@
<VirtualHost *:80>
DocumentRoot <%= @public %>
<% @projects.each do |name| %>
RackBaseURI /<%= name %>
<% end %>

PassengerMaxInstancesPerApp 1
PassengerMaxPoolSize <%= @projects.size %>

<Directory "/">
AuthName "Fortress"
AuthType Basic
AuthUserFile <%= @htpasswd %>
require valid-user
</Directory>

SetEnv RAILS_RELATIVE_URL_ROOT
</VirtualHost>
17 changes: 17 additions & 0 deletions config/templates/index.html.erb
@@ -0,0 +1,17 @@
<!DOCTYPE html>

<html>
<head>
<title>fuck you</title>
</head>

<body>
<h1>fuck you</h1>

<ul>
<% @projects.each do |p| %>
<li><a href="/<%= p %>"><%= p %></a></li>
<% end %>
</ul>
</body>
</html>

0 comments on commit 976d7bd

Please sign in to comment.