bincache 0.0.7 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +43 -5
- data/VERSION +1 -1
- data/bin/bincache +0 -0
- data/bincache.gemspec +2 -2
- data/lib/bincache.rb +18 -12
- data/lib/bincache/provider/bincache.rb +1 -1
- data/lib/bincache/resource/bincache.rb +18 -3
- metadata +4 -4
data/README.rdoc
CHANGED
@@ -1,13 +1,42 @@
|
|
1
1
|
= bincache
|
2
2
|
|
3
|
-
BinCache is a system designed to chache compiled binaries. It has resources for bash, ruby and chef.
|
3
|
+
BinCache is a system designed to chache compiled binaries on S3. It has resources for bash, ruby and chef.
|
4
4
|
|
5
|
-
|
5
|
+
BinCache tracks a single directory and a series of scripts. After each script is run, the contents of the directory is cached on s3. On sequential runs, the scripts are not re-executed, but instead the cache from S3 is downloaded and placed in the directory. If a script is changed, itself and all following scripts will be re-executed. BinCache does this by hashing the current script together with all previous scripts ran and storing the resulting cache in S3 with that hash as it's name. By ensuring that scripts contain markers to introduce uniquness on different systems, you can make sure that you never have to wait twice for something to compile!
|
6
|
+
|
7
|
+
== Install
|
8
|
+
|
9
|
+
## add rubygems.org to your gem sources list if it is not already there
|
10
|
+
gem sources -a https://rubygems.org
|
6
11
|
|
7
|
-
|
12
|
+
|
13
|
+
## install bincache
|
8
14
|
gem install bincache
|
9
15
|
|
10
16
|
|
17
|
+
== Environment
|
18
|
+
|
19
|
+
Make sure you set the environment variables with something like:
|
20
|
+
|
21
|
+
## S3 access key id
|
22
|
+
export BINCACHE_S3_ACCESS_KEY=1234567890ABCDEFGHIJ
|
23
|
+
|
24
|
+
## S3 secret access key
|
25
|
+
export BINCACHE_S3_SECRET_KEY=1234567890ABCDEFHIJKLMNOPQRSTUVWXYZ12345
|
26
|
+
|
27
|
+
## S3 bucket
|
28
|
+
export BINCACHE_S3_BUCKET=my_ec2_bucket
|
29
|
+
|
30
|
+
## prefix inside bucket to store caches
|
31
|
+
export BINCACHE_S3_PREFIX=my_bincache/
|
32
|
+
|
33
|
+
|
34
|
+
== Bash example
|
35
|
+
|
36
|
+
## you may have to put rubygem bins in your path by doing something like..
|
37
|
+
export PATH=$HOME/.gem/ruby/1.8/bin:$PATH
|
38
|
+
|
39
|
+
|
11
40
|
## set the directory to cache
|
12
41
|
dir=/tmp/bincache
|
13
42
|
|
@@ -54,7 +83,7 @@ BinCache is a system designed to chache compiled binaries. It has resources for
|
|
54
83
|
|
55
84
|
## run bincache
|
56
85
|
bincache = BinCache.new
|
57
|
-
bincache.
|
86
|
+
bincache.run_series(dir,scripts)
|
58
87
|
|
59
88
|
== Chef example
|
60
89
|
|
@@ -76,7 +105,16 @@ BinCache is a system designed to chache compiled binaries. It has resources for
|
|
76
105
|
EOS
|
77
106
|
end
|
78
107
|
|
79
|
-
|
108
|
+
|
109
|
+
== uniquness example
|
110
|
+
|
111
|
+
To tag a script with something unique to ensure that it is distingushible on multiple systems, you need to insert something unique into the comments. For example, you could do:
|
112
|
+
|
113
|
+
echo "I am showing you how to uniqueify your script" > example
|
114
|
+
## #{`uname -m`}
|
115
|
+
## #{`lsb_release -ds`
|
116
|
+
|
117
|
+
When this script is hashed, it will produce different values on different systems. With this technique, you can cache different binaries from different systems with the same code base!
|
80
118
|
|
81
119
|
== Copyright
|
82
120
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.8
|
data/bin/bincache
CHANGED
File without changes
|
data/bincache.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{bincache}
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.8"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Martin Rhoads"]
|
12
|
-
s.date = %q{2010-10-
|
12
|
+
s.date = %q{2010-10-18}
|
13
13
|
s.default_executable = %q{bincache}
|
14
14
|
s.description = %q{
|
15
15
|
BinCache is a system designed to cache compiled binaries. It has support for bash, ruby , and chef.
|
data/lib/bincache.rb
CHANGED
@@ -18,26 +18,31 @@ class BinCache
|
|
18
18
|
## set cache_dir to'/var/tmp/bincache' or ENV['BINCACHE_DIR'] if it is set
|
19
19
|
@cache_dir = (ENV['BINCACHE_DIR'] && ENV['BINCACHE_DIR']) || '/var/tmp/bincache'
|
20
20
|
|
21
|
-
print_and_exit "
|
22
|
-
@bucket = ENV['
|
23
|
-
@prefix = ENV['
|
21
|
+
print_and_exit "S3 bucket and path not set. Please set BINCACHE_S3_BUCKET and BINCACHE_S3_PREFIX" unless ENV['BINCACHE_S3_BUCKET'] && ENV['BINCACHE_S3_PREFIX']
|
22
|
+
@bucket = ENV['BINCACHE_S3_BUCKET']
|
23
|
+
@prefix = ENV['BINCACHE_S3_PREFIX']
|
24
24
|
|
25
25
|
|
26
|
-
print_and_exit "
|
27
|
-
@right_s3 = RightAws::S3.new(ENV['
|
26
|
+
print_and_exit "S3 keys not set. Please set BINCACHE_S3_ACCESS_KEY and BINCACHE_S3_SECRET_KEY" unless ENV['BINCACHE_S3_ACCESS_KEY'] && ENV['BINCACHE_S3_SECRET_KEY']
|
27
|
+
@right_s3 = RightAws::S3.new(ENV['BINCACHE_S3_ACCESS_KEY'],ENV['BINCACHE_S3_SECRET_KEY'])
|
28
28
|
@right_s3_bucket = @right_s3.bucket(@bucket)
|
29
|
-
@right_s3_interface = RightAws::S3Interface.new(ENV['
|
29
|
+
@right_s3_interface = RightAws::S3Interface.new(ENV['BINCACHE_S3_ACCESS_KEY'],ENV['BINCACHE_S3_SECRET_KEY'])
|
30
30
|
end
|
31
31
|
|
32
|
-
def run_series(directory, scripts)
|
32
|
+
def run_series(directory, scripts, cwd=nil, script_hash=nil)
|
33
33
|
## exit if given bogus input
|
34
34
|
print_and_exit "bogus input in run_series" if directory.nil? || scripts.nil?
|
35
35
|
|
36
36
|
## clear out directory if we are starting a new sequence
|
37
37
|
`rm -rf #{directory} && mkdir -p #{directory}` && return if scripts.empty?
|
38
38
|
|
39
|
-
## hash the scripts
|
40
|
-
|
39
|
+
## hash the scripts together with the output of the script_hash
|
40
|
+
script_hash_output = ""
|
41
|
+
script_hash_output = `#{script_hash}` unless script_hash == nil
|
42
|
+
|
43
|
+
STDERR.puts "script_hash_output = #{script_hash_output}"
|
44
|
+
|
45
|
+
hash = Digest::MD5.hexdigest("#{directory.inspect}#{scripts.inspect}#{script_hash_output}")
|
41
46
|
|
42
47
|
## pop the last script
|
43
48
|
pop = scripts.pop
|
@@ -46,7 +51,7 @@ class BinCache
|
|
46
51
|
eval("#{__method__}(directory,scripts)") unless check_for_hash?(hash)
|
47
52
|
|
48
53
|
## step this script
|
49
|
-
step(pop,directory,hash)
|
54
|
+
step(pop,directory,hash,cwd)
|
50
55
|
end
|
51
56
|
|
52
57
|
def check_for_hash?(hash)
|
@@ -57,13 +62,14 @@ class BinCache
|
|
57
62
|
key.exists?
|
58
63
|
end
|
59
64
|
|
60
|
-
def step(script,directory,hash)
|
65
|
+
def step(script,directory,hash,cwd=nil)
|
61
66
|
if download_hash? hash
|
62
67
|
`rm -rf #{directory}`
|
63
68
|
`cd #{File.dirname directory} && tar -xzvf #{File.join(@cache_dir,hash)} `
|
64
69
|
else
|
65
70
|
`mkdir -p #{directory} #{@cache_dir}`
|
66
|
-
Dir.chdir
|
71
|
+
Dir.chdir cwd unless cwd == nil
|
72
|
+
puts "pwd = #{`pwd`}"
|
67
73
|
res = `#{script}`
|
68
74
|
`cd #{File.dirname directory} && tar -czvf #{@cache_dir}/#{hash} #{File.basename directory} `
|
69
75
|
upload_file("#{@cache_dir}/#{hash}")
|
@@ -1,8 +1,5 @@
|
|
1
1
|
require 'chef/resource'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
3
|
class Chef
|
7
4
|
class Resource
|
8
5
|
class Bincache < Chef::Resource
|
@@ -14,6 +11,7 @@ class Chef
|
|
14
11
|
@allowed_actions.push(:run)
|
15
12
|
end
|
16
13
|
|
14
|
+
|
17
15
|
def script(arg=nil)
|
18
16
|
set_or_return(
|
19
17
|
:script,
|
@@ -30,6 +28,23 @@ class Chef
|
|
30
28
|
:kind_of => String
|
31
29
|
)
|
32
30
|
end
|
31
|
+
|
32
|
+
|
33
|
+
def cwd(arg=nil)
|
34
|
+
set_or_return(
|
35
|
+
:cwd,
|
36
|
+
arg,
|
37
|
+
:kind_of => String
|
38
|
+
)
|
39
|
+
end
|
40
|
+
|
41
|
+
def script_hash(arg=nil)
|
42
|
+
set_or_return(
|
43
|
+
:script_hash,
|
44
|
+
arg,
|
45
|
+
:kind_of => String
|
46
|
+
)
|
47
|
+
end
|
33
48
|
|
34
49
|
end
|
35
50
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bincache
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 15
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 8
|
10
|
+
version: 0.0.8
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Martin Rhoads
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-10-
|
18
|
+
date: 2010-10-18 00:00:00 -07:00
|
19
19
|
default_executable: bincache
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|