-
-
Save noahgift/4bdad190724047a088632676faba34f1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
""" | |
Simple build tool for deploying lambdas to s3. | |
A tad sick of the cobbler's children going without shoes. | |
""" | |
from subprocess import call | |
from collections import OrderedDict | |
import click | |
from sensible.loginit import logger | |
log = logger(__name__) | |
LBD = "lambdas/lamba_build_dir" #lambda build dir | |
LDD = "lambdas/lamba_deploy_dir" #lambda deploy dir | |
@click.group() | |
def cli(): | |
"""Builds lambdas""" | |
@cli.command("build", help="Builds a lambda project") | |
@click.option("--name", help="Name of lambda folder to build") | |
@click.option("--dryrun", is_flag=True) | |
def go_build(name, dryrun): | |
"""Builds a lambda project""" | |
LBD_name = "%s/%s" % (LBD, name) | |
cmd1 = "rm -rf %s;mkdir %s && cp -r lambdas/%s %s" % (LBD, LBD, name, LBD) | |
msg1 = "INITIALIZING BUILD: %s" % cmd1 | |
cmd2 = "pip install -r lambdas/lambda_requirements.txt -t %s" % (LBD_name) | |
msg2 = "PIP INSTALL: Installing 3rd party python packages: %s" % cmd2 | |
cmd3 = "cp -r uca %s " % (LBD_name) | |
msg3 = "COPY UCA: placing uca into build dir: %s" % cmd3 | |
cmd4 = "rm -rf %s;mkdir %s" % (LDD, LDD) | |
msg4 = "MAKE LAMBDA DEPLOY DIR: %s" % cmd4 | |
cmd5 = "cd %s && zip -r %s.zip * && mv %s.zip ../../lamba_deploy_dir" % (LBD_name, name, name) | |
msg5 = "ZIP DEPLOY: %s" % cmd5 | |
cmd6 = "pwd && ls -l %s" % LDD | |
msg6 = "BUILT DEPLOY PACKAGE: %s | %s" % (name, cmd6) | |
#Note ordered dict is ensure build order | |
run_dict = OrderedDict([(cmd1,msg1), (cmd2,msg2), (cmd3,msg3), (cmd4,msg4), (cmd5,msg5), (cmd6,msg6)]) | |
count = 0 | |
if dryrun: | |
count += 1 | |
click.echo("DRY RUN BUILD OPTION......") | |
for cmd, msg in run_dict.items(): | |
click.echo("CMD [%s]: %s" % (count,msg)) | |
return True | |
#run build | |
count = 0 | |
for cmd, msg in run_dict.items(): | |
count += 1 | |
ret = call(cmd, shell=True) | |
if ret != 0: | |
click.echo("!!!!CMD FAILED!!!!: %s" % cmd) | |
click.echo("CMD [%s]: %s" % (count,msg)) | |
if __name__ == '__main__': | |
cli() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment