traveler 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b1ff89c249a9f86cae865f07b82adc05657b2a6e
4
- data.tar.gz: ca6421f494b18df1f79e59765b1ef1c34e568496
3
+ metadata.gz: 71940c2f9e8689c2b08a8aa506f0582094179c22
4
+ data.tar.gz: 71c6d37800b031616d49097a1e3b38f5bccb74c5
5
5
  SHA512:
6
- metadata.gz: c9bfac3282c9170bbebcbb0a122bff6735a2ce60f16d7b8545dc58e9cb9fcf9a7e2d491f24d7200cd1f2707b7d43ab208c526e6f465db25731da7c6caa0cf112
7
- data.tar.gz: 1b90291047bfc8691a9e34ae715ece6b05d5436007f67320af30c000a3674bb7bbf271aca47b0da945e700ac64dd257de5b58e4c278a7b6e534db7cf813db694
6
+ metadata.gz: ae010579d972b51a4c08b61fdd0ec9ae67185b2c26aa2e724bf11bab1c62614a798be2d076a27c3f73c6df473780826ef4df02e1c58a04ec76372793fdc98299
7
+ data.tar.gz: 26cedddaf7eb74282b923d9df6ab6cb107f7885b1c6a90fd2d2aacd609e42c5f88692ed9be136887fb5582a0e1fc3db338cc05b2ca1fb2a4d8dc31f15909ffa7
data/README.md CHANGED
@@ -1,8 +1,7 @@
1
1
 
2
- # Traveler
3
- **A nifty wrapper for Traveling Ruby**
2
+ ## Traveler
4
3
 
5
- Easily distribute your Ruby app to any Linux and/or OS X.
4
+ **Easily distribute your Ruby apps to any Linux and/or OS X.**
6
5
 
7
6
  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
7
 
