This repository has been archived by the owner on Nov 29, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathRakefile
228 lines (192 loc) · 7.63 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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
# For Bundler.with_clean_env
require 'bundler/setup'
PACKAGE_NAME = "cf-admin"
GITHUB_REPO = "traveling-cf-admin"
RELEASE_NAME = "CLIs for Cloud Foundry administrators"
RELEASE_DESCRIPTION = <<-EOS
All the CLIs and plugins for Cloud Foundry administrators.
* `cf` (useful administrator plugins coming soon)
* `uaac` to configure the UAA
* `nats sub`, `nats pub` to observe NATS messaging
EOS
# http://traveling-ruby.s3-us-west-2.amazonaws.com/list.html
TRAVELING_RUBY_VERSION = "20141224-2.1.5"
CF_CLI_VERSION = "6.11.0"
# RELEASE_PATCH = "1" # if we're releasing a patch to the original CF_CLI_VERSION release; else ""
RELEASE_PATCH = "" # normal; not patching/re-releasing with an existing CF CLI
NATS_CLI_VERSION = "1.0.0"
# Must match Gemfile
EVENTMACHINE_VERSION = "1.0.4"
NATIVE_GEMS = {
"eventmachine" => EVENTMACHINE_VERSION,
}
desc "Package and upload"
task :publish => ['package', 'release']
desc "Create release & upload files"
task :release => ['release:create', 'release:upload_files']
desc "Package your app"
task :package => ['package:linux:x86', 'package:linux:x86_64', 'package:osx']
namespace :release do
desc "Create a release on github and upload"
task :create do
tag = "v#{release_version}"
sh "git commit -a -m 'Releasing #{tag}'; true"
sh "git push origin master"
sh "github-release release \
--user cloudfoundry-community --repo #{GITHUB_REPO} --tag #{tag} \
--name '#{RELEASE_NAME} #{tag}' \
--description '#{RELEASE_DESCRIPTION}'"
sh "git pull origin master" # to get tag created
end
desc "Upload files to github release"
task :upload_files do
tag = "v#{release_version}"
files = Dir["*#{release_version}*.tar.gz"]
if files.size == 0
$stderr.puts "Run `rake package` to create packages first"
exit 1
end
files.each do |file|
sh "github-release upload \
--user cloudfoundry-community --repo #{GITHUB_REPO} --tag #{tag} \
--name #{file} --file #{file}"
end
end
end
namespace :package do
namespace :linux do
desc "Package your app for Linux x86"
task :x86 => [:bundle_install,
"packaging/traveling-ruby-#{TRAVELING_RUBY_VERSION}-linux-x86.tar.gz",
"packaging/traveling-ruby-#{TRAVELING_RUBY_VERSION}-linux-x86-eventmachine-#{EVENTMACHINE_VERSION}.tar.gz",
"packaging/cf-#{CF_CLI_VERSION}-linux-x86.tgz",
"packaging/nats-#{NATS_CLI_VERSION}-linux-x86.tgz",
] do
create_package("linux-x86")
end
desc "Package your app for Linux x86_64"
task :x86_64 => [:bundle_install,
"packaging/traveling-ruby-#{TRAVELING_RUBY_VERSION}-linux-x86_64.tar.gz",
"packaging/traveling-ruby-#{TRAVELING_RUBY_VERSION}-linux-x86_64-eventmachine-#{EVENTMACHINE_VERSION}.tar.gz",
"packaging/cf-#{CF_CLI_VERSION}-linux-x86_64.tgz",
"packaging/nats-#{NATS_CLI_VERSION}-linux-x86_64.tgz",
] do
create_package("linux-x86_64")
end
end
desc "Package your app for OS X"
task :osx => [:bundle_install,
"packaging/traveling-ruby-#{TRAVELING_RUBY_VERSION}-osx.tar.gz",
"packaging/traveling-ruby-#{TRAVELING_RUBY_VERSION}-osx-eventmachine-#{EVENTMACHINE_VERSION}.tar.gz",
"packaging/cf-#{CF_CLI_VERSION}-osx.tgz",
"packaging/nats-#{NATS_CLI_VERSION}-osx.tgz",
] 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 packaging/tmp"
sh "mkdir -p packaging/tmp"
sh "cp Gemfile* packaging/tmp/"
sh "rm -rf packaging/vendor/ruby/2.1.0/bundler" # if multiple clones of same repo, may load in wrong one
Bundler.with_clean_env do
sh "cd packaging/tmp && env BUNDLE_IGNORE_CONFIG=1 bundle install --path ../vendor --without development"
end
sh "rm -rf packaging/tmp"
sh "rm -rf packaging/vendor/*/*/cache/*"
sh "rm -rf packaging/vendor/ruby/*/extensions"
sh "find packaging/vendor/ruby/*/gems -name '*.so' | xargs rm; true"
sh "find packaging/vendor/ruby/*/gems -name '*.bundle' | xargs rm; true"
end
desc "Clean up created releases"
task :clean do
sh "rm -f #{PACKAGE_NAME}*.tar.gz"
sh "rm -rf #{PACKAGE_NAME}*"
sh "rm -rf packaging/vendor"
sh "rm -rf packaging/*.tar.gz"
sh "rm -rf packaging/*.tgz"
end
end
%w[linux-x86 linux-x86_64 osx].each do |target|
file "packaging/traveling-ruby-#{TRAVELING_RUBY_VERSION}-#{target}.tar.gz" do
download_runtime(target)
end
NATIVE_GEMS.each do |gem, version|
file "packaging/traveling-ruby-#{TRAVELING_RUBY_VERSION}-#{target}-#{gem}-#{version}.tar.gz" do
download_native_extension(target, "#{gem}-#{version}")
end
end
file "packaging/cf-#{CF_CLI_VERSION}-#{target}.tgz" do
download_cf_cli(target)
end
file "packaging/nats-#{NATS_CLI_VERSION}-#{target}.tgz" do
download_nats_cli(target)
end
end
def create_package(target)
package_dir = "#{PACKAGE_NAME}-#{release_version}-#{target}"
sh "rm -rf #{package_dir}"
sh "mkdir #{package_dir}"
sh "mkdir -p #{package_dir}/lib/app"
# sh "cp hello.rb #{package_dir}/lib/app/"
sh "mkdir #{package_dir}/lib/ruby"
sh "tar xzf packaging/traveling-ruby-#{TRAVELING_RUBY_VERSION}-#{target}.tar.gz -C #{package_dir}/lib/ruby"
sh "tar xzf packaging/cf-#{CF_CLI_VERSION}-#{target}.tgz -C #{package_dir}"
sh "tar xzf packaging/nats-#{NATS_CLI_VERSION}-#{target}.tgz -C #{package_dir}"
sh "mv #{package_dir}/nats* #{package_dir}/nats"
sh "cp packaging/wrappers/uaac.sh #{package_dir}/uaac"
sh "chmod +x packaging/wrappers/uaac.sh #{package_dir}/uaac"
sh "cp -pR packaging/helpers #{package_dir}/"
sh "cp -pR packaging/vendor #{package_dir}/lib/"
sh "cp Gemfile* #{package_dir}/lib/vendor/"
sh "mkdir #{package_dir}/lib/vendor/.bundle"
sh "cp packaging/bundler-config #{package_dir}/lib/vendor/.bundle/config"
NATIVE_GEMS.each do |gem, version|
sh "tar -xzf packaging/traveling-ruby-#{TRAVELING_RUBY_VERSION}-#{target}-#{gem}-#{version}.tar.gz " +
"-C #{package_dir}/lib/vendor/ruby"
end
if !ENV['DIR_ONLY']
sh "tar -czf #{package_dir}.tar.gz #{package_dir}"
sh "rm -rf #{package_dir}"
end
end
def download_runtime(target)
sh "cd packaging && 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 packaging/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
def download_cf_cli(target)
url = case target
when "linux-x86"
"https://cli.run.pivotal.io/stable?release=linux32-binary&version=#{CF_CLI_VERSION}&source=traveling-cf-admin"
when "linux-x86_64"
"https://cli.run.pivotal.io/stable?release=linux64-binary&version=#{CF_CLI_VERSION}&source=traveling-cf-admin"
when "osx"
"https://cli.run.pivotal.io/stable?release=macosx64-binary&version=#{CF_CLI_VERSION}&source=traveling-cf-admin"
end
sh "curl -L -o packaging/cf-#{CF_CLI_VERSION}-#{target}.tgz #{url}"
end
def download_nats_cli(target)
url = "https://github.com/soutenniza/nats/releases/download/#{NATS_CLI_VERSION}/nats-#{NATS_CLI_VERSION}-#{target}.tar.gz"
sh "curl -L -o packaging/nats-#{NATS_CLI_VERSION}-#{target}.tgz #{url}"
end
def release_version
if RELEASE_PATCH == ""
CF_CLI_VERSION
else
CF_CLI_VERSION + "." + RELEASE_PATCH
end
end
def uaac_cli_version
@uaac_cli_version ||= begin
if `bundle list | grep uaac` =~ /(\d+\.\d+\.\d+)/
$1
end
end
end