|
1 | 1 | from jinja2 import Environment, FileSystemLoader, ChoiceLoader, select_autoescape |
| 2 | +import yaml |
2 | 3 | import os |
3 | 4 | from pathlib import Path |
4 | 5 |
|
|
32 | 33 | autoescape=select_autoescape() |
33 | 34 | ) |
34 | 35 |
|
| 36 | + |
| 37 | +def get_key_value(obj, key): |
| 38 | + if hasattr(obj,'iteritems'): |
| 39 | + for k, v in obj.iteritems(): |
| 40 | + if k == key: |
| 41 | + return v |
| 42 | + if isinstance(v, dict): |
| 43 | + return get_key_value(v, key) |
| 44 | + elif isinstance(v, list): |
| 45 | + for d in v: |
| 46 | + return get_key_value(d, key) |
| 47 | + |
| 48 | +platform = "linux/amd64,linux/arm64,linux/arm/v7" |
| 49 | +variants = ["full", "slim", "alpine"] |
| 50 | +if os.environ.get('BUILDER_WORKFLOW_PATH', False): |
| 51 | + with open(os.environ['BUILDER_WORKFLOW_PATH'], "r") as stream: |
| 52 | + try: |
| 53 | + build_spec = yaml.safe_load(stream) |
| 54 | + platform = get_key_value(build_spec, "platform") |
| 55 | + strategy = get_key_value(build_spec, "strategy") |
| 56 | + if strategy and 'matrix' in strategy: |
| 57 | + if 'target_base' in strategy['matrix']: |
| 58 | + variants = strategy['matrix']['target_base'] |
| 59 | + except yaml.YAMLError as exc: |
| 60 | + print(exc) |
| 61 | + |
35 | 62 | variables = { |
36 | 63 | "package": os.environ["PACKAGE"], |
37 | 64 | "project_name": os.environ["PROJECT_NAME"], |
38 | 65 | "package_versions": os.environ["PACKAGE_VERSIONS"].split(), |
39 | 66 | "python_versions": os.environ["PYTHON_VERSIONS"].split(), |
40 | 67 | "organization": os.environ["ORGANIZATION"], |
41 | | - "repository": os.environ["REPOSITORY"] |
| 68 | + "repository": os.environ["REPOSITORY"], |
| 69 | + "platforms": platform.split(','), |
| 70 | + "variants": variants |
42 | 71 | } |
43 | 72 |
|
44 | 73 | for template_var in subtemplates: |
|
0 commit comments