blob: 658f8cde33f55d6d7968027341c882b90d07986d [file] [log] [blame]
Mohammed Naserdabb1dc2022-09-06 14:45:59 -04001package image_repositories
2
3import (
4 "fmt"
5 "strings"
6)
7
Mohammed Naserf849fdf2022-10-07 18:28:29 +00008var FORKED_PROJECTS map[string]bool = map[string]bool{
Mohammed Nasercd93f762023-03-03 19:56:36 +01009 "cinder": true,
Mohammed Naser94a8cb92023-02-19 20:42:58 +000010 "horizon": true,
Mohammed Nasercd93f762023-03-03 19:56:36 +010011 "keystone": true,
Mohammed Naserc27351a2023-03-09 08:46:37 +000012 "magnum": true,
Mohammed Naserf849fdf2022-10-07 18:28:29 +000013}
Mohammed Naser96c23ef2022-09-08 19:19:23 -040014var EXTRAS map[string]string = map[string]string{}
Mohammed Naserdabb1dc2022-09-06 14:45:59 -040015var PROFILES map[string]string = map[string]string{
16 "cinder": "ceph qemu",
Mohammed Naserdabb1dc2022-09-06 14:45:59 -040017 "glance": "ceph",
Mohammed Naser57e6b872022-09-06 17:46:29 -040018 "horizon": "apache",
19 "ironic": "ipxe ipmi qemu tftp",
20 "keystone": "apache ldap openidc",
21 "monasca-api": "apache influxdb",
Mohammed Naserdabb1dc2022-09-06 14:45:59 -040022 "monasca-persister": "influxdb",
Mohammed Naser57e6b872022-09-06 17:46:29 -040023 "neutron": "openvswitch vpn",
24 "nova": "ceph openvswitch configdrive qemu migration",
Mohammed Naserdabb1dc2022-09-06 14:45:59 -040025 "placement": "apache",
26}
27var DIST_PACAKGES map[string]string = map[string]string{
Mohammed Naserfdc71b72022-09-14 14:30:44 -040028 "cinder": "kubectl lsscsi nvme-cli sysfsutils udev util-linux",
Mohammed Naserdabb1dc2022-09-06 14:45:59 -040029 "designate": "bind9utils",
Mohammed Naser85b896c2022-09-08 22:19:19 -040030 "glance": "kubectl lsscsi nvme-cli sysfsutils udev util-linux",
Mohammed Naser57e6b872022-09-06 17:46:29 -040031 "heat": "curl",
Mohammed Naserdabb1dc2022-09-06 14:45:59 -040032 "ironic": "ethtool lshw iproute2",
Mohammed Naserf0e9cf52023-04-10 22:52:24 -040033 "magnum": "haproxy",
ricoline284e492023-03-22 22:03:02 +080034 "manila": "iproute2 openvswitch-switch",
Mohammed Naser57e6b872022-09-06 17:46:29 -040035 "monasca-agent": "iproute2 libvirt-clients lshw",
36 "neutron": "jq ethtool lshw",
Mohammed Naser69f67fe2022-10-26 17:14:01 -040037 "nova": "ovmf qemu-efi-aarch64 lsscsi nvme-cli sysfsutils udev util-linux ndctl",
Mohammed Naserdabb1dc2022-09-06 14:45:59 -040038}
39var PIP_PACKAGES map[string]string = map[string]string{
Mohammed Naser5aafa202022-12-21 18:30:05 +000040 "cinder": "purestorage",
Mohammed Naser96c23ef2022-09-08 19:19:23 -040041 "glance": "glance_store[cinder]",
okozachenko1203875a0412023-03-23 21:18:07 +110042 "horizon": "git+https://github.com/openstack/designate-dashboard.git@stable/${{ matrix.release }} git+https://github.com/openstack/heat-dashboard.git@stable/${{ matrix.release }} git+https://github.com/openstack/ironic-ui.git@stable/${{ matrix.release }} git+https://github.com/vexxhost/magnum-ui.git@stable/${{ matrix.release }} git+https://github.com/openstack/neutron-vpnaas-dashboard.git@stable/${{ matrix.release }} git+https://github.com/openstack/octavia-dashboard.git@stable/${{ matrix.release }} git+https://github.com/openstack/senlin-dashboard.git@stable/${{ matrix.release }} git+https://github.com/openstack/monasca-ui.git@stable/${{ matrix.release }} git+https://github.com/openstack/manila-ui.git@stable/${{ matrix.release }}",
Mohammed Naserdabb1dc2022-09-06 14:45:59 -040043 "ironic": "python-dracclient sushy",
okozachenko1203d1232d22023-06-02 02:47:53 +100044 "magnum": "magnum-cluster-api==0.6.0",
Mohammed Naser57e6b872022-09-06 17:46:29 -040045 "monasca-agent": "libvirt-python python-glanceclient python-neutronclient python-novaclient py3nvml",
Mohammed Naserf5113972023-03-12 13:15:30 +010046 "neutron": "neutron-vpnaas",
Mohammed Naserdabb1dc2022-09-06 14:45:59 -040047 "placement": "httplib2",
48}
49var PLATFORMS map[string]string = map[string]string{
50 "nova": "linux/amd64,linux/arm64",
51 "neutron": "linux/amd64,linux/arm64",
52}
53
54func NewBuildWorkflow(project string) *GithubWorkflow {
Mohammed Naser96c23ef2022-09-08 19:19:23 -040055 extras := ""
56 if val, ok := EXTRAS[project]; ok {
57 extras = fmt.Sprintf("[%s]", val)
58 }
59
Mohammed Naserdabb1dc2022-09-06 14:45:59 -040060 profiles := ""
61 if val, ok := PROFILES[project]; ok {
62 profiles = val
63 }
64
65 distPackages := ""
66 if val, ok := DIST_PACAKGES[project]; ok {
67 distPackages = val
68 }
69
okozachenko120398aedb62023-02-01 01:28:34 +110070 pipPackages := "cryptography python-binary-memcached"
Mohammed Naserdabb1dc2022-09-06 14:45:59 -040071 if val, ok := PIP_PACKAGES[project]; ok {
Mohammed Naserdc5784e2022-10-18 23:49:35 -040072 pipPackages += fmt.Sprintf(" %s", val)
Mohammed Naserdabb1dc2022-09-06 14:45:59 -040073 }
74
75 platforms := "linux/amd64"
76 if val, ok := PLATFORMS[project]; ok {
77 platforms = val
78 }
79
Mohammed Naserf849fdf2022-10-07 18:28:29 +000080 gitRepo := fmt.Sprintf("https://github.com/openstack/%s", project)
81 if _, ok := FORKED_PROJECTS[project]; ok {
82 gitRepo = fmt.Sprintf("https://github.com/vexxhost/%s", project)
83 }
84
Mohammed Naserdabb1dc2022-09-06 14:45:59 -040085 buildArgs := []string{
Mohammed Naser19c4e4e2022-12-03 15:14:02 -050086 "BUILDER_IMAGE=quay.io/vexxhost/openstack-builder-${{ matrix.from }}",
Mohammed Naser67abe6a2022-12-03 14:24:12 -050087 "RUNTIME_IMAGE=quay.io/vexxhost/openstack-runtime-${{ matrix.from }}",
Mohammed Naserdabb1dc2022-09-06 14:45:59 -040088 "RELEASE=${{ matrix.release }}",
89 fmt.Sprintf("PROJECT=%s", project),
Mohammed Naserf849fdf2022-10-07 18:28:29 +000090 fmt.Sprintf("PROJECT_REPO=%s", gitRepo),
Mohammed Naserdabb1dc2022-09-06 14:45:59 -040091 "PROJECT_REF=${{ env.PROJECT_REF }}",
Mohammed Naser96c23ef2022-09-08 19:19:23 -040092 fmt.Sprintf("EXTRAS=%s", extras),
Mohammed Naserdabb1dc2022-09-06 14:45:59 -040093 fmt.Sprintf("PROFILES=%s", profiles),
94 fmt.Sprintf("DIST_PACKAGES=%s", distPackages),
95 fmt.Sprintf("PIP_PACKAGES=%s", pipPackages),
96 }
97
Mohammed Naserf79991e2023-04-11 00:03:28 +000098 releases := []string{"wallaby", "xena", "yoga", "zed", "2023.1"}
99 if project == "magnum" {
100 releases = []string{"yoga", "zed", "2023.1"}
101 }
102
Mohammed Naserdabb1dc2022-09-06 14:45:59 -0400103 return &GithubWorkflow{
104 Name: "build",
Mohammed Naser6d6b2c92022-09-06 15:24:23 -0400105 Concurrency: GithubWorkflowConcurrency{
106 Group: "${{ github.head_ref || github.run_id }}",
107 CancelInProgress: true,
108 },
Mohammed Naserdabb1dc2022-09-06 14:45:59 -0400109 On: GithubWorkflowTrigger{
Mohammed Naser6d6b2c92022-09-06 15:24:23 -0400110 PullRequest: GithubWorkflowPullRequest{
111 Types: []string{"opened", "synchronize", "reopened"},
112 },
Mohammed Naserdabb1dc2022-09-06 14:45:59 -0400113 Push: GithubWorkflowPush{
114 Branches: []string{"main"},
115 },
116 },
117 Jobs: map[string]GithubWorkflowJob{
118 "image": {
119 RunsOn: "ubuntu-latest",
120 Strategy: GithubWorkflowStrategy{
Mohammed Naser67abe6a2022-12-03 14:24:12 -0500121 Matrix: map[string]interface{}{
122 "from": []string{"focal", "jammy"},
Mohammed Naser58ad1042023-04-11 00:04:32 +0000123 "release": releases,
Mohammed Naser67abe6a2022-12-03 14:24:12 -0500124 "exclude": []map[string]string{
125 {
126 "from": "focal",
127 "release": "zed",
128 },
129 {
Mohammed Naser91388662023-03-22 17:26:18 +0000130 "from": "focal",
131 "release": "2023.1",
132 },
133 {
Mohammed Naser67abe6a2022-12-03 14:24:12 -0500134 "from": "jammy",
135 "release": "wallaby",
136 },
137 {
138 "from": "jammy",
139 "release": "xena",
140 },
141 },
Mohammed Naserdabb1dc2022-09-06 14:45:59 -0400142 },
143 },
144 Steps: []GithubWorkflowStep{
145 {
146 Name: "Install QEMU static binaries",
147 Uses: "docker/setup-qemu-action@v2",
148 },
149 {
150 Name: "Configure Buildkit",
151 Uses: "docker/setup-buildx-action@v2",
152 },
153 {
154 Name: "Checkout project",
155 Uses: "actions/checkout@v3",
156 },
157 {
158 Name: "Setup environment variables",
Mohammed Naser91388662023-03-22 17:26:18 +0000159 Run: "echo PROJECT_REF=$(cat manifest.yml | yq '.\"${{ matrix.release }}\".sha') >> $GITHUB_ENV",
Mohammed Naserdabb1dc2022-09-06 14:45:59 -0400160 },
161 {
162 Name: "Authenticate with Quay.io",
163 Uses: "docker/login-action@v2",
Mohammed Naser07493fc2022-09-06 17:33:20 -0400164 If: "${{ github.event_name == 'push' }}",
Mohammed Naserdabb1dc2022-09-06 14:45:59 -0400165 With: map[string]string{
166 "registry": "quay.io",
167 "username": "${{ secrets.QUAY_USERNAME }}",
168 "password": "${{ secrets.QUAY_ROBOT_TOKEN }}",
169 },
170 },
171 {
172 Name: "Build image",
173 Uses: "docker/build-push-action@v3",
174 With: map[string]string{
175 "context": ".",
Mohammed Naser67abe6a2022-12-03 14:24:12 -0500176 "cache-from": "type=gha,scope=${{ matrix.from }}-${{ matrix.release }}",
177 "cache-to": "type=gha,mode=max,scope=${{ matrix.from }}-${{ matrix.release }}",
Mohammed Naserdabb1dc2022-09-06 14:45:59 -0400178 "platforms": platforms,
Mohammed Naser07493fc2022-09-06 17:33:20 -0400179 "push": "${{ github.event_name == 'push' }}",
Mohammed Naserdabb1dc2022-09-06 14:45:59 -0400180 "build-args": strings.Join(buildArgs, "\n"),
Mohammed Naser67abe6a2022-12-03 14:24:12 -0500181 "tags": fmt.Sprintf("quay.io/vexxhost/%s:${{ env.PROJECT_REF }}-${{ matrix.from }}", project),
Mohammed Naserdabb1dc2022-09-06 14:45:59 -0400182 },
183 },
184 {
185 Name: "Promote image",
186 Uses: "akhilerm/tag-push-action@v2.0.0",
Mohammed Naser686e5c42022-12-03 14:29:03 -0500187 If: `github.event_name == 'push' && ((matrix.from == 'focal') || (matrix.from == 'jammy' && matrix.release != 'yoga'))`,
Mohammed Naserdabb1dc2022-09-06 14:45:59 -0400188 With: map[string]string{
Mohammed Naser67abe6a2022-12-03 14:24:12 -0500189 "src": fmt.Sprintf("quay.io/vexxhost/%s:${{ env.PROJECT_REF }}-${{ matrix.from }}", project),
Mohammed Naserdabb1dc2022-09-06 14:45:59 -0400190 "dst": fmt.Sprintf("quay.io/vexxhost/%s:${{ matrix.release }}", project),
191 },
192 },
193 },
194 },
195 },
196 }
197}