def deploy(args): svc, func = get_svc_func(args) if func: deploy_cmd = f"cd services/{svc} && env {envs()} {SLS} deploy function --stage {CFG.DEPLOYED_ENV} --aws-s3-accelerate -v --function {func}" else: deploy_cmd = f"cd services/{svc} && env {envs()} {SLS} deploy --stage {CFG.DEPLOYED_ENV} --aws-s3-accelerate -v" call(deploy_cmd, stdout=None, stderr=None)
def curl(args): svc, func = defaults(*args, svc="fxa", func=None) assert svc in SVCS, f"{svc} is not a valid service in {SVCS}" funcs = ([func] if func else [func for func in get_svcs_to_funcs()[svc] if func != "mia"]) for func in funcs: for route in ("version", "deployed"): cmd = f"curl --silent https://{CFG.DEPLOYED_ENV}.{svc}.mozilla-subhub.app/v1/{func}/{route}" call(f'echo "{cmd}"; {cmd}', stdout=None, stderr=None)
def curl(args): svc, func = svc_func(*args) funcs = [func] if func else [ func for func in get_svcs_to_funcs()[svc] if func != 'mia' ] for func in funcs: for route in ('version', 'deployed'): cmd = f'curl --silent https://{CFG.DEPLOYED_ENV}.{svc}.mozilla-subhub.app/v1/{func}/{route}' call(f'echo "{cmd}"; {cmd}', stdout=None, stderr=None)
def curl(args): svc, func = defaults(*args, svc='fxa', func=None) assert svc in SVCS, f'{svc} is not a valid service in {SVCS}' funcs = [func] if func else [ func for func in get_svcs_to_funcs()[svc] if func != 'mia' ] for func in funcs: for route in ('version', 'deployed'): cmd = f'curl --silent https://{CFG.DEPLOYED_ENV}.{svc}.mozilla-subhub.app/v1/{func}/{route}' call(f'echo "{cmd}"; {cmd}', stdout=None, stderr=None)
def deploy(args): svc, func = defaults(*args, svc='fxa', func=None) assert svc in SVCS, f'{svc} is not a valid service in {SVCS}' if func: funcs = get_svcs_to_funcs()[svc] assert func in funcs, f'{func} is not a valid function in {funcs}' if func: deploy_cmd = f'cd services/{svc} && env {envs()} {SLS} deploy function --stage {CFG.DEPLOYED_ENV} --aws-s3-accelerate -v --function {func}' else: deploy_cmd = f'cd services/{svc} && env {envs()} {SLS} deploy --stage {CFG.DEPLOYED_ENV} --aws-s3-accelerate -v' call(deploy_cmd, stdout=None, stderr=None)
def running(): mutex.acquire() pid = None try: pid = call(f'lsof -i:{CFG.DYNALITE_PORT} -t')[1].strip() except CalledProcessError: return None finally: mutex.release() mutex.acquire() try: args = call(f'ps -p {pid} -o args=')[1].strip() except CalledProcessError: return None finally: mutex.release() if cmd in args: return pid return None
def check_reqs(): ''' check requirements ''' installed = call('python3 -m pip freeze')[1].strip().split('\n') installed = [tuple(item.split('==')) for item in installed if '==' in item] required = [ line for line in open( 'automation_requirements.txt').read().strip().split('\n') if not line.startswith('#') ] required = [ tuple(item.split('==')) if '==' in item else (item, None) for item in required ] @lru_cache(3) def check(): def match_one(iname, iver, rname, rver=None): return (iname == rname and parse_version(iver) >= parse_version(rver or iver)) def match_any(installed, rname, rver): return any([ match_one(iname, iver, rname, rver) for iname, iver in installed ]) return [(rname, rver) for rname, rver in required if not match_any(installed, rname, rver)] def report(rname, rver): version = f'or at version {rver}' if rver else '' return f'echo "-> {rname} is not installed {version}"' return { 'name': 'reqs', 'task_dep': [ 'check:noroot', ], 'actions': [report(rname, rver) for rname, rver in check()] + [ 'echo "consider running \'./dodo.py\' or \'sudo pip install -r automation_requirements.txt\'"', 'false', ] if len(check()) else [], 'uptodate': [ lambda: len(check()) == 0, ], }
def check_reqs(): """ check requirements """ installed = call("python3 -m pip freeze")[1].strip().split("\n") installed = [tuple(item.split("==")) for item in installed if "==" in item] required = [ line for line in open( "automation_requirements.txt").read().strip().split("\n") if not line.startswith("#") ] required = [ tuple(item.split("==")) if "==" in item else (item, None) for item in required ] @lru_cache(3) def check(): def match_one(iname, iver, rname, rver=None): return iname == rname and parse_version(iver) >= parse_version( rver or iver) def match_any(installed, rname, rver): return any([ match_one(iname, iver, rname, rver) for iname, iver in installed ]) return [(rname, rver) for rname, rver in required if not match_any(installed, rname, rver)] def report(rname, rver): version = f"or at version {rver}" if rver else "" return f'echo "-> {rname} is not installed {version}"' return { "name": "reqs", "task_dep": ["check:noroot"], "actions": [report(rname, rver) for rname, rver in check()] + [ "echo \"consider running './dodo.py' or 'sudo pip install -r automation_requirements.txt'\"", "false", ] if len(check()) else [], "uptodate": [lambda: len(check()) == 0], }
def domain(args): svc, action = defaults(svc='fxa', action=None) assert action in ('create', 'delete'), "provide 'create' or 'delete'" domain_cmd = f'cd services/{svc} && env {envs()} {SLS} {action}_domain --stage {CFG.DEPLOYED_ENV} -v' call(domain_cmd, stdout=None, stderr=None)
def creds_check(): try: call('aws sts get-caller-identity') return True except CalledProcessError: return False
def check_hash(program): try: call(f'hash {program}') return True except CalledProcessError: return False
def local(args): svc, func = get_svc_func(args) local_cmd = f"env {envs()} docker-compose up --build" if func: local_cmd += f" {func}" call(local_cmd, stdout=None, stderr=None)
def docker_compose(args): docker_compose_args = " ".join(args) docker_compose_cmd = f"env {envs()} docker-compose {docker_compose_args}" call(docker_compose_cmd, stdout=None, stderr=None)