...
1#!/usr/bin/env python3
2"""Verify that all GA artifacts got pushed."""
3
4import os.path
5import sys
6import argparse
7import subprocess
8import fileinput
9from contextlib import contextmanager
10from typing import Dict, Generator, Optional, Tuple, cast
11
12from lib import check_artifacts, re_rc
13from lib.uiutil import Checker, CheckResult, run
14
15def main(rc_ver: str, docker_image: str, helm_ver: str, s3_bucket: str, s3_key: str) -> int:
16 checker = Checker()
17
18 @contextmanager
19 def check(name: str) -> Generator[CheckResult, None, None]:
20 with checker.check(name) as subcheck:
21 # time.sleep(1) # it's stupid, but honestly the delay makes the output more readable
22 yield subcheck
23 with check(f"Check for docker image {docker_image}"):
24 check_artifacts.docker_pull(docker_image)
25 with check(f"Check helm chart"):
26 subprocess.run(['helm', 'repo', 'rm', 'emissary-dev'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
27 subprocess.run(['helm', 'repo', 'add', 'emissary-dev',
28 'https://s3.amazonaws.com/{}/{}'.format(s3_bucket, s3_key)], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
29 p = subprocess.run(['helm', 'template', '--devel', '--version', helm_ver, 'emissary-dev/emissary-ingress'], capture_output=True, check=True, text=True)
30 found = False
31 lines = p.stdout.splitlines()
32 for line in lines:
33 line = line.strip()
34 if line.startswith('image:'):
35 if docker_image in line:
36 found = True
37 if not found:
38 raise AssertionError("Image not found in chart")
39 with check(f"checking s3 yaml files"):
40 s3_url = f"https://s3.amazonaws.com/{s3_bucket}/yaml/emissary/{rc_ver}/emissary-emissaryns.yaml"
41 info = check_artifacts.http_cat(s3_url).decode('utf-8')
42 found = False
43 for line in info.split("\n"):
44 line = line.strip()
45 if line.startswith('image:'):
46 if docker_image in line:
47 found = True
48 if not found:
49 raise AssertionError("Image not found in yaml")
50
51 if not checker.ok:
52 return 1
53 return 0
54
55
56if __name__ == '__main__':
57 parser = argparse.ArgumentParser(description='Edit image values for ambassador helm charts.')
58 parser.add_argument('--rc-version', required=True)
59 parser.add_argument('--docker-image', required=True)
60 parser.add_argument('--s3-bucket', default='datawire-static-files')
61 parser.add_argument('--s3-key', default='charts-dev')
62 parser.add_argument('--helm-version', required=True)
63 args = parser.parse_args()
64
65 include_docker = True
66
67 if not re_rc.match(args.rc_version):
68 sys.stderr.write(f"{args.rc_version} does not match X.Y.Z-rc.N")
69 sys.exit(2)
70
71 sys.exit(main(rc_ver=args.rc_version, docker_image=args.docker_image, helm_ver=args.helm_version, s3_bucket=args.s3_bucket, s3_key=args.s3_key))
View as plain text