traveler 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +23 -0
- data/README.md +86 -0
- data/Rakefile +1 -0
- data/bin/traveler +4 -0
- data/lib/traveler/build.rb +6 -0
- data/lib/traveler/bundler.rb +90 -0
- data/lib/traveler/cli.rb +79 -0
- data/lib/traveler/config.rb +45 -0
- data/lib/traveler/core_ext.rb +17 -0
- data/lib/traveler/gem.rb +45 -0
- data/lib/traveler/prerequisites.rb +38 -0
- data/lib/traveler/runtime.rb +47 -0
- data/lib/traveler/util.rb +55 -0
- data/lib/traveler/wrapper.rb +44 -0
- data/lib/traveler.rb +57 -0
- data/skel/Gemfile +1 -0
- data/skel/Travelfile +45 -0
- data/skel/bundle.config +3 -0
- data/skel/wrapper.sh +17 -0
- data/traveler.gemspec +26 -0
- metadata +124 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b1ff89c249a9f86cae865f07b82adc05657b2a6e
|
4
|
+
data.tar.gz: ca6421f494b18df1f79e59765b1ef1c34e568496
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c9bfac3282c9170bbebcbb0a122bff6735a2ce60f16d7b8545dc58e9cb9fcf9a7e2d491f24d7200cd1f2707b7d43ab208c526e6f465db25731da7c6caa0cf112
|
7
|
+
data.tar.gz: 1b90291047bfc8691a9e34ae715ece6b05d5436007f67320af30c000a3674bb7bbf271aca47b0da945e700ac64dd257de5b58e4c278a7b6e534db7cf813db694
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
|
2
|
+
Copyright (c) 2015 Slee Woo
|
3
|
+
|
4
|
+
MIT License
|
5
|
+
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
7
|
+
a copy of this software and associated documentation files (the
|
8
|
+
"Software"), to deal in the Software without restriction, including
|
9
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
10
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
11
|
+
permit persons to whom the Software is furnished to do so, subject to
|
12
|
+
the following conditions:
|
13
|
+
|
14
|
+
The above copyright notice and this permission notice shall be
|
15
|
+
included in all copies or substantial portions of the Software.
|
16
|
+
|
17
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
18
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
19
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
20
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
21
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
22
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
23
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
|
2
|
+
# Traveler
|
3
|
+
**A nifty wrapper for Traveling Ruby**
|
4
|
+
|
5
|
+
Easily distribute your Ruby app to any Linux and/or OS X.
|
6
|
+
|
7
|
+
Traveler is about doing all hard work on packaging your Ruby apps into self-running containers using [Traveling Ruby](http://phusion.github.io/traveling-ruby/).
|
8
|
+
|
9
|
+
Not familiar with [Traveling Ruby](http://phusion.github.io/traveling-ruby/)?
|
10
|
+
Here are some [introductory materials](https://github.com/phusion/traveling-ruby#getting-started).
|
11
|
+
|
12
|
+
**Ok, what do i need to use Traveler?**
|
13
|
+
|
14
|
+
You'll need Ruby 2.1.x or 2.2.x installed on your system.
|
15
|
+
|
16
|
+
Why so?
|
17
|
+
|
18
|
+
Cause for now Traveling Ruby is distributing only these versions of Ruby and target containers should be built using same minor Ruby version.
|
19
|
+
|
20
|
+
Patch version may differ, but major and minor ones should match exactly.
|
21
|
+
|
22
|
+
## Install
|
23
|
+
|
24
|
+
```bash
|
25
|
+
$ gem install traveler
|
26
|
+
```
|
27
|
+
|
28
|
+
make sure to run `rbenv rehash` is you are using rbenv.
|
29
|
+
|
30
|
+
## Use
|
31
|
+
|
32
|
+
Traveler acts inside your app folder. It creates a `Travelfile` file and the `traveler` folder(name is configurable).
|
33
|
+
|
34
|
+
`Travelfile` is a Ruby file containing few configurations:
|
35
|
+
|
36
|
+
- `platforms`: specify what platforms your app should run on
|
37
|
+
- `wrapper`: define wrapper(s) that will allow to easily run your app
|
38
|
+
- `folder_name`: name of the folder that will hold the builds
|
39
|
+
- `traveling_ruby_version`: what version of Traveling Ruby to be used for builds
|
40
|
+
|
41
|
+
And that's pretty all about configuration.
|
42
|
+
|
43
|
+
To generate a Travelfile run:
|
44
|
+
|
45
|
+
```bash
|
46
|
+
$ traveler init
|
47
|
+
```
|
48
|
+
|
49
|
+
This will also generate a Gemfile if it does not exists.
|
50
|
+
|
51
|
+
Now add a wrapper in your Travelfile and run:
|
52
|
+
|
53
|
+
```bash
|
54
|
+
$ traveler build
|
55
|
+
```
|
56
|
+
|
57
|
+
After build is done your app can be uploaded to server and run accordingly.
|
58
|
+
|
59
|
+
E.g. if your app resides in /path/to/my/app and you defined a wrapper named `run` in Travelfile, you can run your app with `/path/to/my/app/run`
|
60
|
+
|
61
|
+
|
62
|
+
## Multiple Ruby versions
|
63
|
+
|
64
|
+
Target Ruby version will match the Ruby version the runtime was built on.
|
65
|
+
|
66
|
+
So if you are on Ruby 2.1.x Traveler will build a 2.1.5 runtime.
|
67
|
+
|
68
|
+
And if you switch to Ruby 2.2.x, Traveler will build a 2.2.0 runtime, without touching the 2.1.5 one.
|
69
|
+
|
70
|
+
So you can have multiple Ruby versions with same app.
|
71
|
+
|
72
|
+
To make use of them simply define multiple wrappers, each using a specific Ruby version.
|
73
|
+
|
74
|
+
## Contributors are highly welcome!
|
75
|
+
|
76
|
+
Would love to have some help with testing.
|
77
|
+
|
78
|
+
1. Fork it ( https://github.com/[my-github-username]/traveler/fork )
|
79
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
80
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
81
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
82
|
+
5. Create a new Pull Request
|
83
|
+
|
84
|
+
## License
|
85
|
+
|
86
|
+
Released under the MIT license, see LICENSE.txt for details.
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/traveler
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
module Traveler
|
2
|
+
class Bundler
|
3
|
+
include Util
|
4
|
+
|
5
|
+
def initialize platform
|
6
|
+
@platform = platform
|
7
|
+
end
|
8
|
+
|
9
|
+
def install_into dst
|
10
|
+
install
|
11
|
+
clean
|
12
|
+
config
|
13
|
+
install_extensions
|
14
|
+
copy_into(dst)
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
def install
|
19
|
+
FileUtils.rm_rf('vendor')
|
20
|
+
FileUtils.cp(GEMFILE_PATH, '.')
|
21
|
+
sh('BUNDLE_IGNORE_CONFIG=1 "%s" install --path vendor --without development' % BUNDLER)
|
22
|
+
end
|
23
|
+
|
24
|
+
def clean
|
25
|
+
return if no_local_gems # nothing to clean if no gems in Gemfile
|
26
|
+
sh('"%s" -fr vendor/*/*/cache/*' % RM)
|
27
|
+
sh('"%s" -fr vendor/ruby/*/extensions' % RM)
|
28
|
+
sh('"%s" vendor/ruby/*/gems -name "*.so" | xargs rm -f' % FIND)
|
29
|
+
sh('"%s" vendor/ruby/*/gems -name "*.bundle" | xargs rm -f' % FIND)
|
30
|
+
sh('"%s" vendor/ruby/*/gems -name "*.o" | xargs rm -f' % FIND)
|
31
|
+
end
|
32
|
+
|
33
|
+
def install_extensions
|
34
|
+
remote_gems = remote_gems()
|
35
|
+
local_gems.each_pair do |name,version|
|
36
|
+
next unless remote_gems[name]
|
37
|
+
if remote_gems[name].include?(version)
|
38
|
+
Gem.new(@platform, name, version).install
|
39
|
+
else
|
40
|
+
fail('Native extensions missing for "%s" version "%s".
|
41
|
+
Please use %s in your %s.' % [
|
42
|
+
name,
|
43
|
+
version,
|
44
|
+
remote_gems[name].map(&:inspect).join(" or "),
|
45
|
+
GEMFILE
|
46
|
+
])
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def local_gems
|
52
|
+
Dir.chdir 'vendor' do
|
53
|
+
scanner = /\*(.+)\((.+)\)/
|
54
|
+
%x["#{BUNDLER}" list --no-color].split("\n").each_with_object({}) do |l,o|
|
55
|
+
name, version = l.scan(scanner).flatten.map(&:strip).map(&:freeze)
|
56
|
+
next unless name && version
|
57
|
+
o[name] = version
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def no_local_gems
|
63
|
+
local_gems.keys.reject {|g| g == 'bundler'}.empty?
|
64
|
+
end
|
65
|
+
|
66
|
+
def remote_gems
|
67
|
+
matcher = /traveling\-ruby\-gems\-#{TRAVELING_RUBY_VERSION}\-/
|
68
|
+
replace = /.*#{matcher.source}|\.tar\.gz\Z/
|
69
|
+
scanner = /\A([\d|\.]+)\-([^\/].+)\/(.+)\-([\d|\.]+)\Z/
|
70
|
+
lines = open(BUCKET_ROOT).read.scan(/<Key>([^<]+)<\/Key>/).flatten
|
71
|
+
lines.select {|l| l =~ matcher}.each_with_object({}) do |line,o|
|
72
|
+
line.gsub!(replace, '')
|
73
|
+
ruby_version, platform, gem_name, gem_version = line.scan(scanner).flatten
|
74
|
+
next unless ruby_version == EFFECTIVE_RUBY_VERSION
|
75
|
+
next unless platform == @platform
|
76
|
+
(o[gem_name] ||= []).push(gem_version)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
def config
|
81
|
+
FileUtils.mkdir_p('vendor/.bundle')
|
82
|
+
FileUtils.cp(skeldir('bundle.config'), 'vendor/.bundle/config')
|
83
|
+
end
|
84
|
+
|
85
|
+
def copy_into dst
|
86
|
+
sh('"%s" %s %s.lock vendor' % [CP, GEMFILE, GEMFILE])
|
87
|
+
sh('"%s" -a vendor "%s"' % [CP, dst])
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
data/lib/traveler/cli.rb
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
module Traveler
|
2
|
+
class CLI < Thor
|
3
|
+
include Util
|
4
|
+
|
5
|
+
desc 'init', "Generating #{CONFIGFILE} and #{GEMFILE} files if ones does exists"
|
6
|
+
def init
|
7
|
+
bootstrap_gemfile unless gemfile_exists?
|
8
|
+
bootstrap_configfile unless configfile_exists?
|
9
|
+
if gemfile_exists? && configfile_exists?
|
10
|
+
puts success(:ok.icon, " Awesome! All files in place. You can run `traveler build` now!")
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
desc 'build', "Build runtime for platforms specified in #{CONFIGFILE}"
|
15
|
+
def build
|
16
|
+
require 'traveler/build'
|
17
|
+
build_world
|
18
|
+
generate_wrappers
|
19
|
+
puts '', bold_success(SUCCESS_ICONS.sample, ' All Done! You are ready to rock!')
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
def build_world
|
24
|
+
FileUtils.mkdir_p(Traveler.rubydir)
|
25
|
+
Dir.chdir Traveler.rubydir do
|
26
|
+
OPTED_PLATFORMS.each do |platform|
|
27
|
+
runtime = Runtime.new(platform)
|
28
|
+
puts '', :package.icon << bold_warn(' ', runtime.basename)
|
29
|
+
runtime.install
|
30
|
+
Dir.chdir runtime.basename do
|
31
|
+
within_sandbox do
|
32
|
+
bundler = Bundler.new(platform)
|
33
|
+
bundler.install_into(runtime.dirname)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def generate_wrappers
|
41
|
+
return if WRAPPERS.empty?
|
42
|
+
puts '', warn(:wrapping.icon, ' Wrapping...')
|
43
|
+
Dir.chdir Traveler.appdir do
|
44
|
+
WRAPPERS.each_pair do |name,(cmd_or_file,ruby_version)|
|
45
|
+
Wrapper.new(name, cmd_or_file, ruby_version)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def within_sandbox
|
51
|
+
return unless block_given?
|
52
|
+
sandbox = '__traveler_sandbox__'
|
53
|
+
FileUtils.rm_rf(sandbox)
|
54
|
+
FileUtils.mkdir_p(sandbox)
|
55
|
+
Dir.chdir(sandbox) {yield}
|
56
|
+
ensure
|
57
|
+
FileUtils.rm_rf(sandbox) if File.exists?(sandbox)
|
58
|
+
end
|
59
|
+
|
60
|
+
def bootstrap_configfile
|
61
|
+
puts info(:seeding.icon, ' Bootstrapping %s...' % CONFIGFILE)
|
62
|
+
FileUtils.cp(CONFIGFILE_SKEL, CONFIGFILE_PATH)
|
63
|
+
end
|
64
|
+
|
65
|
+
def bootstrap_gemfile
|
66
|
+
puts info(:seeding.icon, ' Bootstrapping %s...' % GEMFILE)
|
67
|
+
FileUtils.cp(GEMFILE_SKEL, GEMFILE_PATH)
|
68
|
+
end
|
69
|
+
|
70
|
+
def gemfile_exists?
|
71
|
+
File.exists?(GEMFILE_PATH)
|
72
|
+
end
|
73
|
+
|
74
|
+
def configfile_exists?
|
75
|
+
File.exists?(CONFIGFILE_PATH)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
Traveler::CLI.start(ARGV)
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module Traveler
|
2
|
+
module Config
|
3
|
+
extend Util
|
4
|
+
extend self
|
5
|
+
|
6
|
+
def assert_ruby_version_supported! version, caller = nil
|
7
|
+
versions = 'Please use %s' % RUBY_VERSIONS.join(' or ')
|
8
|
+
version.to_s.split('.').size == 3 || fail('Invalid Ruby version: "%s"
|
9
|
+
%s' % [version, versions], caller)
|
10
|
+
return true if RUBY_VERSIONS.include?(version)
|
11
|
+
fail('Ruby %s not supported. %s' % [version, versions], caller)
|
12
|
+
end
|
13
|
+
|
14
|
+
def assert_traveling_ruby_version_supported! version, caller = nil
|
15
|
+
return true if TRAVELING_RUBY_VERSIONS.include?(version)
|
16
|
+
fail('traveling-ruby %s not supported. Please use %s' % [version, TRAVELING_RUBY_VERSIONS.join(' or ')], caller)
|
17
|
+
end
|
18
|
+
|
19
|
+
def assert_platform_supported! platform, caller = nil
|
20
|
+
return true if PLATFORMS.include?(platform.to_s)
|
21
|
+
fail('"%s" platform not supported' % platform, caller)
|
22
|
+
end
|
23
|
+
|
24
|
+
def platforms *platforms
|
25
|
+
platforms.flatten!
|
26
|
+
called_from = caller[0]
|
27
|
+
platforms.each {|p| assert_platform_supported!(p, called_from)}
|
28
|
+
OPTED_PLATFORMS.concat(platforms)
|
29
|
+
end
|
30
|
+
|
31
|
+
def wrapper name, ruby_version, cmd_or_file
|
32
|
+
assert_ruby_version_supported!(ruby_version, caller[0])
|
33
|
+
WRAPPERS[name.to_s.freeze] = [cmd_or_file, ruby_version].map(&:to_s)
|
34
|
+
end
|
35
|
+
|
36
|
+
def traveling_ruby_version version
|
37
|
+
assert_traveling_ruby_version_supported!(version, caller[0])
|
38
|
+
Traveler.const_set(:TRAVELING_RUBY_VERSION, version.to_s.freeze)
|
39
|
+
end
|
40
|
+
|
41
|
+
def folder_name name
|
42
|
+
Traveler.const_set(:FOLDER_NAME, name.to_s.freeze)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
class String
|
2
|
+
def unindent
|
3
|
+
gsub(/^#{scan(/\A\s*/m).min_by(&:length)}/, "")
|
4
|
+
end
|
5
|
+
end
|
6
|
+
|
7
|
+
class Symbol
|
8
|
+
def icon
|
9
|
+
[{
|
10
|
+
ok: 10004,
|
11
|
+
error: 10007,
|
12
|
+
seeding: 127793,
|
13
|
+
wrapping: 127873,
|
14
|
+
package: 128230,
|
15
|
+
}[self] || 10067].pack('U*')
|
16
|
+
end
|
17
|
+
end
|
data/lib/traveler/gem.rb
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
module Traveler
|
2
|
+
class Gem
|
3
|
+
include Util
|
4
|
+
URL_FORMAT = 'traveling-ruby-gems-%s-%s-%s/%s'.freeze
|
5
|
+
EXTENSION = '.tar.gz'.freeze
|
6
|
+
|
7
|
+
def initialize platform, name, version
|
8
|
+
@platform, @name, @version = platform, name, version
|
9
|
+
end
|
10
|
+
|
11
|
+
def install
|
12
|
+
Dir.chdir 'vendor/ruby' do
|
13
|
+
download
|
14
|
+
extract
|
15
|
+
clean
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def name
|
20
|
+
[@name, @version].join('-') + EXTENSION
|
21
|
+
end
|
22
|
+
|
23
|
+
def url
|
24
|
+
RELEASES_URL + URL_FORMAT % [
|
25
|
+
TRAVELING_RUBY_VERSION,
|
26
|
+
EFFECTIVE_RUBY_VERSION,
|
27
|
+
@platform,
|
28
|
+
name
|
29
|
+
]
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
def download
|
34
|
+
sh('"%s" -L --fail -O "%s"' % [CURL, url])
|
35
|
+
end
|
36
|
+
|
37
|
+
def extract
|
38
|
+
sh('"%s" -xzf "%s"' % [TAR, name])
|
39
|
+
end
|
40
|
+
|
41
|
+
def clean
|
42
|
+
sh('"%s" -f "%s"' % [RM, name])
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module Traveler
|
2
|
+
|
3
|
+
if v = RUBY_VERSIONS.find {|v| v.to_f == RUBY_VERSION.to_f}
|
4
|
+
EFFECTIVE_RUBY_VERSION = v
|
5
|
+
else
|
6
|
+
assert_ruby_version_supported!(RUBY_VERSION)
|
7
|
+
end
|
8
|
+
|
9
|
+
[
|
10
|
+
CONFIGFILE,
|
11
|
+
GEMFILE
|
12
|
+
].each do |f|
|
13
|
+
file = appdir(f)
|
14
|
+
File.file?(file) || fail("Looks like #{f} does not exists. Did you run `traveler init`?")
|
15
|
+
File.readable?(file) || fail("Looks like #{f} is not readable")
|
16
|
+
end
|
17
|
+
|
18
|
+
%w[
|
19
|
+
curl
|
20
|
+
tar
|
21
|
+
gzip
|
22
|
+
cp
|
23
|
+
rm
|
24
|
+
find
|
25
|
+
bundler
|
26
|
+
].each do |x|
|
27
|
+
Traveler.const_set(x.upcase, %x[which #{x}].strip)
|
28
|
+
next if $? && $?.exitstatus == 0
|
29
|
+
fail("Could not find %s.
|
30
|
+
Please make sure it is installed and in your PATH" % x)
|
31
|
+
end
|
32
|
+
|
33
|
+
Config.class_eval(File.read(CONFIGFILE_PATH))
|
34
|
+
|
35
|
+
OPTED_PLATFORMS.any? || fail('Please specify at least one platform')
|
36
|
+
const_defined?(:TRAVELING_RUBY_VERSION) || fail('Please specify the traveling_ruby_version')
|
37
|
+
const_defined?(:FOLDER_NAME) || fail('Please specify the folder_name')
|
38
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module Traveler
|
2
|
+
class Runtime
|
3
|
+
include Util
|
4
|
+
BASENAME_FORMAT = 'traveling-ruby-%s-%s-%s'.freeze
|
5
|
+
EXTENSION = '.tar.gz'.freeze
|
6
|
+
|
7
|
+
def initialize platform
|
8
|
+
@platform = platform
|
9
|
+
end
|
10
|
+
|
11
|
+
def install
|
12
|
+
download
|
13
|
+
extract
|
14
|
+
end
|
15
|
+
|
16
|
+
def basename
|
17
|
+
BASENAME_FORMAT % [
|
18
|
+
TRAVELING_RUBY_VERSION,
|
19
|
+
EFFECTIVE_RUBY_VERSION,
|
20
|
+
@platform
|
21
|
+
]
|
22
|
+
end
|
23
|
+
|
24
|
+
def name
|
25
|
+
basename + EXTENSION
|
26
|
+
end
|
27
|
+
|
28
|
+
def dirname
|
29
|
+
Traveler.rubydir(basename)
|
30
|
+
end
|
31
|
+
|
32
|
+
def url
|
33
|
+
RELEASES_URL + name
|
34
|
+
end
|
35
|
+
|
36
|
+
def download
|
37
|
+
return if File.exists?(name)
|
38
|
+
sh('"%s" -L --fail -O "%s"' % [CURL, url])
|
39
|
+
end
|
40
|
+
|
41
|
+
def extract
|
42
|
+
FileUtils.rm_rf(basename)
|
43
|
+
FileUtils.mkdir(basename)
|
44
|
+
sh('"%s" -C "%s" -xzf "%s"' % [TAR, basename, name])
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'traveler/core_ext'
|
2
|
+
|
3
|
+
module Traveler
|
4
|
+
module Util
|
5
|
+
|
6
|
+
def appdir *args
|
7
|
+
File.join(PWD, *args.flatten.map(&:to_s))
|
8
|
+
end
|
9
|
+
|
10
|
+
def rubydir *args
|
11
|
+
appdir(FOLDER_NAME, *args)
|
12
|
+
end
|
13
|
+
|
14
|
+
def skeldir *args
|
15
|
+
File.join(SKEL_PATH, *args.flatten.map(&:to_s))
|
16
|
+
end
|
17
|
+
|
18
|
+
{
|
19
|
+
success: [0, 32],
|
20
|
+
bold_success: [1, 32],
|
21
|
+
info: [0, 36],
|
22
|
+
bold_info: [1, 36],
|
23
|
+
warn: [0, 35],
|
24
|
+
bold_warn: [1, 35],
|
25
|
+
error: [0, 31],
|
26
|
+
bold_error: [1, 31],
|
27
|
+
}.each_pair do |m,(esc,color)|
|
28
|
+
define_method m do |*args|
|
29
|
+
args.map {|a| "\e[%i;%im%s\e[0m" % [esc, color, a]}.join
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def fail reason = nil, caller = nil
|
34
|
+
buffer = []
|
35
|
+
buffer << error(:error.icon, ' ', reason) if reason
|
36
|
+
buffer << info(' in %s' % caller.to_s.gsub(/.*:(\d+):in.*/, CONFIGFILE + ':\1')) if caller
|
37
|
+
puts(*buffer) if buffer.any?
|
38
|
+
exit(1)
|
39
|
+
end
|
40
|
+
|
41
|
+
def sh *args
|
42
|
+
puts '$ ' << info(cmd = args.map(&:to_s).join(" "))
|
43
|
+
PTY.spawn cmd do |r, w, pid|
|
44
|
+
begin
|
45
|
+
r.sync
|
46
|
+
r.each_char {|c| print(c)}
|
47
|
+
rescue Errno::EIO => e
|
48
|
+
ensure
|
49
|
+
_, status = Process.wait2(pid)
|
50
|
+
fail('Exiting...') unless status == 0
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module Traveler
|
2
|
+
class Wrapper
|
3
|
+
include Util
|
4
|
+
|
5
|
+
def initialize file, cmd_or_file, ruby_version
|
6
|
+
@file, @cmd_or_file, @ruby_version = file, cmd_or_file, ruby_version
|
7
|
+
write if writeable?
|
8
|
+
end
|
9
|
+
|
10
|
+
def write
|
11
|
+
File.open(@file, 'w') {|f| f << render}
|
12
|
+
FileUtils.chmod('+x', @file)
|
13
|
+
end
|
14
|
+
|
15
|
+
def writeable?
|
16
|
+
if File.exists?(@file) && File.read(@file) !~ /#{SIGNATURE}/m
|
17
|
+
puts warn('
|
18
|
+
"%s" file exists and is not a Traveler wrapper.
|
19
|
+
If you still want to use it as a Traveler wrapper
|
20
|
+
please delete it and rerun `traveler`' % @file, '')
|
21
|
+
return false
|
22
|
+
end
|
23
|
+
true
|
24
|
+
end
|
25
|
+
|
26
|
+
def wrapper
|
27
|
+
File.read(skeldir('wrapper.sh'))
|
28
|
+
end
|
29
|
+
|
30
|
+
def locals
|
31
|
+
{
|
32
|
+
signature: SIGNATURE,
|
33
|
+
folder_name: FOLDER_NAME,
|
34
|
+
traveling_ruby_version: TRAVELING_RUBY_VERSION,
|
35
|
+
wrapper_ruby_version: @ruby_version,
|
36
|
+
cmd_or_file: @cmd_or_file
|
37
|
+
}
|
38
|
+
end
|
39
|
+
|
40
|
+
def render
|
41
|
+
Mustache.render(wrapper, locals)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
data/lib/traveler.rb
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
require 'pty'
|
3
|
+
require 'open-uri'
|
4
|
+
require 'mustache'
|
5
|
+
require 'thor'
|
6
|
+
require 'traveler/util'
|
7
|
+
|
8
|
+
module Traveler
|
9
|
+
extend Util
|
10
|
+
|
11
|
+
BUCKET_ROOT = 'https://traveling-ruby.s3-us-west-2.amazonaws.com/'.freeze
|
12
|
+
RELEASES_URL = 'http://d6r77u77i8pq3.cloudfront.net/releases/'.freeze
|
13
|
+
|
14
|
+
PWD = Dir.pwd.freeze
|
15
|
+
SKEL_PATH = File.expand_path('../../skel', __FILE__).freeze
|
16
|
+
|
17
|
+
CONFIGFILE = 'Travelfile'.freeze
|
18
|
+
CONFIGFILE_PATH = File.join(PWD, CONFIGFILE).freeze
|
19
|
+
CONFIGFILE_SKEL = skeldir(CONFIGFILE).freeze
|
20
|
+
|
21
|
+
GEMFILE = 'Gemfile'.freeze
|
22
|
+
GEMFILE_PATH = File.join(PWD, GEMFILE)
|
23
|
+
GEMFILE_SKEL = skeldir(GEMFILE)
|
24
|
+
|
25
|
+
RUBY_VERSIONS = %w[
|
26
|
+
2.1.5
|
27
|
+
2.2.0
|
28
|
+
].freeze
|
29
|
+
|
30
|
+
TRAVELING_RUBY_VERSIONS = %w[
|
31
|
+
20150210
|
32
|
+
20150210
|
33
|
+
20150204
|
34
|
+
].freeze
|
35
|
+
|
36
|
+
PLATFORMS = %w[
|
37
|
+
linux-x86
|
38
|
+
linux-x86_64
|
39
|
+
osx
|
40
|
+
].freeze
|
41
|
+
|
42
|
+
OPTED_PLATFORMS = []
|
43
|
+
WRAPPERS = {}
|
44
|
+
|
45
|
+
SIGNATURE = <<-STR.unindent.strip.freeze
|
46
|
+
# ================================================================= #
|
47
|
+
# Autogenerated by Traveler. Any updates will be lost on next build #
|
48
|
+
# ================================================================= #
|
49
|
+
STR
|
50
|
+
|
51
|
+
SUCCESS_ICONS = %w[
|
52
|
+
10004 128515 128516 128522
|
53
|
+
128523 128540 127866 128079
|
54
|
+
128076 128077 128175 128176
|
55
|
+
127853 127942 128640 127919
|
56
|
+
].map {|c| [c.to_i].pack('U*')}.freeze
|
57
|
+
end
|
data/skel/Gemfile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
source 'https://rubygems.org'
|
data/skel/Travelfile
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
|
2
|
+
# indicate platforms you need your program to run on.
|
3
|
+
# supported platforms:
|
4
|
+
# - linux-x86
|
5
|
+
# - linux-x86_64
|
6
|
+
# - osx
|
7
|
+
#
|
8
|
+
platforms 'linux-x86_64'
|
9
|
+
|
10
|
+
# create handy wrappers to run your app.
|
11
|
+
#
|
12
|
+
# 1) first argument is the name of the file to be created.
|
13
|
+
#
|
14
|
+
# 2) second argument is the Ruby version to be used by wrapper.
|
15
|
+
# supported Ruby versions:
|
16
|
+
# - 2.1.5
|
17
|
+
# - 2.2.0
|
18
|
+
#
|
19
|
+
# 3) third argument will be used to run your program.
|
20
|
+
# it can be a command or a file and will be used like:
|
21
|
+
# /path/to/ruby -r bundler/setup your-file-or-command
|
22
|
+
#
|
23
|
+
# @note: MULTIPLE wrappers can be defined each using a specific Ruby version
|
24
|
+
#
|
25
|
+
# @note: files and commands will be executed in the folder the wrapper resides in
|
26
|
+
#
|
27
|
+
# @note: you can comment this option if you do not need any wrappers
|
28
|
+
#
|
29
|
+
# @example create "run" file that will execute "app.rb" on Ruby 2.1.5
|
30
|
+
# wrapper :run, '2.1.5', 'app.rb'
|
31
|
+
#
|
32
|
+
# @example create "run" file that will run `puma` on Ruby 2.2.0
|
33
|
+
# wrapper :run, '2.2.0', 'puma'
|
34
|
+
#
|
35
|
+
# @example create two wrappers, one running on Ruby 2.2.0 and another on 2.1.5
|
36
|
+
# wrapper :run22, '2.2.0', 'puma'
|
37
|
+
# wrapper :run21, '2.1.5', 'puma'
|
38
|
+
#
|
39
|
+
wrapper :run, '2.1.5', 'your command or file here'
|
40
|
+
|
41
|
+
# the folder Ruby runtimes will be installed into.
|
42
|
+
folder_name 'traveler'
|
43
|
+
|
44
|
+
# see versions at http://traveling-ruby.s3-us-west-2.amazonaws.com/list.html
|
45
|
+
traveling_ruby_version '20150210'
|
data/skel/bundle.config
ADDED
data/skel/wrapper.sh
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
#!/usr/bin/env bash
|
2
|
+
{{signature}}
|
3
|
+
set -e
|
4
|
+
cd "$(cd $(dirname "$0") && pwd)"
|
5
|
+
|
6
|
+
if [[ `uname -s` =~ inux ]]; then
|
7
|
+
TRAVELING_RUBY_PLATFORM="linux-$(uname -m)"
|
8
|
+
else
|
9
|
+
TRAVELING_RUBY_PLATFORM="osx"
|
10
|
+
fi
|
11
|
+
|
12
|
+
TRAVELING_RUBY_ROOT="{{folder_name}}/traveling-ruby-{{traveling_ruby_version}}-{{wrapper_ruby_version}}-$TRAVELING_RUBY_PLATFORM/"
|
13
|
+
|
14
|
+
export BUNDLE_GEMFILE="$TRAVELING_RUBY_ROOT/vendor/Gemfile"
|
15
|
+
unset BUNDLE_IGNORE_CONFIG
|
16
|
+
|
17
|
+
exec "$TRAVELING_RUBY_ROOT/bin/ruby" -r bundler/setup {{cmd_or_file}}
|
data/traveler.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
name, version = 'traveler 0.0.1'.split
|
4
|
+
Gem::Specification.new do |spec|
|
5
|
+
spec.name = name
|
6
|
+
spec.version = version
|
7
|
+
spec.authors = ['Slee Woo']
|
8
|
+
spec.email = ['mail@sleewoo.com']
|
9
|
+
spec.description = 'A nifty wrapper for Traveling Ruby'
|
10
|
+
spec.summary = [name, version]*'-'
|
11
|
+
spec.homepage = 'https://github.com/sleewoo/' + name
|
12
|
+
spec.license = 'MIT'
|
13
|
+
|
14
|
+
spec.files = Dir['**/{*,.[a-z]*}'].reject {|e| e =~ /\.(gem|lock)\Z/}
|
15
|
+
spec.require_paths = ['lib']
|
16
|
+
|
17
|
+
spec.executables = Dir['bin/*'].map {|f| File.basename(f)}
|
18
|
+
|
19
|
+
spec.required_ruby_version = '>= 2.1'
|
20
|
+
|
21
|
+
spec.add_runtime_dependency 'mustache', '~> 1'
|
22
|
+
spec.add_runtime_dependency 'thor', '~> 0.19'
|
23
|
+
|
24
|
+
spec.add_development_dependency 'bundler', '~> 1.8'
|
25
|
+
spec.add_development_dependency 'rake', '~> 10'
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,124 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: traveler
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Slee Woo
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-02-22 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: mustache
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: thor
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0.19'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0.19'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.8'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.8'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '10'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '10'
|
69
|
+
description: A nifty wrapper for Traveling Ruby
|
70
|
+
email:
|
71
|
+
- mail@sleewoo.com
|
72
|
+
executables:
|
73
|
+
- traveler
|
74
|
+
extensions: []
|
75
|
+
extra_rdoc_files: []
|
76
|
+
files:
|
77
|
+
- ".gitignore"
|
78
|
+
- Gemfile
|
79
|
+
- LICENSE.txt
|
80
|
+
- README.md
|
81
|
+
- Rakefile
|
82
|
+
- bin/traveler
|
83
|
+
- lib/traveler.rb
|
84
|
+
- lib/traveler/build.rb
|
85
|
+
- lib/traveler/bundler.rb
|
86
|
+
- lib/traveler/cli.rb
|
87
|
+
- lib/traveler/config.rb
|
88
|
+
- lib/traveler/core_ext.rb
|
89
|
+
- lib/traveler/gem.rb
|
90
|
+
- lib/traveler/prerequisites.rb
|
91
|
+
- lib/traveler/runtime.rb
|
92
|
+
- lib/traveler/util.rb
|
93
|
+
- lib/traveler/wrapper.rb
|
94
|
+
- skel/Gemfile
|
95
|
+
- skel/Travelfile
|
96
|
+
- skel/bundle.config
|
97
|
+
- skel/wrapper.sh
|
98
|
+
- traveler.gemspec
|
99
|
+
homepage: https://github.com/sleewoo/traveler
|
100
|
+
licenses:
|
101
|
+
- MIT
|
102
|
+
metadata: {}
|
103
|
+
post_install_message:
|
104
|
+
rdoc_options: []
|
105
|
+
require_paths:
|
106
|
+
- lib
|
107
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
108
|
+
requirements:
|
109
|
+
- - ">="
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: '2.1'
|
112
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - ">="
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '0'
|
117
|
+
requirements: []
|
118
|
+
rubyforge_project:
|
119
|
+
rubygems_version: 2.2.2
|
120
|
+
signing_key:
|
121
|
+
specification_version: 4
|
122
|
+
summary: traveler-0.0.1
|
123
|
+
test_files: []
|
124
|
+
has_rdoc:
|