forked from phusion/traveling-ruby-native-extensions-demo
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Rakefile
132 lines (112 loc) · 4.24 KB
/
Rakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
require 'bundler'
# For Bundler.with_clean_env
require 'bundler/setup'
PACKAGE_NAME = "hello"
VERSION = "1.0.0"
TRAVELING_RUBY_VERSION = "20150204-2.1.5"
NOKOGIRI_VERSION = "1.6.6.2" # Must match Gemfile
desc "Package your app"
task :package => ['package:linux:x86', 'package:linux:x86_64', 'package:osx']
namespace :package do
namespace :linux do
desc "Package your app for Linux x86"
task :x86 => [:bundle_install,
"traveling-ruby-#{TRAVELING_RUBY_VERSION}-linux-x86.tar.gz",
"traveling-ruby-#{TRAVELING_RUBY_VERSION}-linux-x86-nokogiri-#{NOKOGIRI_VERSION}.tar.gz"
] do
create_package("linux-x86")
end
desc "Package your app for Linux x86_64"
task :x86_64 => [:bundle_install,
"traveling-ruby-#{TRAVELING_RUBY_VERSION}-linux-x86_64.tar.gz",
"traveling-ruby-#{TRAVELING_RUBY_VERSION}-linux-x86_64-nokogiri-#{NOKOGIRI_VERSION}.tar.gz"
] do
create_package("linux-x86_64")
end
end
desc "Package your app for OS X"
task :osx => [:bundle_install,
"traveling-ruby-#{TRAVELING_RUBY_VERSION}-osx.tar.gz",
"traveling-ruby-#{TRAVELING_RUBY_VERSION}-osx-nokogiri-#{NOKOGIRI_VERSION}.tar.gz"
] do
create_package("osx")
end
desc "Install gems to local directory"
task :bundle_install do
if RUBY_VERSION !~ /^2\.1\./
abort "You can only 'bundle install' using Ruby 2.1, because that's what Traveling Ruby uses."
end
sh "rm -rf tmp"
sh "mkdir tmp"
sh "cp app/Gemfile app/Gemfile.lock tmp/"
Bundler.with_clean_env do
sh "cd tmp && env BUNDLE_IGNORE_CONFIG=1 bundle install --path ../vendor --without development"
end
sh "rm -rf tmp"
sh "rm -f vendor/*/*/cache/*"
sh "rm -rf vendor/ruby/*/extensions"
sh "find vendor/ruby/*/gems -name '*.so' | xargs rm -f"
sh "find vendor/ruby/*/gems -name '*.bundle' | xargs rm -f"
sh "find vendor/ruby/*/gems -name '*.o' | xargs rm -f"
end
end
file "traveling-ruby-#{TRAVELING_RUBY_VERSION}-linux-x86.tar.gz" do
download_runtime("linux-x86")
end
file "traveling-ruby-#{TRAVELING_RUBY_VERSION}-linux-x86_64.tar.gz" do
download_runtime("linux-x86_64")
end
file "traveling-ruby-#{TRAVELING_RUBY_VERSION}-osx.tar.gz" do
download_runtime("osx")
end
file "traveling-ruby-#{TRAVELING_RUBY_VERSION}-linux-x86-nokogiri-#{NOKOGIRI_VERSION}.tar.gz" do
download_native_extension("linux-x86", "nokogiri-#{NOKOGIRI_VERSION}")
end
file "traveling-ruby-#{TRAVELING_RUBY_VERSION}-linux-x86_64-nokogiri-#{NOKOGIRI_VERSION}.tar.gz" do
download_native_extension("linux-x86_64", "nokogiri-#{NOKOGIRI_VERSION}")
end
file "traveling-ruby-#{TRAVELING_RUBY_VERSION}-osx-nokogiri-#{NOKOGIRI_VERSION}.tar.gz" do
download_native_extension("osx", "nokogiri-#{NOKOGIRI_VERSION}")
end
def create_package(target)
sh "mkdir -p lib"
sh "rm -rf lib/app"
sh "rm -rf lib/ruby"
sh "rm -rf lib/vendor"
sh "cp -r app lib/"
sh "mkdir lib/ruby"
sh "mkdir lib/vendor"
sh "tar -xzf traveling-ruby-#{TRAVELING_RUBY_VERSION}-#{target}.tar.gz -C lib/ruby"
sh "rm traveling-ruby-#{TRAVELING_RUBY_VERSION}-#{target}.tar.gz"
sh "mv vendor lib"
sh "cp app/Gemfile app/Gemfile.lock lib/vendor/"
sh "mkdir lib/vendor/.bundle"
sh "cp bundler-config lib/vendor/.bundle/config"
sh "tar -xzf traveling-ruby-#{TRAVELING_RUBY_VERSION}-#{target}-nokogiri-#{NOKOGIRI_VERSION}.tar.gz " +
"-C lib/vendor/ruby"
sh "rm traveling-ruby-#{TRAVELING_RUBY_VERSION}-#{target}-nokogiri-#{NOKOGIRI_VERSION}.tar.gz"
end
def download_runtime(target)
sh "curl -L -O --fail " +
"http://d6r77u77i8pq3.cloudfront.net/releases/traveling-ruby-#{TRAVELING_RUBY_VERSION}-#{target}.tar.gz"
end
def download_native_extension(target, gem_name_and_version)
sh "curl -L --fail -o traveling-ruby-#{TRAVELING_RUBY_VERSION}-#{target}-#{gem_name_and_version}.tar.gz " +
"http://d6r77u77i8pq3.cloudfront.net/releases/traveling-ruby-gems-#{TRAVELING_RUBY_VERSION}-#{target}/#{gem_name_and_version}.tar.gz"
end
desc "Integration Test"
task :test do
expected = File.read(__dir__ + '/integration-test/expected_output')
actual = %x(serverless run -f hello)
puts '------expected output------'
puts expected
puts '------actual output------'
puts actual
if expected == actual
puts 'test success!'
exit 0
else
puts 'test failed!'
exit 1
end
end