bincache 0.0.4 → 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/VERSION +1 -1
- data/bin/bincache +1 -1
- data/bincache.gemspec +1 -1
- data/lib/bincache.rb +15 -7
- metadata +3 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.5
|
data/bin/bincache
CHANGED
data/bincache.gemspec
CHANGED
data/lib/bincache.rb
CHANGED
@@ -7,7 +7,8 @@ require 'right_aws'
|
|
7
7
|
class BinCache
|
8
8
|
|
9
9
|
def initialize()
|
10
|
-
|
10
|
+
## set cache_dir to'/var/tmp/bincache' or ENV['BINCACHE_DIR'] if it is set
|
11
|
+
@cache_dir = (ENV['BINCACHE_DIR'] && ENV['BINCACHE_DIR']) || '/var/tmp/bincache'
|
11
12
|
|
12
13
|
print_and_exit "s3 keys not set. Please set S3_BUCKET and S3_PREFIX" unless ENV['S3_BUCKET'] && ENV['S3_PREFIX']
|
13
14
|
@bucket = ENV['S3_BUCKET']
|
@@ -28,7 +29,7 @@ class BinCache
|
|
28
29
|
`rm -rf #{directory} && mkdir -p #{directory}` && return if scripts.empty?
|
29
30
|
|
30
31
|
## hash the scripts
|
31
|
-
hash = Digest::MD5.hexdigest(scripts.inspect)
|
32
|
+
hash = Digest::MD5.hexdigest("#{directory.inspect}#{scripts.inspect}")
|
32
33
|
|
33
34
|
## pop the last script
|
34
35
|
pop = scripts.pop
|
@@ -41,6 +42,9 @@ class BinCache
|
|
41
42
|
end
|
42
43
|
|
43
44
|
def check_for_hash?(hash)
|
45
|
+
## return true if the hash is already on our local fs
|
46
|
+
return true if File.exists?(File.join(@cache_dir,hash))
|
47
|
+
|
44
48
|
key = RightAws::S3::Key.create( @right_s3_bucket, "#{@prefix}#{hash}" )
|
45
49
|
key.exists?
|
46
50
|
end
|
@@ -48,13 +52,13 @@ class BinCache
|
|
48
52
|
def step(script,directory,hash)
|
49
53
|
if download_hash? hash
|
50
54
|
`rm -rf #{directory}`
|
51
|
-
`cd #{File.dirname directory} && tar -xzvf #{File.join(@
|
55
|
+
`cd #{File.dirname directory} && tar -xzvf #{File.join(@cache_dir,hash)} `
|
52
56
|
else
|
53
|
-
`mkdir -p #{directory}`
|
57
|
+
`mkdir -p #{directory} #{@cache_dir}`
|
54
58
|
Dir.chdir directory
|
55
59
|
res = `#{script}`
|
56
|
-
`cd #{File.dirname directory} && tar -czvf #{@
|
57
|
-
upload_file("#{@
|
60
|
+
`cd #{File.dirname directory} && tar -czvf #{@cache_dir}/#{hash} #{File.basename directory} `
|
61
|
+
upload_file("#{@cache_dir}/#{hash}")
|
58
62
|
end
|
59
63
|
end
|
60
64
|
|
@@ -69,8 +73,12 @@ class BinCache
|
|
69
73
|
end
|
70
74
|
|
71
75
|
def download_hash?(hash)
|
76
|
+
## return true if the hash is already on our local fs
|
77
|
+
return true if File.exists?(File.join(@cache_dir,hash))
|
78
|
+
|
79
|
+
## attempt to download the hash from s3
|
72
80
|
begin
|
73
|
-
File.open(File.join(@
|
81
|
+
File.open(File.join(@cache_dir,hash) , 'w') {|f| f.write( @right_s3_interface.get_object(@bucket, "#{@prefix}#{hash}") ) }
|
74
82
|
rescue
|
75
83
|
return false
|
76
84
|
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: 21
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 5
|
10
|
+
version: 0.0.5
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Martin Rhoads
|