isolate-lockdown 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Isolate +1 -0
- data/LICENSE.txt +20 -0
- data/README.textile +75 -0
- data/Rakefile +50 -0
- data/lib/isolate/lockdown.rb +20 -0
- data/lib/isolate/lockdown/rake.rb +84 -0
- metadata +91 -0
data/Isolate
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
gem 'isolate'
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2010 Luis Lavena.
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.textile
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
h1. Isolate-Lockdown
|
2
|
+
|
3
|
+
* "github.com/luislavena/isolate-lockdown":https://github.com/luislavena/isolate-lockdown
|
4
|
+
|
5
|
+
h2. Description
|
6
|
+
|
7
|
+
Isolate-Lockdown extends Isolate sandbox behavior with the goal of generating a monolithic directory to reduce startup time of your application.
|
8
|
+
|
9
|
+
h2. What?
|
10
|
+
|
11
|
+
Having several gems in Ruby's @$LOAD_PATH@ results in slow require. The more bigger your application (with more gems), the longer it will take to start up.
|
12
|
+
|
13
|
+
On Rails applications, you can see this performance problem once you deploy a new version of code to your server. When the application restart, it can take several seconds to respond to the first request.
|
14
|
+
|
15
|
+
h2. Requirements
|
16
|
+
|
17
|
+
Isolate, RubyGems and Rake (only for extraction)
|
18
|
+
|
19
|
+
h2. How to use it
|
20
|
+
|
21
|
+
Isolate-lockdown provides a rake task that allow easy execution from command line.
|
22
|
+
|
23
|
+
These instructions assume you already followed Isolate "instructions":https://github.com/jbarnette/isolate for using Isolate in your application.
|
24
|
+
|
25
|
+
h3. Depend on @isolate-lockdown@
|
26
|
+
|
27
|
+
Since you're using Isolate, you need to define your dependency on this extension, please add it:
|
28
|
+
|
29
|
+
bc. gem 'isolate-lockdown'
|
30
|
+
|
31
|
+
After that, early in your application Rakefile (after @isolate/now@)
|
32
|
+
|
33
|
+
bc. require 'isolate/lockdown'
|
34
|
+
|
35
|
+
h3. Using @isolate:lockdown@
|
36
|
+
|
37
|
+
Previous step will make available @isolate:lockdown@ rake task:
|
38
|
+
|
39
|
+
bc. rake isolate:lockdown[folder] # Lockdown isolated gems into folder (defaults 'tmp/lockdown')
|
40
|
+
|
41
|
+
Once you execute @isolate:lockdown@, it will extract your gems contents into the specified _folder_, also generating @paths.rb@ file that will look something like this:
|
42
|
+
|
43
|
+
bc. $:.unshift File.expand_path("tmp/lockdown/lib")
|
44
|
+
|
45
|
+
h3. Using the lockdown gems in your application
|
46
|
+
|
47
|
+
Now, you need to adapt the startup process of your application to use this generate file.
|
48
|
+
|
49
|
+
The following is a simple Rails 3 example:
|
50
|
+
|
51
|
+
bc.. lockdown = File.expand_path('../../tmp/lockdown/paths.rb', __FILE__)
|
52
|
+
unless File.exist?(lockdown)
|
53
|
+
# using Isolate (development)
|
54
|
+
require 'isolate/now'
|
55
|
+
require 'isolate/lockdown'
|
56
|
+
else
|
57
|
+
# using the lockdown (production)
|
58
|
+
require lockdown
|
59
|
+
end
|
60
|
+
|
61
|
+
h3. Avoid executing during development
|
62
|
+
|
63
|
+
Please remember that lockdown is aimed to be used or executed during deployment and should not be used during development, as it removes Isolate and itself from the equation.
|
64
|
+
|
65
|
+
Not depending on Isolate will render any update to your gem manifest (Isolate) useless. Prior reporting bugs, please remove @tmp/lockdown@ directory and try again.
|
66
|
+
|
67
|
+
h2. License
|
68
|
+
|
69
|
+
Copyright (c) 2010 Luis Lavena.
|
70
|
+
|
71
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
72
|
+
|
73
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
74
|
+
|
75
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
# prepend lib directory
|
2
|
+
$:.unshift File.expand_path('lib', File.dirname(__FILE__))
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'isolate/now'
|
6
|
+
rescue LoadError
|
7
|
+
abort "This project requires Isolate to work, please 'gem install isolate' first."
|
8
|
+
end
|
9
|
+
|
10
|
+
require 'isolate/lockdown'
|
11
|
+
require 'rubygems/package_task'
|
12
|
+
|
13
|
+
GEM_SPEC = Gem::Specification.new do |s|
|
14
|
+
# basic information
|
15
|
+
s.name = 'isolate-lockdown'
|
16
|
+
s.version = '0.3.0'
|
17
|
+
s.platform = Gem::Platform::RUBY
|
18
|
+
|
19
|
+
# description and details
|
20
|
+
s.summary = 'Lockdown your isolated gems, give them speed.'
|
21
|
+
s.description = "Extension for Isolate that extracts dependent gem contents\ninto a single, monolithic directory to reduce Ruby load time."
|
22
|
+
|
23
|
+
# requirements
|
24
|
+
s.required_ruby_version = ">= 1.8.6"
|
25
|
+
s.required_rubygems_version = ">= 1.3.7"
|
26
|
+
|
27
|
+
# dependencies
|
28
|
+
s.add_dependency 'isolate'
|
29
|
+
|
30
|
+
# components, files and paths
|
31
|
+
s.files = FileList["lib/**/*.rb", "Rakefile", "Isolate", "*.{textile,txt}"]
|
32
|
+
|
33
|
+
s.require_path = 'lib'
|
34
|
+
|
35
|
+
# documentation
|
36
|
+
s.has_rdoc = false
|
37
|
+
|
38
|
+
# project information
|
39
|
+
s.homepage = 'http://github.com/luislavena/isolate-lockdown'
|
40
|
+
s.licenses = ['MIT']
|
41
|
+
|
42
|
+
# author and contributors
|
43
|
+
s.author = 'Luis Lavena'
|
44
|
+
s.email = 'luislavena@gmail.com'
|
45
|
+
end
|
46
|
+
|
47
|
+
Gem::PackageTask.new(GEM_SPEC) do |pkg|
|
48
|
+
pkg.need_tar = false
|
49
|
+
pkg.need_zip = false
|
50
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'isolate'
|
2
|
+
require 'isolate/lockdown/rake' if defined?(Rake)
|
3
|
+
|
4
|
+
module Isolate::Lockdown
|
5
|
+
# Adapt from Isolate own source code
|
6
|
+
def legitimize!(deps)
|
7
|
+
specs = []
|
8
|
+
|
9
|
+
deps.flatten.each do |dep|
|
10
|
+
spec = Gem.source_index.find_name(dep.name, dep.requirement).last
|
11
|
+
|
12
|
+
if spec
|
13
|
+
specs.concat legitimize!(spec.runtime_dependencies)
|
14
|
+
specs << spec
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
specs.uniq
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
namespace :isolate do
|
2
|
+
desc "Lockdown isolated gems into folder (defaults 'tmp/lockdown')"
|
3
|
+
task :lockdown, [:folder] do |t, args|
|
4
|
+
include Isolate::Lockdown
|
5
|
+
|
6
|
+
args.with_defaults(:folder => 'tmp/lockdown')
|
7
|
+
|
8
|
+
folder = args.folder
|
9
|
+
safe_folder = "#{folder}.safe"
|
10
|
+
temp_folder = "#{folder}.#{$$}"
|
11
|
+
loader_script = File.join(folder, 'paths.rb')
|
12
|
+
|
13
|
+
# remove previous safe folder if exists
|
14
|
+
when_writing "Removing previous safe folder" do
|
15
|
+
FileUtils.rm_rf safe_folder if File.exist?(safe_folder)
|
16
|
+
end
|
17
|
+
|
18
|
+
# collect entries valid for current environment
|
19
|
+
entries = Isolate.sandbox.entries.find_all { |e| e.matches?(Isolate.env) }
|
20
|
+
|
21
|
+
# determine which specs are really needed
|
22
|
+
specs = legitimize!(entries)
|
23
|
+
|
24
|
+
# collect gem lib dir to be used for require
|
25
|
+
require_paths = []
|
26
|
+
|
27
|
+
specs.each do |spec|
|
28
|
+
$stdout.puts "Locking down #{spec.name} #{spec.version}" if
|
29
|
+
Rake.application.options.trace
|
30
|
+
|
31
|
+
base = spec.full_gem_path
|
32
|
+
|
33
|
+
spec.add_bindir(spec.executables).each do |exe|
|
34
|
+
bin_dir = File.join(temp_folder, 'bin')
|
35
|
+
full_exe = File.join(base, exe)
|
36
|
+
|
37
|
+
FileUtils.mkdir_p(bin_dir) unless File.exist?(bin_dir)
|
38
|
+
FileUtils.cp full_exe, bin_dir
|
39
|
+
end
|
40
|
+
|
41
|
+
spec.require_paths.each do |path|
|
42
|
+
# do not add bindir to load path
|
43
|
+
next if path == spec.bindir
|
44
|
+
|
45
|
+
lib_dir = File.join(temp_folder, path)
|
46
|
+
require_paths << File.join(folder, path)
|
47
|
+
|
48
|
+
FileUtils.mkdir_p(lib_dir)
|
49
|
+
|
50
|
+
glob = File.join(base, path, '*')
|
51
|
+
Dir.glob(glob).each do |full_lib|
|
52
|
+
if File.file?(full_lib)
|
53
|
+
FileUtils.cp(full_lib, lib_dir)
|
54
|
+
else
|
55
|
+
FileUtils.cp_r(full_lib, lib_dir)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
# show some progress with big list of gems
|
61
|
+
unless Rake.application.options.trace
|
62
|
+
$stdout.print "."
|
63
|
+
$stdout.flush
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
FileUtils.mv(folder, safe_folder) if File.exist?(folder)
|
68
|
+
|
69
|
+
# Avoid permission denied issues under Windows
|
70
|
+
sleep(1) if RbConfig::CONFIG['host_os'] =~ /mswin|mingw/
|
71
|
+
|
72
|
+
FileUtils.mv(temp_folder, folder)
|
73
|
+
|
74
|
+
when_writing("Updating #{loader_script}") do
|
75
|
+
File.open(loader_script, 'w') do |f|
|
76
|
+
require_paths.uniq.each do |path|
|
77
|
+
f.puts "$:.unshift File.expand_path(#{path.inspect})"
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
$stdout.puts
|
83
|
+
end
|
84
|
+
end
|
metadata
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: isolate-lockdown
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 19
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 3
|
9
|
+
- 0
|
10
|
+
version: 0.3.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Luis Lavena
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-12-24 00:00:00 -03:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: isolate
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 3
|
30
|
+
segments:
|
31
|
+
- 0
|
32
|
+
version: "0"
|
33
|
+
type: :runtime
|
34
|
+
version_requirements: *id001
|
35
|
+
description: |-
|
36
|
+
Extension for Isolate that extracts dependent gem contents
|
37
|
+
into a single, monolithic directory to reduce Ruby load time.
|
38
|
+
email: luislavena@gmail.com
|
39
|
+
executables: []
|
40
|
+
|
41
|
+
extensions: []
|
42
|
+
|
43
|
+
extra_rdoc_files: []
|
44
|
+
|
45
|
+
files:
|
46
|
+
- lib/isolate/lockdown/rake.rb
|
47
|
+
- lib/isolate/lockdown.rb
|
48
|
+
- Rakefile
|
49
|
+
- Isolate
|
50
|
+
- README.textile
|
51
|
+
- LICENSE.txt
|
52
|
+
has_rdoc: true
|
53
|
+
homepage: http://github.com/luislavena/isolate-lockdown
|
54
|
+
licenses:
|
55
|
+
- MIT
|
56
|
+
post_install_message:
|
57
|
+
rdoc_options: []
|
58
|
+
|
59
|
+
require_paths:
|
60
|
+
- lib
|
61
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
62
|
+
none: false
|
63
|
+
requirements:
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
hash: 59
|
67
|
+
segments:
|
68
|
+
- 1
|
69
|
+
- 8
|
70
|
+
- 6
|
71
|
+
version: 1.8.6
|
72
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
hash: 21
|
78
|
+
segments:
|
79
|
+
- 1
|
80
|
+
- 3
|
81
|
+
- 7
|
82
|
+
version: 1.3.7
|
83
|
+
requirements: []
|
84
|
+
|
85
|
+
rubyforge_project:
|
86
|
+
rubygems_version: 1.3.7
|
87
|
+
signing_key:
|
88
|
+
specification_version: 3
|
89
|
+
summary: Lockdown your isolated gems, give them speed.
|
90
|
+
test_files: []
|
91
|
+
|