mirror of
https://github.com/kennethreitz/bob-builder-1.git
synced 2026-06-05 06:56:13 +00:00
add ability to override the s3 archive file names
if given (via --name) the override name is passed to the formula as the second argument
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
*.py[cod]
|
||||
*.egg-info/
|
||||
build/
|
||||
builds/
|
||||
dist/
|
||||
src/
|
||||
|
||||
+10
-8
@@ -1,13 +1,14 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""Usage: bob build <formula>
|
||||
bob deploy <formula> [--overwrite]
|
||||
"""Usage: bob build <formula> [--name=FILE]
|
||||
bob deploy <formula> [--overwrite] [--name=<FILE>]
|
||||
|
||||
Build formula and optionally deploy it.
|
||||
|
||||
Options:
|
||||
-h --help
|
||||
--overwrite allow overwriting of deployed archives.
|
||||
--name=<path> allow separate name for the archived output
|
||||
|
||||
Configuration:
|
||||
Environment Variables: AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, S3_BUCKET, S3_PREFIX (optional), UPSTREAM_S3_BUCKET (optional), UPSTREAM_S3_PREFIX (optional)
|
||||
@@ -21,8 +22,8 @@ from .models import Formula
|
||||
from .utils import print_stderr
|
||||
|
||||
|
||||
def build(formula):
|
||||
f = Formula(path=formula)
|
||||
def build(formula, name):
|
||||
f = Formula(path=formula, override_path=name)
|
||||
|
||||
try:
|
||||
assert f.exists
|
||||
@@ -36,8 +37,8 @@ def build(formula):
|
||||
return f
|
||||
|
||||
|
||||
def deploy(formula, overwrite):
|
||||
f = build(formula)
|
||||
def deploy(formula, overwrite, name):
|
||||
f = build(formula, name)
|
||||
|
||||
print('Archiving.')
|
||||
f.archive()
|
||||
@@ -53,12 +54,13 @@ def main():
|
||||
do_build = args['build']
|
||||
do_deploy = args['deploy']
|
||||
do_overwrite = args['--overwrite']
|
||||
do_name = args['--name']
|
||||
|
||||
if do_build:
|
||||
build(formula)
|
||||
build(formula, name=do_name)
|
||||
|
||||
if do_deploy:
|
||||
deploy(formula, overwrite=do_overwrite)
|
||||
deploy(formula, overwrite=do_overwrite, name=do_name)
|
||||
|
||||
|
||||
def dispatch():
|
||||
|
||||
+14
-3
@@ -36,9 +36,10 @@ sys.stderr = os.fdopen(sys.stderr.fileno(), 'w', 0)
|
||||
|
||||
class Formula(object):
|
||||
|
||||
def __init__(self, path):
|
||||
def __init__(self, path, override_path=None):
|
||||
self.path = path
|
||||
self.archived_path = None
|
||||
self.override_path = override_path
|
||||
|
||||
if not S3_BUCKET:
|
||||
print_stderr('The environment variable S3_BUCKET must be set to the bucket name.')
|
||||
@@ -135,7 +136,11 @@ class Formula(object):
|
||||
print('Building formula {} in {}:\n'.format(self.path, cwd_path))
|
||||
|
||||
# Execute the formula script.
|
||||
p = process(["/usr/bin/env", "bash", "--", self.full_path, self.build_path], cwd=cwd_path)
|
||||
args = ["/usr/bin/env", "bash", "--", self.full_path, self.build_path]
|
||||
if self.override_path:
|
||||
args.append(self.override_path)
|
||||
|
||||
p = process(args, cwd=cwd_path)
|
||||
|
||||
pipe(p.stdout, sys.stdout, indent=True)
|
||||
p.wait()
|
||||
@@ -162,7 +167,13 @@ class Formula(object):
|
||||
print_stderr('Deploy requires valid AWS credentials.')
|
||||
sys.exit(1)
|
||||
|
||||
key_name = '{}{}.tar.gz'.format(S3_PREFIX, self.path)
|
||||
if override_name != None:
|
||||
name = self.override_path
|
||||
else:
|
||||
name = self.path
|
||||
|
||||
key_name = '{}{}.tar.gz'.format(S3_PREFIX, name)
|
||||
|
||||
key = self.bucket.get_key(key_name)
|
||||
|
||||
if key:
|
||||
|
||||
Reference in New Issue
Block a user