apcera-stager-api 0.2.5 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +0 -1
- data/apcera-stager-api-contrib.gemspec +1 -1
- data/lib/apcera/stager/stager.rb +29 -15
- data/spec/apcera/stager/stager_spec.rb +21 -3
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fc3737fcfd86c07d0f4009741e6168079d80ceb3
|
4
|
+
data.tar.gz: 0ad42b5acc9d9e75a146dec1cba0f73664f1e7dc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4ea8c40730ad9005247a057f21bc59ce202c255fde4dc36651af9c51ff3598bb54c13dc120cfb14debae6e953d44e5f8453721750db785084aa9fcf5c48b5501
|
7
|
+
data.tar.gz: a74dc48fc698a0485ed038af8dc47ef8f32adcb6c93b3f849f72041d961603994392fd9249520f3d4a1baf6a1fa2f9304a4aa4843cd794e0240b301ba70197be
|
data/.travis.yml
CHANGED
@@ -15,7 +15,7 @@ Gem::Specification.new do |gem|
|
|
15
15
|
gem.test_files = `git ls-files -- {spec}/*`.split("\n")
|
16
16
|
gem.name = "apcera-stager-api"
|
17
17
|
gem.require_paths = ["lib"]
|
18
|
-
gem.version = "0.
|
18
|
+
gem.version = "0.3.0"
|
19
19
|
|
20
20
|
gem.add_development_dependency 'rspec', '~> 2.6.0'
|
21
21
|
gem.add_development_dependency 'rake'
|
data/lib/apcera/stager/stager.rb
CHANGED
@@ -69,11 +69,12 @@ module Apcera
|
|
69
69
|
fail e
|
70
70
|
end
|
71
71
|
|
72
|
-
# Execute a command in the
|
72
|
+
# Execute a command in the directory your package was extracted to (or where
|
73
|
+
# you manually set @app_dir). Useful helper.
|
73
74
|
def execute_app(cmd)
|
74
|
-
raise_app_path_error if @
|
75
|
+
raise_app_path_error if @run_path == nil
|
75
76
|
Bundler.with_clean_env do
|
76
|
-
Dir.chdir(@
|
77
|
+
Dir.chdir(@run_path) do |run_path|
|
77
78
|
result = system(cmd, @system_options)
|
78
79
|
if !result
|
79
80
|
raise Apcera::Error::ExecuteError.new("failed to execute: #{cmd}.\n")
|
@@ -86,19 +87,26 @@ module Apcera
|
|
86
87
|
fail e
|
87
88
|
end
|
88
89
|
|
89
|
-
# Extract the package to a
|
90
|
-
|
91
|
-
|
90
|
+
# Extract the package to a location within staging path, optionally creating
|
91
|
+
# the named folder first and extract into it. If a location parameter is
|
92
|
+
# given, when upload is run the folder will be uploaded up along with the
|
93
|
+
# files. In either case, execute_app will run commands in the location
|
94
|
+
# where files were extracted to.
|
95
|
+
def extract(location="")
|
96
|
+
@app_path=File.join(@root_path, "staging")
|
92
97
|
Dir.mkdir(@app_path) unless Dir.exists?(@app_path)
|
93
98
|
|
99
|
+
@run_path = location.empty? ? @app_path : File.join(@app_path, location)
|
100
|
+
Dir.mkdir(@run_path) unless Dir.exists?(@run_path)
|
101
|
+
|
94
102
|
execute_app("tar -zxf #{@pkg_path}")
|
95
103
|
rescue => e
|
96
104
|
fail e
|
97
105
|
end
|
98
106
|
|
99
|
-
# Upload the new package to the staging coordinator. If we have an app
|
100
|
-
# send that to the staging coordinator. If no app was ever
|
101
|
-
#
|
107
|
+
# Upload the new package to the staging coordinator. If we have an app
|
108
|
+
# extracted we send that to the staging coordinator. If no app was ever
|
109
|
+
# extracted it is a noop.
|
102
110
|
def upload
|
103
111
|
if @app_path == nil
|
104
112
|
unless File.exist?(@pkg_path)
|
@@ -107,8 +115,7 @@ module Apcera
|
|
107
115
|
|
108
116
|
upload_file(@pkg_path)
|
109
117
|
else
|
110
|
-
|
111
|
-
execute_app("cd #{app_path}/.. && tar czf #{@updated_pkg_path} #{app_dir}")
|
118
|
+
execute_app("tar czf #{@updated_pkg_path} ./*")
|
112
119
|
|
113
120
|
upload_file(@updated_pkg_path)
|
114
121
|
end
|
@@ -116,7 +123,7 @@ module Apcera
|
|
116
123
|
fail e
|
117
124
|
end
|
118
125
|
|
119
|
-
# Snapshot the stager filesystem for app
|
126
|
+
# Snapshot the stager filesystem for app.
|
120
127
|
def snapshot
|
121
128
|
response = RestClient.post(@stager_url+"/snapshot", {})
|
122
129
|
rescue => e
|
@@ -267,7 +274,7 @@ module Apcera
|
|
267
274
|
self.meta["environment"]["START_COMMAND"]
|
268
275
|
end
|
269
276
|
|
270
|
-
# Easily set the start command
|
277
|
+
# Easily set the start command.
|
271
278
|
def start_command=(val)
|
272
279
|
self.environment_add("START_COMMAND", val)
|
273
280
|
end
|
@@ -277,7 +284,7 @@ module Apcera
|
|
277
284
|
self.meta["environment"]["START_PATH"]
|
278
285
|
end
|
279
286
|
|
280
|
-
# Easily set the start path
|
287
|
+
# Easily set the start path.
|
281
288
|
def start_path=(val)
|
282
289
|
self.environment_add("START_PATH", val)
|
283
290
|
end
|
@@ -297,7 +304,7 @@ module Apcera
|
|
297
304
|
exit code
|
298
305
|
end
|
299
306
|
|
300
|
-
# Output to stderr
|
307
|
+
# Output to stderr.
|
301
308
|
def output_error(text)
|
302
309
|
$stderr.puts text
|
303
310
|
end
|
@@ -307,6 +314,13 @@ module Apcera
|
|
307
314
|
$stdout.puts text
|
308
315
|
end
|
309
316
|
|
317
|
+
# Set @app_path, the location that will uploaded. Also updates location
|
318
|
+
# where execute_app will run commands from.
|
319
|
+
def app_path=(value)
|
320
|
+
@app_path=value
|
321
|
+
@run_path=value
|
322
|
+
end
|
323
|
+
|
310
324
|
private
|
311
325
|
|
312
326
|
def raise_app_path_error
|
@@ -97,7 +97,16 @@ describe Apcera::Stager do
|
|
97
97
|
|
98
98
|
it "should decompress the package to a supplied path" do
|
99
99
|
@stager.extract(@appdir)
|
100
|
-
|
100
|
+
extracted_path = File.join(@stager.root_path, "staging", @appdir)
|
101
|
+
expected_path = File.join(@stager.root_path, "staging")
|
102
|
+
|
103
|
+
File.exist?(extracted_path).should == true
|
104
|
+
@stager.app_path.should == expected_path
|
105
|
+
end
|
106
|
+
|
107
|
+
it "should decompress the package without a supplied path" do
|
108
|
+
@stager.extract()
|
109
|
+
expected_path = File.join(@stager.root_path, "staging")
|
101
110
|
File.exist?(expected_path).should == true
|
102
111
|
@stager.app_path.should == expected_path
|
103
112
|
end
|
@@ -125,7 +134,7 @@ describe Apcera::Stager do
|
|
125
134
|
Bundler.should_receive(:with_clean_env).at_least(:once).and_yield
|
126
135
|
|
127
136
|
@stager.execute("cat thing").should == nil
|
128
|
-
@stager.execute("cat #{File.join(@stager.app_path, "app", "Gemfile")}").should == true
|
137
|
+
@stager.execute("cat #{File.join(@stager.app_path, @appdir, "app", "Gemfile")}").should == true
|
129
138
|
end
|
130
139
|
|
131
140
|
it "should bubble errors to fail" do
|
@@ -152,6 +161,15 @@ describe Apcera::Stager do
|
|
152
161
|
@stager.execute_app("cat #{File.join("app", "Gemfile")}").should == true
|
153
162
|
end
|
154
163
|
|
164
|
+
it "should execute commands in extracted dir with clean bundler environment" do
|
165
|
+
Bundler.should_receive(:with_clean_env).at_least(:once).and_yield
|
166
|
+
|
167
|
+
@stager.extract()
|
168
|
+
|
169
|
+
@stager.execute_app("cat thing").should == nil
|
170
|
+
@stager.execute_app("cat #{File.join("app", "Gemfile")}").should == true
|
171
|
+
end
|
172
|
+
|
155
173
|
it "should bubble errors to fail when app path is missing (no extract)" do
|
156
174
|
@stager.should_receive(:exit0r).with(1) { raise }
|
157
175
|
|
@@ -191,7 +209,7 @@ describe Apcera::Stager do
|
|
191
209
|
|
192
210
|
@stager.extract(@appdir)
|
193
211
|
|
194
|
-
@stager.should_receive(:execute_app).with("
|
212
|
+
@stager.should_receive(:execute_app).with("tar czf #{@stager.updated_pkg_path} ./*").and_return
|
195
213
|
|
196
214
|
@stager.upload
|
197
215
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: apcera-stager-api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Josh Ellithorpe
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-02-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rest-client
|
@@ -182,7 +182,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
182
182
|
version: '0'
|
183
183
|
requirements: []
|
184
184
|
rubyforge_project:
|
185
|
-
rubygems_version: 2.4.
|
185
|
+
rubygems_version: 2.4.8
|
186
186
|
signing_key:
|
187
187
|
specification_version: 4
|
188
188
|
summary: Apcera Stager API library which makes it super easy to write stagers for
|