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