capistrano-sbt 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +3 -3
- data/lib/capistrano-sbt/deploy.rb +65 -53
- data/lib/capistrano-sbt/version.rb +1 -1
- metadata +2 -3
data/README.md
CHANGED
@@ -20,9 +20,9 @@ Or install it yourself as:
|
|
20
20
|
|
21
21
|
This recipes will try to do following things during Capistrano `deploy:setup` and `deploy` tasks.
|
22
22
|
|
23
|
-
|
24
|
-
|
25
|
-
|
23
|
+
1. Download and install sbt for current project
|
24
|
+
2. Prepare optional `*.sbt` for current project (optional)
|
25
|
+
3. Build sbt project remotely (default) or locally
|
26
26
|
|
27
27
|
To build you sbt projects during Capistrano `deploy` tasks, add following in you `config/deploy.rb`. By default, sbt build will run after the Capistrano's `deploy:finalize_update`.
|
28
28
|
|
@@ -1,5 +1,6 @@
|
|
1
1
|
|
2
2
|
require 'capistrano'
|
3
|
+
require 'tempfile'
|
3
4
|
require 'uri'
|
4
5
|
|
5
6
|
module Capistrano
|
@@ -8,8 +9,16 @@ module Capistrano
|
|
8
9
|
configuration.load {
|
9
10
|
namespace(:sbt) {
|
10
11
|
_cset(:sbt_version, '0.11.2')
|
12
|
+
_cset(:sbt_group_id) {
|
13
|
+
case sbt_version
|
14
|
+
when /^0\.(?:7|10)\.\d+$/, /^0\.11\.[0-2]$/
|
15
|
+
'org.scala-tools.sbt'
|
16
|
+
else
|
17
|
+
'org.scala-sbt'
|
18
|
+
end
|
19
|
+
}
|
11
20
|
_cset(:sbt_jar_url) {
|
12
|
-
"http://typesafe.artifactoryonline.com/typesafe/ivy-releases/
|
21
|
+
"http://typesafe.artifactoryonline.com/typesafe/ivy-releases/#{sbt_group_id}/sbt-launch/#{sbt_version}/sbt-launch.jar"
|
13
22
|
}
|
14
23
|
_cset(:sbt_jar_file) {
|
15
24
|
File.join(shared_path, 'tools', 'sbt', "sbt-#{sbt_version}", File.basename(URI.parse(sbt_jar_url).path))
|
@@ -88,68 +97,72 @@ module Capistrano
|
|
88
97
|
}
|
89
98
|
}
|
90
99
|
|
100
|
+
def _install(options={})
|
101
|
+
execute = []
|
102
|
+
jar_file = options.delete(:jar_file)
|
103
|
+
jar_url = options.delete(:jar_url)
|
104
|
+
execute << "mkdir -p #{File.dirname(jar_file)}"
|
105
|
+
execute << "( test -f #{jar_file} || wget --no-verbose -O #{jar_file} #{jar_url} )"
|
106
|
+
execute << "test -f #{jar_file}"
|
107
|
+
execute.join(' && ')
|
108
|
+
end
|
109
|
+
|
91
110
|
task(:install, :roles => :app, :except => { :no_release => true }) {
|
92
|
-
run(
|
93
|
-
( test -d #{File.dirname(sbt_jar_file)} || mkdir -p #{File.dirname(sbt_jar_file)} ) &&
|
94
|
-
( test -f #{sbt_jar_file} || wget --no-verbose -O #{sbt_jar_file} #{sbt_jar_url} ) &&
|
95
|
-
test -f #{sbt_jar_file};
|
96
|
-
E
|
111
|
+
run(_install(:jar_file => sbt_jar_file, :jar_url => sbt_jar_url))
|
97
112
|
}
|
98
113
|
|
99
|
-
task(:install_locally, :except => { :no_release => true }) {
|
100
|
-
run_locally(
|
101
|
-
( test -d #{File.dirname(sbt_jar_file_local)} || mkdir -p #{File.dirname(sbt_jar_file_local)} ) &&
|
102
|
-
( test -f #{sbt_jar_file_local} || wget --no-verbose -O #{sbt_jar_file_local} #{sbt_jar_url} ) &&
|
103
|
-
test -f #{sbt_jar_file_local};
|
104
|
-
E
|
114
|
+
task(:install_locally, :except => { :no_release => true }) {
|
115
|
+
run_locally(_install(:jar_file => sbt_jar_file_local, :jar_url => sbt_jar_url))
|
105
116
|
}
|
106
117
|
|
118
|
+
def template(file)
|
119
|
+
if File.file?(file)
|
120
|
+
File.read(file)
|
121
|
+
elsif File.file?("#{file}.erb")
|
122
|
+
ERB.new(File.read(file)).result(binding)
|
123
|
+
else
|
124
|
+
abort("No such template: #{file} or #{file}.erb")
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
def _update_settings(files_map, options={})
|
129
|
+
execute = []
|
130
|
+
dirs = files_map.map { |src, dst| File.dirname(dst) }.uniq
|
131
|
+
execute << "mkdir -p #{dirs.join(' ')}" unless dirs.empty?
|
132
|
+
files_map.each do |src, dst|
|
133
|
+
execute << "( diff -u #{dst} #{src} || mv -f #{src} #{dst} )"
|
134
|
+
cleanup = options.fetch(:cleanup, [])
|
135
|
+
execute << "rm -f #{cleanup.join(' ')}" unless cleanup.empty?
|
136
|
+
end
|
137
|
+
execute.join(' && ')
|
138
|
+
end
|
139
|
+
|
107
140
|
task(:update_settings, :roles => :app, :except => { :no_release => true }) {
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
src_file = File.join(sbt_template_path, file)
|
115
|
-
dst_file = File.join(sbt_settings_path, file)
|
116
|
-
run(<<-E)
|
117
|
-
( test -d #{File.dirname(dst_file)} || mkdir -p #{File.dirname(dst_file)} ) &&
|
118
|
-
( test -f #{dst_file} && mv -f #{dst_file} #{dst_file}.orig; true );
|
119
|
-
E
|
120
|
-
if File.file?(src_file)
|
121
|
-
put(File.read(src_file), tmp_file)
|
122
|
-
elsif File.file?("#{src_file}.erb")
|
123
|
-
put(ERB.new(File.read("#{src_file}.erb")).result(binding), tmp_file)
|
124
|
-
else
|
125
|
-
abort("sbt:update_settings: no such template found: #{src_file} or #{src_file}.erb")
|
141
|
+
srcs = sbt_settings.map { |f| File.join(sbt_template_path, f) }
|
142
|
+
tmps = sbt_settings.map { |f| t=Tempfile.new('sbt');s=t.path;t.close(true);s }
|
143
|
+
dsts = sbt_settings.map { |f| File.join(sbt_settings_path, f) }
|
144
|
+
begin
|
145
|
+
srcs.zip(tmps).each do |src, tmp|
|
146
|
+
put(template(src), tmp)
|
126
147
|
end
|
127
|
-
run(
|
128
|
-
|
129
|
-
|
148
|
+
run(_update_settings(tmps.zip(dsts), :cleanup => sbt_cleanup_settings)) unless tmps.empty?
|
149
|
+
ensure
|
150
|
+
run("rm -f #{tmps.join(' ')}") unless tmps.empty?
|
151
|
+
end
|
130
152
|
}
|
131
153
|
|
132
154
|
task(:update_settings_locally, :except => { :no_release => true }) {
|
133
|
-
sbt_settings_local.
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
(
|
139
|
-
E
|
140
|
-
if File.file?(src_file)
|
141
|
-
File.open(dst_file, 'w') { |fp|
|
142
|
-
fp.write(File.read(src_file))
|
143
|
-
}
|
144
|
-
elsif File.file?("#{src_file}.erb")
|
145
|
-
File.open(dst_file, 'w') { |fp|
|
146
|
-
fp.write(ERB.new(File.read("#{src_file}.erb")).result(binding))
|
147
|
-
}
|
148
|
-
else
|
149
|
-
abort("sbt:update_settings_locally: no such template: #{src_file} or #{src_file}.erb")
|
155
|
+
srcs = sbt_settings_local.map { |f| File.join(sbt_template_path, f) }
|
156
|
+
tmps = sbt_settings.map { |f| t=Tempfile.new('sbt');s=t.path;t.close(true);s }
|
157
|
+
dsts = sbt_settings_local.map { |f| File.join(sbt_settings_path_local, f) }
|
158
|
+
begin
|
159
|
+
srcs.zip(tmps).each do |src, tmp|
|
160
|
+
File.open(tmp, 'wb') { |fp| fp.write(template(src)) }
|
150
161
|
end
|
151
|
-
|
152
|
-
|
162
|
+
run_locally(_update_settings(tmps.zip(dsts), :cleanup => sbt_cleanup_settings_local)) unless tmps.empty?
|
163
|
+
ensure
|
164
|
+
run_locally("rm -f #{tmps.join(' ')}") unless tmps.empty?
|
165
|
+
end
|
153
166
|
}
|
154
167
|
|
155
168
|
desc("Update sbt build.")
|
@@ -182,7 +195,6 @@ module Capistrano
|
|
182
195
|
|
183
196
|
desc("Perform sbt build locally.")
|
184
197
|
task(:execute_locally, :roles => :app, :except => { :no_release => true }) {
|
185
|
-
setup_locally
|
186
198
|
on_rollback {
|
187
199
|
run_locally("cd #{sbt_project_path_local} && #{sbt_cmd_local} clean")
|
188
200
|
}
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: capistrano-sbt
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-10-18 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: capistrano
|
@@ -69,4 +69,3 @@ signing_key:
|
|
69
69
|
specification_version: 3
|
70
70
|
summary: a capistrano recipe to deploy sbt based projects.
|
71
71
|
test_files: []
|
72
|
-
has_rdoc:
|