blob: 4cb9c28307ff3e94078af7f3b992edeea3194507 [file] [log] [blame]
Mohammed Nasereb46b6c2022-08-29 21:45:29 -04001#!/usr/bin/env python3
2
3import yaml
4
Mohammed Naser5e7a5c82022-08-29 21:51:12 -04005PROJECTS = ["keystone"]
Mohammed Nasereb46b6c2022-08-29 21:45:29 -04006
7RELEASES = ["wallaby"]
8
9
10def get_ref_for_project(project, release):
11 return (
12 open(f"images/openstack/projects/{project}/{release}/ref", "r").read().strip()
13 )
14
15
16def get_profiles_for_project(project):
17 try:
18 return open(f"images/openstack/projects/{project}/profiles", "r").read().strip()
19 except FileNotFoundError:
20 return ""
21
22
23def get_dist_packages_for_project(project):
24 try:
25 return (
26 open(f"images/openstack/projects/{project}/dist-packages", "r")
27 .read()
28 .strip()
29 )
30 except FileNotFoundError:
31 return ""
32
33
34def get_pip_packages_for_project(project):
35 try:
36 return (
37 open(f"images/openstack/projects/{project}/pip-packages", "r")
38 .read()
39 .strip()
40 )
41 except FileNotFoundError:
42 return ""
43
44
45def get_build_args_for_project(project, release):
46 return {
47 "RELEASE": release,
48 "PROJECT": project,
49 "PROJECT_REF": get_ref_for_project(project, release),
50 "PROFILES": get_profiles_for_project(project),
51 "DIST_PACKAGES": get_dist_packages_for_project(project),
52 "PIP_PACKAGES": get_pip_packages_for_project(project),
53 }
54
55
56def get_platforms_for_project(project):
57 try:
58 return (
59 open(f"images/openstack/projects/{project}/platforms", "r").read().strip()
60 )
61 except FileNotFoundError:
62 return "linux/amd64"
63
64
65def get_job_for_project(project, release):
66 build_args = get_build_args_for_project(project, release)
67 ref = get_ref_for_project(project, release)
68
69 return {
Mohammed Naserf83c92c2022-08-29 21:49:29 -040070 "name": "Build OpenStack {}".format(project.title()),
Mohammed Nasereb46b6c2022-08-29 21:45:29 -040071 "uses": "docker/build-push-action@v3.1.1",
72 "with": {
73 "context": "images/openstack",
Mohammed Naser473c0f32022-08-29 21:53:27 -040074 "cache-from": "type=gha",
75 "cache-to": "type=gha,mode=max",
Mohammed Nasereb46b6c2022-08-29 21:45:29 -040076 "push": True,
77 "platforms": get_platforms_for_project(project),
78 "build-args": "\n".join([f"{k}={v}" for k, v in build_args.items()]),
79 "tags": f"quay.io/vexxhost/{project}:{ref}",
80 },
81 }
82
83
84for release in RELEASES:
85 # - uses: docker/build-push-action@v3
86 # with:
87 # context: .
88 # cache-from: type=registry,ref=quay.io/vexxhost/${{ matrix.project }}:${{ matrix.release }}
89 # cache-to: type=inline
90 # push: ${{ github.ref == format('refs/heads/{0}', github.event.repository.default_branch) }}
91 # platforms: ${{ env.PLATFORMS }}
92 # build-args: |
93 # RELEASE=${{ matrix.release }}
94 # PROJECT=${{ matrix.project }}
95 # PROJECT_REF=${{ env.PROJECT_REF }}
96 # PROFILES=${{ env.PROFILES }}
97 # DIST_PACKAGES=${{ env.DIST_PACKAGES }}
98 # PIP_PACKAGES=${{ env.PIP_PACKAGES }}
99 # tags: |
100 # quay.io/vexxhost/${{ matrix.project }}:${{ env.PROJECT_REF }}
101
Mohammed Naser7a37c992022-08-29 21:47:49 -0400102 workflow_name = f"test-{release}"
103
Mohammed Nasereb46b6c2022-08-29 21:45:29 -0400104 build_openstack_images_steps = (
105 [
106 {"uses": "actions/checkout@v3.0.2"},
107 {"uses": "docker/setup-qemu-action@v2.0.0"},
108 {"uses": "docker/setup-buildx-action@v2.0.0"},
Mohammed Naserf83c92c2022-08-29 21:49:29 -0400109 # {
110 # "uses": "docker/login-action@v2.0.0",
111 # "with": {
112 # "registry": "quay.io",
113 # "username": "${{ secrets.QUAY_USERNAME }}",
114 # "password": "${{ secrets.QUAY_ROBOT_TOKEN }}",
115 # },
116 # },
Mohammed Nasereb46b6c2022-08-29 21:45:29 -0400117 ]
118 + [get_job_for_project(project, release) for project in PROJECTS]
119 + [
120 # molecule
121 # promote image if it is the default branch
122 ]
123 )
124
125 workflow = {
126 "name": f"test-{release}",
127 "on": {
128 "pull_request": {},
129 "push": {"branches": ["main"]},
130 },
131 "jobs": {
132 "build-images": {
133 "runs-on": "ubuntu-latest",
134 "steps": build_openstack_images_steps,
135 }
136 },
137 }
138
Mohammed Naser7a37c992022-08-29 21:47:49 -0400139 with open(f".github/workflows/{workflow_name}.yml", "w") as fd:
140 yaml.dump(workflow, fd, sort_keys=False)