Skip to content

Commit 3c5f462

Browse files
troyreadyphobologic
authored andcommitted
add s3 remote package sources (#487)
* add s3 remote package sources * cleanup fetch_s3_package * add check for last modified date on s3 * rearrange imports for style (placing standard imports first) * add datetutil for utc conversion; cleanup doc warnings * add additional debug statements
1 parent 8483ebd commit 3c5f462

File tree

6 files changed

+329
-32
lines changed

6 files changed

+329
-32
lines changed

docs/config.rst

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ See the AWS documentation for `AWS CloudFormation Service Roles`_.
117117

118118
Remote Packages
119119
---------------
120-
The **package_sources** top level keyword can be used to define remote git
120+
The **package_sources** top level keyword can be used to define remote
121121
sources for blueprints (e.g., retrieving ``stacker_blueprints`` on github at
122122
tag ``v1.0.2``).
123123

@@ -136,13 +136,30 @@ The only required key for a git repository config is ``uri``, but ``branch``,
136136
- uri: git@github.com:contoso/foo.git
137137
commit: 12345678
138138

139-
Use the ``paths`` option when subdirectories of the repo should be added to
140-
Stacker's ``sys.path``.
141-
142139
If no specific commit or tag is specified for a repo, the remote repository
143140
will be checked for newer commits on every execution of Stacker.
144141

145-
Cloned repositories will be cached between builds; the cache location defaults
142+
For ``.tar.gz`` & ``zip`` archives on s3, specify a ``bucket`` & ``key``::
143+
144+
package_sources:
145+
s3:
146+
- bucket: mystackers3bucket
147+
key: archives/blueprints-v1.zip
148+
paths:
149+
- stacker_blueprints
150+
- bucket: anothers3bucket
151+
key: public/public-blueprints-v2.tar.gz
152+
requester_pays: true
153+
- bucket: yetanothers3bucket
154+
key: sallys-blueprints-v1.tar.gz
155+
# use_latest defaults to true - will update local copy if the
156+
# last modified date on S3 changes
157+
use_latest: false
158+
159+
Use the ``paths`` option when subdirectories of the repo/archive should be
160+
added to Stacker's ``sys.path``.
161+
162+
Cloned repos/archives will be cached between builds; the cache location defaults
146163
to ~/.stacker but can be manually specified via the **stacker_cache_dir** top
147164
level keyword.
148165

setup.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
"colorama~=0.3.7",
1414
"formic~=0.9b",
1515
"gitpython~=2.0",
16-
"schematics~=2.0.1"
16+
"schematics~=2.0.1",
17+
"python-dateutil~=2.0"
1718
]
1819

1920
tests_require = [

stacker/config/__init__.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,9 +242,21 @@ class GitPackageSource(Model):
242242
configs = ListType(StringType, serialize_when_none=False)
243243

244244

245+
class S3PackageSource(Model):
246+
bucket = StringType(required=True)
247+
248+
key = StringType(required=True)
249+
250+
use_latest = BooleanType(serialize_when_none=False)
251+
252+
requester_pays = BooleanType(serialize_when_none=False)
253+
254+
245255
class PackageSources(Model):
246256
git = ListType(ModelType(GitPackageSource))
247257

258+
s3 = ListType(ModelType(S3PackageSource))
259+
248260

249261
class Hook(Model):
250262
path = StringType(required=True)

stacker/tests/test_config.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,15 @@ def test_parse(self):
198198
args:
199199
domain: mydomain.com
200200
package_sources:
201+
s3:
202+
- bucket: acmecorpbucket
203+
key: public/acmecorp-blueprints-v1.zip
204+
- bucket: examplecorpbucket
205+
key: public/examplecorp-blueprints-v2.tar.gz
206+
requester_pays: true
207+
- bucket: anotherexamplebucket
208+
key: example-blueprints-v3.tar.gz
209+
use_latest: false
201210
git:
202211
- uri: git@github.com:acmecorp/stacker_blueprints.git
203212
- uri: git@github.com:remind101/stacker_blueprints.git
@@ -250,6 +259,15 @@ def test_parse(self):
250259
args:
251260
domain: mydomain.com
252261
package_sources:
262+
s3:
263+
- bucket: acmecorpbucket
264+
key: public/acmecorp-blueprints-v1.zip
265+
- bucket: examplecorpbucket
266+
key: public/examplecorp-blueprints-v2.tar.gz
267+
requester_pays: true
268+
- bucket: anotherexamplebucket
269+
key: example-blueprints-v3.tar.gz
270+
use_latest: false
253271
git:
254272
- uri: git@github.com:acmecorp/stacker_blueprints.git
255273
- uri: git@github.com:remind101/stacker_blueprints.git
@@ -292,6 +310,25 @@ def test_parse(self):
292310
self.assertEqual(
293311
hooks[0].args, {"domain": "mydomain.com"})
294312

313+
self.assertEqual(
314+
config.package_sources.s3[0].bucket,
315+
"acmecorpbucket")
316+
self.assertEqual(
317+
config.package_sources.s3[0].key,
318+
"public/acmecorp-blueprints-v1.zip")
319+
self.assertEqual(
320+
config.package_sources.s3[1].bucket,
321+
"examplecorpbucket")
322+
self.assertEqual(
323+
config.package_sources.s3[1].key,
324+
"public/examplecorp-blueprints-v2.tar.gz")
325+
self.assertEqual(
326+
config.package_sources.s3[1].requester_pays,
327+
True)
328+
self.assertEqual(
329+
config.package_sources.s3[2].use_latest,
330+
False)
331+
295332
self.assertEqual(
296333
config.package_sources.git[0].uri,
297334
"git@github.com:acmecorp/stacker_blueprints.git")

stacker/tests/test_util.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@
2020
get_client_region,
2121
get_s3_endpoint,
2222
s3_bucket_location_constraint,
23+
Extractor,
24+
TarExtractor,
25+
TarGzipExtractor,
26+
ZipExtractor,
2327
SourceProcessor
2428
)
2529

@@ -141,6 +145,15 @@ def test_s3_bucket_location_constraint(self):
141145
result
142146
)
143147

148+
def test_extractors(self):
149+
self.assertEqual(Extractor('test.zip').archive, 'test.zip')
150+
self.assertEqual(TarExtractor().extension(), '.tar')
151+
self.assertEqual(TarGzipExtractor().extension(), '.tar.gz')
152+
self.assertEqual(ZipExtractor().extension(), '.zip')
153+
for i in [TarExtractor(), ZipExtractor(), ZipExtractor()]:
154+
i.set_archive('/tmp/foo')
155+
self.assertEqual(i.archive.endswith(i.extension()), True)
156+
144157
def test_SourceProcessor_helpers(self):
145158
with mock.patch.object(SourceProcessor,
146159
'create_cache_directories',
@@ -151,6 +164,10 @@ def test_SourceProcessor_helpers(self):
151164
sp.sanitize_git_path('git@github.com:foo/bar.git'),
152165
'git_github.com_foo_bar'
153166
)
167+
self.assertEqual(
168+
sp.sanitize_uri_path('http://example.com/foo/bar.gz@1'),
169+
'http___example.com_foo_bar.gz_1'
170+
)
154171
self.assertEqual(
155172
sp.sanitize_git_path('git@github.com:foo/bar.git', 'v1'),
156173
'git_github.com_foo_bar-v1'

0 commit comments

Comments
 (0)