continuum-stager-api 0.1.7 → 0.1.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/apcera-stager-api-contrib.gemspec +1 -1
- data/lib/apcera/stager/error.rb +1 -0
- data/lib/apcera/stager/stager.rb +20 -10
- data/spec/apcera/stager/stager_spec.rb +24 -4
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 12edd2b8b9c59ea9e1559d0d82a70dcd80974852
|
4
|
+
data.tar.gz: 4ff0c5b27bcce22bbfceeeb0efbbb42ec58f9156
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 882efbf11bd13e8d214ab3da90bec6305fd6d77d3bd1bf8e1c02b5b428ebed875a79a1df9d92db6882b08d1fe51c960dcd059fd8a6f84ce04f742f4d30f66621
|
7
|
+
data.tar.gz: 428d0d08dd667c23809f312c89cbde645d0971b8f4605788faafe4c92e1a3ac3199667972172a16ccfa31b55e524f1b780eaa73d23bac41ada92dacf77290ae9
|
@@ -15,7 +15,7 @@ Gem::Specification.new do |gem|
|
|
15
15
|
gem.test_files = `git ls-files -- {spec}/*`.split("\n")
|
16
16
|
gem.name = "continuum-stager-api"
|
17
17
|
gem.require_paths = ["lib"]
|
18
|
-
gem.version = "0.1.
|
18
|
+
gem.version = "0.1.8"
|
19
19
|
|
20
20
|
gem.add_development_dependency 'rspec', '~> 2.6.0'
|
21
21
|
gem.add_development_dependency 'rake'
|
data/lib/apcera/stager/error.rb
CHANGED
data/lib/apcera/stager/stager.rb
CHANGED
@@ -41,6 +41,7 @@ module Apcera
|
|
41
41
|
|
42
42
|
# Execute a command in the app dir. Useful helper.
|
43
43
|
def execute_app(cmd)
|
44
|
+
raise_app_path_error if @app_path == nil
|
44
45
|
Bundler.with_clean_env do
|
45
46
|
Dir.chdir(@app_path) do |app_path|
|
46
47
|
result = system(cmd, @system_options)
|
@@ -67,12 +68,13 @@ module Apcera
|
|
67
68
|
|
68
69
|
# Upload the new package to the staging coordinator
|
69
70
|
def upload
|
71
|
+
raise_app_path_error if @app_path == nil
|
70
72
|
app_dir = Pathname.new(@app_path).relative_path_from(Pathname.new(@root_path)).to_s
|
71
73
|
execute_app("cd #{app_path}/.. && tar czf #{@updated_pkg_path} #{app_dir}")
|
72
74
|
|
73
75
|
sha1 = Digest::SHA1.file(@updated_pkg_path)
|
74
76
|
File.open(@updated_pkg_path, "rb") do |f|
|
75
|
-
response = RestClient.post(@stager_url+"/data?sha1=#{sha1.to_s}", f
|
77
|
+
response = RestClient.post(@stager_url+"/data?sha1=#{sha1.to_s}", f, { :content_type => "application/octet-stream" } )
|
76
78
|
end
|
77
79
|
rescue => e
|
78
80
|
fail e
|
@@ -87,7 +89,7 @@ module Apcera
|
|
87
89
|
|
88
90
|
# Add environment variable to package.
|
89
91
|
def environment_add(key, value)
|
90
|
-
response = RestClient.put(
|
92
|
+
response = RestClient.put(stager_meta_url, {
|
91
93
|
:resource => "environment",
|
92
94
|
:action => "add",
|
93
95
|
:key => key,
|
@@ -99,7 +101,7 @@ module Apcera
|
|
99
101
|
|
100
102
|
# Delete environment variable from package.
|
101
103
|
def environment_remove(key, value)
|
102
|
-
response = RestClient.put(
|
104
|
+
response = RestClient.put(stager_meta_url, {
|
103
105
|
:resource => "environment",
|
104
106
|
:action => "remove",
|
105
107
|
:key => key,
|
@@ -111,7 +113,7 @@ module Apcera
|
|
111
113
|
|
112
114
|
# Add provides to package.
|
113
115
|
def provides_add(type, name)
|
114
|
-
response = RestClient.put(
|
116
|
+
response = RestClient.put(stager_meta_url, {
|
115
117
|
:resource => "provides",
|
116
118
|
:action => "add",
|
117
119
|
:type => type,
|
@@ -123,7 +125,7 @@ module Apcera
|
|
123
125
|
|
124
126
|
# Delete provides from package.
|
125
127
|
def provides_remove(key, value)
|
126
|
-
response = RestClient.put(
|
128
|
+
response = RestClient.put(stager_meta_url, {
|
127
129
|
:resource => "provides",
|
128
130
|
:action => "remove",
|
129
131
|
:type => type,
|
@@ -138,7 +140,7 @@ module Apcera
|
|
138
140
|
exists = self.meta["dependencies"].detect { |dep| dep["type"] == type && dep["name"] == name }
|
139
141
|
return false if exists
|
140
142
|
|
141
|
-
response = RestClient.put(
|
143
|
+
response = RestClient.put(stager_meta_url, {
|
142
144
|
:resource => "dependencies",
|
143
145
|
:action => "add",
|
144
146
|
:type => type,
|
@@ -155,7 +157,7 @@ module Apcera
|
|
155
157
|
exists = self.meta["dependencies"].detect { |dep| dep["type"] == type && dep["name"] == name}
|
156
158
|
return false if !exists
|
157
159
|
|
158
|
-
response = RestClient.put(
|
160
|
+
response = RestClient.put(stager_meta_url, {
|
159
161
|
:resource => "dependencies",
|
160
162
|
:action => "remove",
|
161
163
|
:type => type,
|
@@ -169,7 +171,7 @@ module Apcera
|
|
169
171
|
|
170
172
|
# Add template to package.
|
171
173
|
def templates_add(path, left_delimiter = "{{", right_delimiter = "}}")
|
172
|
-
response = RestClient.put(
|
174
|
+
response = RestClient.put(stager_meta_url, {
|
173
175
|
:resource => "templates",
|
174
176
|
:action => "add",
|
175
177
|
:path => path,
|
@@ -182,7 +184,7 @@ module Apcera
|
|
182
184
|
|
183
185
|
# Delete template from package.
|
184
186
|
def templates_remove(path, left_delimiter = "{{", right_delimiter = "}}")
|
185
|
-
response = RestClient.put(
|
187
|
+
response = RestClient.put(stager_meta_url, {
|
186
188
|
:resource => "templates",
|
187
189
|
:action => "remove",
|
188
190
|
:path => path,
|
@@ -195,7 +197,7 @@ module Apcera
|
|
195
197
|
|
196
198
|
# Get metadata for the package being staged.
|
197
199
|
def meta
|
198
|
-
response = RestClient.get(
|
200
|
+
response = RestClient.get(stager_meta_url)
|
199
201
|
return JSON.parse(response.to_s)
|
200
202
|
rescue => e
|
201
203
|
output_error "Error: #{e.message}.\n"
|
@@ -272,6 +274,10 @@ module Apcera
|
|
272
274
|
|
273
275
|
private
|
274
276
|
|
277
|
+
def raise_app_path_error
|
278
|
+
raise Apcera::Error::AppPathError.new("app path not set, please run extract!\n")
|
279
|
+
end
|
280
|
+
|
275
281
|
def setup_environment
|
276
282
|
# When staging we use the root path. These are overridden in tests.
|
277
283
|
@root_path = "/tmp"
|
@@ -279,5 +285,9 @@ module Apcera
|
|
279
285
|
@updated_pkg_path = File.join(@root_path, UPDATED_PKG_NAME)
|
280
286
|
@system_options = {}
|
281
287
|
end
|
288
|
+
|
289
|
+
def stager_meta_url
|
290
|
+
@stager_url + "/meta"
|
291
|
+
end
|
282
292
|
end
|
283
293
|
end
|
@@ -128,20 +128,29 @@ describe Apcera::Stager do
|
|
128
128
|
VCR.use_cassette('download') do
|
129
129
|
@stager.download
|
130
130
|
end
|
131
|
-
|
132
|
-
@stager.extract(@appdir)
|
133
131
|
end
|
134
132
|
|
135
133
|
it "should execute commands in app dir with clean bundler environment" do
|
136
134
|
Bundler.should_receive(:with_clean_env).at_least(:once).and_yield
|
137
135
|
|
136
|
+
@stager.extract(@appdir)
|
137
|
+
|
138
138
|
@stager.execute_app("cat thing").should == nil
|
139
139
|
@stager.execute_app("cat #{File.join("app", "Gemfile")}").should == true
|
140
140
|
end
|
141
141
|
|
142
|
+
it "should bubble errors to fail when app path is missing (no extract)" do
|
143
|
+
@stager.should_receive(:exit0r).with(1) { raise }
|
144
|
+
|
145
|
+
cmd = "cat thing"
|
146
|
+
expect {@stager.execute_app(cmd) }.to raise_error(Apcera::Error::AppPathError, "app path not set, please run extract!\n")
|
147
|
+
end
|
148
|
+
|
142
149
|
it "should bubble errors to fail" do
|
143
150
|
@stager.should_receive(:exit0r).with(1) { raise }
|
144
151
|
|
152
|
+
@stager.extract(@appdir)
|
153
|
+
|
145
154
|
cmd = "cat thing"
|
146
155
|
expect {@stager.execute_app(cmd) }.to raise_error(Apcera::Error::ExecuteError, "failed to execute: #{cmd}.\n")
|
147
156
|
end
|
@@ -152,11 +161,11 @@ describe Apcera::Stager do
|
|
152
161
|
VCR.use_cassette('download') do
|
153
162
|
@stager.download
|
154
163
|
end
|
155
|
-
|
156
|
-
@stager.extract(@appdir)
|
157
164
|
end
|
158
165
|
|
159
166
|
it "should compress a new package and send to the staging coordinator" do
|
167
|
+
@stager.extract(@appdir)
|
168
|
+
|
160
169
|
VCR.use_cassette('upload') do
|
161
170
|
@stager.upload
|
162
171
|
end
|
@@ -165,14 +174,25 @@ describe Apcera::Stager do
|
|
165
174
|
end
|
166
175
|
|
167
176
|
it "should compress using tar czf" do
|
177
|
+
@stager.extract(@appdir)
|
178
|
+
|
168
179
|
@stager.should_receive(:execute_app).with("cd #{@stager.app_path}/.. && tar czf #{@stager.updated_pkg_path} #{@appdir}").and_return
|
169
180
|
|
170
181
|
@stager.upload
|
171
182
|
end
|
172
183
|
|
184
|
+
it "should bubble errors to fail when app path is missing (no extract)" do
|
185
|
+
@stager.should_receive(:exit0r).with(1) { raise }
|
186
|
+
|
187
|
+
cmd = "cat thing"
|
188
|
+
expect {@stager.upload }.to raise_error(Apcera::Error::AppPathError, "app path not set, please run extract!\n")
|
189
|
+
end
|
190
|
+
|
173
191
|
it "should bubble errors to fail" do
|
174
192
|
@stager.should_receive(:exit0r).with(1) { raise }
|
175
193
|
|
194
|
+
@stager.extract(@appdir)
|
195
|
+
|
176
196
|
VCR.use_cassette('invalid/upload') do
|
177
197
|
expect { @stager.upload }.to raise_error(RestClient::ResourceNotFound, "404 Resource Not Found")
|
178
198
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: continuum-stager-api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Josh Ellithorpe
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-08-
|
11
|
+
date: 2014-08-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rest-client
|