@@ -11,7 +10,7 @@ Here are some [introductory materials](https://github.com/phusion/traveling-ruby
11
10
 
12
11
  **Ok, what do i need to use Traveler?**
13
12
 
14
- You'll need Ruby 2.1.x or 2.2.x installed on your system.
13
+ You'll need Ruby 2.1.x or 2.2.x on a Linux or OS X machine ([no windows support for now](https://github.com/sleewoo/traveler/issues/2)).
15
14
 
16
15
  Why so?
17
16
 
@@ -29,14 +28,14 @@ make sure to run `rbenv rehash` is you are using rbenv.
29
28
 
30
29
  ## Use
31
30
 
32
- Traveler acts inside your app folder. It creates a `Travelfile` file and the `traveler` folder(name is configurable).
31
+ Traveler acts inside your app folder. It creates a `Travelfile` file and the `traveler` folder.
33
32
 
34
33
  `Travelfile` is a Ruby file containing few configurations:
35
34
 
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
35
+ - `platforms` specify what platforms your app should run on
36
+ - `wrapper` [define wrapper(s)](https://github.com/sleewoo/traveler/blob/master/skel/Travelfile#L12) that will allow to easily run your app
37
+ - `folder_name` name of the folder that will hold the builds (`traveler` by default)
38
+ - `traveling_ruby_version` what version of Traveling Ruby to be used for builds
40
39
 
41
40
  And that's pretty all about configuration.
42
41
 
@@ -71,11 +70,23 @@ So you can have multiple Ruby versions with same app.
71
70
 
72
71
  To make use of them simply define multiple wrappers, each using a specific Ruby version.
73
72
 
73
+
74
+ ## Rewrapping
75
+
76
+ Sometimes you need to rebuild wrappers without actually rebuild the runtime/gems.
77
+
78
+ For this simply run:
79
+
80
+ `traveler wrap`
81
+
82
+ It will reread your wrappers in Travelfile and rebuild them accordingly.
83
+
84
+
74
85
  ## Contributors are highly welcome!
75
86
 
76
87
  Would love to have some help with testing.
77
88
 
78
- 1. Fork it ( https://github.com/[my-github-username]/traveler/fork )
89
+ 1. Fork it ( https://github.com/sleewoo/traveler/fork )
79
90
  2. Create your feature branch (`git checkout -b my-new-feature`)
80
91
  3. Commit your changes (`git commit -am 'Add some feature'`)
81
92
  4. Push to the branch (`git push origin my-new-feature`)
data/lib/traveler/cli.rb CHANGED
@@ -13,12 +13,19 @@ module Traveler
13
13
 
14
14
  desc 'build', "Build runtime for platforms specified in #{CONFIGFILE}"
15
15
  def build
16
- require 'traveler/build'
16
+ load_configs
17
17
  build_world
18
18
  generate_wrappers
19
19
  puts '', bold_success(SUCCESS_ICONS.sample, ' All Done! You are ready to rock!')
20
20
  end
21
21
 
22
+ desc 'wrap', 'Only (re)build wrappers without '
23
+ def wrap
24
+ load_configs
25
+ generate_wrappers
26
+ puts bold_success(SUCCESS_ICONS.sample, ' Done!')
27
+ end
28
+
22
29
  private
23
30
  def build_world
24
31
  FileUtils.mkdir_p(Traveler.rubydir)
@@ -38,11 +45,12 @@ module Traveler
38
45
  end
39
46
 
40
47
  def generate_wrappers
41
- return if WRAPPERS.empty?
48
+ return puts('', warn(" No wrappers defined in #{CONFIGFILE}"), '') if WRAPPERS.empty?
42
49
  puts '', warn(:wrapping.icon, ' Wrapping...')
43
50
  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)
51
+ WRAPPERS.each_pair do |name,(ruby_version,cmd_or_file,block)|
52
+ puts warn(' (re)building "%s" wrapper...' % name)
53
+ Wrapper.new(ruby_version, name, cmd_or_file, block)
46
54
  end
47
55
  end
48
56
  end
@@ -74,6 +82,10 @@ module Traveler
74
82
  def configfile_exists?
75
83
  File.exists?(CONFIGFILE_PATH)
76
84
  end
85
+
86
+ def load_configs
87
+ require 'traveler/config'
88
+ end
77
89
  end
78
90
  end
79
91
  Traveler::CLI.start(ARGV)
@@ -28,9 +28,9 @@ module Traveler
28
28
  OPTED_PLATFORMS.concat(platforms)
29
29
  end
30
30
 
31
- def wrapper name, ruby_version, cmd_or_file
31
+ def wrapper name, ruby_version, cmd = nil, &block
32
32
  assert_ruby_version_supported!(ruby_version, caller[0])
33
- WRAPPERS[name.to_s.freeze] = [cmd_or_file, ruby_version].map(&:to_s)
33
+ WRAPPERS[name.to_s.freeze] = [ruby_version.to_s.freeze, cmd.to_s.freeze, block].freeze
34
34
  end
35
35
 
36
36
  def traveling_ruby_version version
@@ -43,3 +43,9 @@ module Traveler
43
43
  end
44
44
  end
45
45
  end
46
+
47
+ require 'traveler/prerequisites'
48
+ require 'traveler/runtime'
49
+ require 'traveler/bundler'
50
+ require 'traveler/gem'
51
+ require 'traveler/wrapper'
@@ -2,43 +2,58 @@ module Traveler
2
2
  class Wrapper
3
3
  include Util
4
4
 
5
- def initialize file, cmd_or_file, ruby_version
6
- @file, @cmd_or_file, @ruby_version = file, cmd_or_file, ruby_version
5
+ def initialize ruby_version, name, cmd, block
6
+ @ruby_version, @name, @cmd, @block = ruby_version, name, cmd, block
7
7
  write if writeable?
8
8
  end
9
9
 
10
10
  def write
11
- File.open(@file, 'w') {|f| f << render}
12
- FileUtils.chmod('+x', @file)
11
+ File.open(file, 'w') {|f| f << render_wrapper}
12
+ FileUtils.chmod('+x', file)
13
13
  end
14
14
 
15
15
  def writeable?
16
- if File.exists?(@file) && File.read(@file) !~ /#{SIGNATURE}/m
16
+ if File.exists?(file) && File.read(file) !~ /#{SIGNATURE}/m
17
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, '')
18
+ "%s" file exists and is not a Traveler wrapper.
19
+ Use another file or delete/rename this one and (re)run `traveler wrap`' % file)
21
20
  return false
22
21
  end
23
22
  true
24
23
  end
25
24
 
26
- def wrapper
27
- File.read(skeldir('wrapper.sh'))
28
- end
29
-
30
25
  def locals
31
26
  {
32
- signature: SIGNATURE,
33
- folder_name: FOLDER_NAME,
27
+ signature: SIGNATURE,
28
+ folder_name: FOLDER_NAME,
34
29
  traveling_ruby_version: TRAVELING_RUBY_VERSION,
35
- wrapper_ruby_version: @ruby_version,
36
- cmd_or_file: @cmd_or_file
30
+ wrapper_ruby_version: @ruby_version
37
31
  }
38
32
  end
39
33
 
40
- def render
41
- Mustache.render(wrapper, locals)
34
+ def cmd
35
+ return @block.call if @block
36
+ render_cmd(@cmd)
37
+ end
38
+
39
+ def render_wrapper
40
+ Mustache.render(wrapper_template, locals.merge(cmd: cmd))
41
+ end
42
+
43
+ def render_cmd cmd
44
+ Mustache.render(cmd_template, locals.merge(cmd: cmd))
45
+ end
46
+
47
+ def wrapper_template
48
+ File.read(skeldir('wrapper.sh'))
49
+ end
50
+
51
+ def cmd_template
52
+ File.read(skeldir('cmd.sh'))
53
+ end
54
+
55
+ def file
56
+ @name
42
57
  end
43
58
  end
44
59
  end
data/skel/Travelfile CHANGED
@@ -18,7 +18,20 @@ platforms 'linux-x86_64'
18
18
  #
19
19
  # 3) third argument will be used to run your program.
20
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
21
+ # `exec /path/to/ruby -r bundler/setup your-file-or-command`
22
+ # However this can be omitted if providing a block.
23
+ #
24
+ # 4) A optional block.
25
+ # If given, returned string will be used as a un-prefixed cmd.
26
+ # Useful when you need full control over cmd to run.
27
+ # Will run like:
28
+ # `exec your-command-here`
29
+ #
30
+ # @note: use $RUBY_ROOT to refer to the Ruby installation folder,
31
+ # e.g. '$RUBY_ROOT/bin/bundler'
32
+ # IMPORTANT: make sure to use it inside single quotes - '$RUBY_ROOT'
33
+ # or escape it if using inside double quotes - "\$RUBY_ROOT"
34
+ # Otherwise it will refer to a Ruby global variable and make your wrapper unusable.
22
35
  #
23
36
  # @note: MULTIPLE wrappers can be defined each using a specific Ruby version
24
37
  #
@@ -27,14 +40,20 @@ platforms 'linux-x86_64'
27
40
  # @note: you can comment this option if you do not need any wrappers
28
41
  #
29
42
  # @example create "run" file that will execute "app.rb" on Ruby 2.1.5
43
+ # will run like:
44
+ # `exec "$RUBY_ROOT/bin/ruby" -r bundler/setup app.rb`
45
+ #
30
46
  # wrapper :run, '2.1.5', 'app.rb'
31
47
  #
32
48
  # @example create "run" file that will run `puma` on Ruby 2.2.0
33
- # wrapper :run, '2.2.0', 'puma'
49
+ #
50
+ # wrapper :run, '2.2.0' do
51
+ # "\$RUBY_ROOT/bin/bundler exec puma"
52
+ # end
34
53
  #
35
54
  # @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'
55
+ # wrapper :run22, '2.2.0', 'config.ru'
56
+ # wrapper :run21, '2.1.5', 'config.ru'
38
57
  #
39
58
  wrapper :run, '2.1.5', 'your command or file here'
40
59
 
data/skel/cmd.sh ADDED
@@ -0,0 +1 @@
1
+ exec "$RUBY_ROOT/bin/ruby" -r bundler/setup {{{cmd}}}
data/skel/wrapper.sh CHANGED
@@ -4,14 +4,15 @@ set -e
4
4
  cd "$(cd $(dirname "$0") && pwd)"
5
5
 
6
6
  if [[ `uname -s` =~ inux ]]; then
7
- TRAVELING_RUBY_PLATFORM="linux-$(uname -m)"
7
+ arch="linux-$(uname -m)"
8
8
  else
9
- TRAVELING_RUBY_PLATFORM="osx"
9
+ arch="osx"
10
10
  fi
11
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
12
  unset BUNDLE_IGNORE_CONFIG
16
13
 
17
- exec "$TRAVELING_RUBY_ROOT/bin/ruby" -r bundler/setup {{cmd_or_file}}
14
+ export RUBY_VERSION="{{wrapper_ruby_version}}"
15
+ export RUBY_ROOT="{{folder_name}}/traveling-ruby-{{traveling_ruby_version}}-$RUBY_VERSION-$arch/"
16
+ export BUNDLE_GEMFILE="$RUBY_ROOT/vendor/Gemfile"
17
+
18
+ {{{cmd}}}
data/traveler.gemspec CHANGED
@@ -1,12 +1,12 @@
1
1
  # coding: utf-8
2
2
 
3
- name, version = 'traveler 0.0.1'.split
3
+ name, version = 'traveler 0.1.0'.split
4
4
  Gem::Specification.new do |spec|
5
5
  spec.name = name
6
6
  spec.version = version
7
7
  spec.authors = ['Slee Woo']
8
8
  spec.email = ['mail@sleewoo.com']
9
- spec.description = 'A nifty wrapper for Traveling Ruby'
9
+ spec.description = 'Easily embrace Traveling Ruby awesomeness'
10
10
  spec.summary = [name, version]*'-'
11
11
  spec.homepage = 'https://github.com/sleewoo/' + name
12
12
  spec.license = 'MIT'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: traveler
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Slee Woo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-22 00:00:00.000000000 Z
11
+ date: 2015-03-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mustache
@@ -66,7 +66,7 @@ dependencies:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '10'
69
- description: A nifty wrapper for Traveling Ruby
69
+ description: Easily embrace Traveling Ruby awesomeness
70
70
  email:
71
71
  - mail@sleewoo.com
72
72
  executables:
@@ -81,7 +81,6 @@ files:
81
81
  - Rakefile
82
82
  - bin/traveler
83
83
  - lib/traveler.rb
84
- - lib/traveler/build.rb
85
84
  - lib/traveler/bundler.rb
86
85
  - lib/traveler/cli.rb
87
86
  - lib/traveler/config.rb
@@ -94,6 +93,7 @@ files:
94
93
  - skel/Gemfile
95
94
  - skel/Travelfile
96
95
  - skel/bundle.config
96
+ - skel/cmd.sh
97
97
  - skel/wrapper.sh
98
98
  - traveler.gemspec
99
99
  homepage: https://github.com/sleewoo/traveler
@@ -119,6 +119,6 @@ rubyforge_project:
119
119
  rubygems_version: 2.2.2
120
120
  signing_key:
121
121
  specification_version: 4
122
- summary: traveler-0.0.1
122
+ summary: traveler-0.1.0
123
123
  test_files: []
124
124
  has_rdoc:
@@ -1,6 +0,0 @@
1
- require 'traveler/config'
2
- require 'traveler/prerequisites'
3
- require 'traveler/runtime'
4
- require 'traveler/bundler'
5
- require 'traveler/gem'
6
- require 'traveler/wrapper'