forked from benhoskings/babushka-deps
-
Notifications
You must be signed in to change notification settings - Fork 0
/
babushka.me.rb
75 lines (70 loc) · 1.59 KB
/
babushka.me.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
meta :bab_tarball do
def uri
'git://github.com/benhoskings/babushka.git'
end
def latest
var(:tarball_path) / 'LATEST'
end
def tarball_for commit_id
var(:tarball_path) / "babushka-#{commit_id}.tgz"
end
def current_head
in_build_dir 'babushka' do
`git rev-parse --short HEAD`.strip
end
end
end
dep 'babushka tarball' do
requires 'linked.bab_tarball', 'LATEST.bab_tarball'
setup {
set :tarball_path, './public/tarballs'.p
}
end
dep 'LATEST.bab_tarball' do
met? {
latest.exists? && (latest.read.strip == current_head)
}
meet {
shell "echo #{current_head} > '#{latest}'"
}
end
dep 'linked.bab_tarball' do
requires 'exists.bab_tarball'
setup {
git uri, :dir => 'babushka'
}
met? {
(var(:tarball_path) / 'babushka.tgz').readlink == tarball_for(current_head)
}
meet {
cd var(:tarball_path), :create => true do
shell "ln -sf #{tarball_for(current_head)} babushka.tgz"
end
}
end
dep 'exists.bab_tarball' do
met? {
shell "tar -t -f #{tarball_for(current_head)}"
}
before { shell "mkdir -p #{tarball_for(current_head).parent}" }
meet {
in_build_dir do
shell "tar -zcv --exclude .git -f '#{tarball_for(current_head)}' babushka/"
end
}
end
dep 'babushka.me db dump' do
def db_dump_path
'./public/db'.p
end
def db_dump
db_dump_path / 'babushka.me.psql'
end
met? {
db_dump.exists? && (db_dump.mtime + 300 > Time.now) # less than 5 minutes old
}
before { db_dump_path.mkdir }
meet {
shell "pg_dump babushka.me > '#{db_dump}.tmp' && mv '#{db_dump}.tmp' '#{db_dump}'"
}
end