blob: 46f04f2d4bf6d6f24b82114fb3989331d6fd8a02 [file] [log] [blame]
Mohammed Naserdabb1dc2022-09-06 14:45:59 -04001package image_repositories
2
3import (
4 "fmt"
5 "strings"
6)
7
Mohammed Naser96c23ef2022-09-08 19:19:23 -04008var EXTRAS map[string]string = map[string]string{}
Mohammed Naserdabb1dc2022-09-06 14:45:59 -04009var PROFILES map[string]string = map[string]string{
10 "cinder": "ceph qemu",
Mohammed Naserdabb1dc2022-09-06 14:45:59 -040011 "glance": "ceph",
Mohammed Naser57e6b872022-09-06 17:46:29 -040012 "horizon": "apache",
13 "ironic": "ipxe ipmi qemu tftp",
14 "keystone": "apache ldap openidc",
15 "monasca-api": "apache influxdb",
Mohammed Naserdabb1dc2022-09-06 14:45:59 -040016 "monasca-persister": "influxdb",
Mohammed Naser57e6b872022-09-06 17:46:29 -040017 "neutron": "openvswitch vpn",
18 "nova": "ceph openvswitch configdrive qemu migration",
Mohammed Naserdabb1dc2022-09-06 14:45:59 -040019 "placement": "apache",
20}
21var DIST_PACAKGES map[string]string = map[string]string{
Mohammed Naserfdc71b72022-09-14 14:30:44 -040022 "cinder": "kubectl lsscsi nvme-cli sysfsutils udev util-linux",
Mohammed Naserdabb1dc2022-09-06 14:45:59 -040023 "designate": "bind9utils",
Mohammed Naser85b896c2022-09-08 22:19:19 -040024 "glance": "kubectl lsscsi nvme-cli sysfsutils udev util-linux",
Mohammed Naser57e6b872022-09-06 17:46:29 -040025 "heat": "curl",
Mohammed Naserdabb1dc2022-09-06 14:45:59 -040026 "ironic": "ethtool lshw iproute2",
Mohammed Naser57e6b872022-09-06 17:46:29 -040027 "monasca-agent": "iproute2 libvirt-clients lshw",
28 "neutron": "jq ethtool lshw",
Mohammed Naserfdc71b72022-09-14 14:30:44 -040029 "nova": "ovmf qemu-efi-aarch64 lsscsi nvme-cli sysfsutils udev util-linux",
Mohammed Naserdabb1dc2022-09-06 14:45:59 -040030}
31var PIP_PACKAGES map[string]string = map[string]string{
Mohammed Naser96c23ef2022-09-08 19:19:23 -040032 "glance": "glance_store[cinder]",
Mohammed Naserdabb1dc2022-09-06 14:45:59 -040033 "horizon": "designate-dashboard heat-dashboard ironic-ui magnum-ui neutron-vpnaas-dashboard octavia-dashboard senlin-dashboard monasca-ui",
34 "ironic": "python-dracclient sushy",
Mohammed Naser57e6b872022-09-06 17:46:29 -040035 "monasca-agent": "libvirt-python python-glanceclient python-neutronclient python-novaclient py3nvml",
36 "neutron": "neutron-vpnaas",
Mohammed Naserdabb1dc2022-09-06 14:45:59 -040037 "placement": "httplib2",
38}
39var PLATFORMS map[string]string = map[string]string{
40 "nova": "linux/amd64,linux/arm64",
41 "neutron": "linux/amd64,linux/arm64",
42}
43
44func NewBuildWorkflow(project string) *GithubWorkflow {
Mohammed Naser96c23ef2022-09-08 19:19:23 -040045 extras := ""
46 if val, ok := EXTRAS[project]; ok {
47 extras = fmt.Sprintf("[%s]", val)
48 }
49
Mohammed Naserdabb1dc2022-09-06 14:45:59 -040050 profiles := ""
51 if val, ok := PROFILES[project]; ok {
52 profiles = val
53 }
54
55 distPackages := ""
56 if val, ok := DIST_PACAKGES[project]; ok {
57 distPackages = val
58 }
59
60 pipPackages := ""
61 if val, ok := PIP_PACKAGES[project]; ok {
62 pipPackages = val
63 }
64
65 platforms := "linux/amd64"
66 if val, ok := PLATFORMS[project]; ok {
67 platforms = val
68 }
69
70 buildArgs := []string{
71 "RELEASE=${{ matrix.release }}",
72 fmt.Sprintf("PROJECT=%s", project),
73 "PROJECT_REF=${{ env.PROJECT_REF }}",
Mohammed Naser96c23ef2022-09-08 19:19:23 -040074 fmt.Sprintf("EXTRAS=%s", extras),
Mohammed Naserdabb1dc2022-09-06 14:45:59 -040075 fmt.Sprintf("PROFILES=%s", profiles),
76 fmt.Sprintf("DIST_PACKAGES=%s", distPackages),
77 fmt.Sprintf("PIP_PACKAGES=%s", pipPackages),
78 }
79
80 return &GithubWorkflow{
81 Name: "build",
Mohammed Naser6d6b2c92022-09-06 15:24:23 -040082 Concurrency: GithubWorkflowConcurrency{
83 Group: "${{ github.head_ref || github.run_id }}",
84 CancelInProgress: true,
85 },
Mohammed Naserdabb1dc2022-09-06 14:45:59 -040086 On: GithubWorkflowTrigger{
Mohammed Naser6d6b2c92022-09-06 15:24:23 -040087 PullRequest: GithubWorkflowPullRequest{
88 Types: []string{"opened", "synchronize", "reopened"},
89 },
Mohammed Naserdabb1dc2022-09-06 14:45:59 -040090 Push: GithubWorkflowPush{
91 Branches: []string{"main"},
92 },
93 },
94 Jobs: map[string]GithubWorkflowJob{
95 "image": {
96 RunsOn: "ubuntu-latest",
97 Strategy: GithubWorkflowStrategy{
98 Matrix: map[string][]string{
99 "release": {"wallaby", "xena", "yoga"},
100 },
101 },
102 Steps: []GithubWorkflowStep{
103 {
104 Name: "Install QEMU static binaries",
105 Uses: "docker/setup-qemu-action@v2",
106 },
107 {
108 Name: "Configure Buildkit",
109 Uses: "docker/setup-buildx-action@v2",
110 },
111 {
112 Name: "Checkout project",
113 Uses: "actions/checkout@v3",
114 },
115 {
116 Name: "Setup environment variables",
117 Run: "echo PROJECT_REF=$(cat manifest.yml | yq \".${{ matrix.release }}.sha\") >> $GITHUB_ENV",
118 },
119 {
120 Name: "Authenticate with Quay.io",
121 Uses: "docker/login-action@v2",
Mohammed Naser07493fc2022-09-06 17:33:20 -0400122 If: "${{ github.event_name == 'push' }}",
Mohammed Naserdabb1dc2022-09-06 14:45:59 -0400123 With: map[string]string{
124 "registry": "quay.io",
125 "username": "${{ secrets.QUAY_USERNAME }}",
126 "password": "${{ secrets.QUAY_ROBOT_TOKEN }}",
127 },
128 },
129 {
130 Name: "Build image",
131 Uses: "docker/build-push-action@v3",
132 With: map[string]string{
133 "context": ".",
134 "cache-from": "type=gha,scope=${{ matrix.release }}",
135 "cache-to": "type=gha,mode=max,scope=${{ matrix.release }}",
136 "platforms": platforms,
Mohammed Naser07493fc2022-09-06 17:33:20 -0400137 "push": "${{ github.event_name == 'push' }}",
Mohammed Naserdabb1dc2022-09-06 14:45:59 -0400138 "build-args": strings.Join(buildArgs, "\n"),
139 "tags": fmt.Sprintf("quay.io/vexxhost/%s:${{ env.PROJECT_REF }}", project),
140 },
141 },
142 {
143 Name: "Promote image",
144 Uses: "akhilerm/tag-push-action@v2.0.0",
145 If: "github.ref == 'refs/heads/main'",
146 With: map[string]string{
147 "src": fmt.Sprintf("quay.io/vexxhost/%s:${{ env.PROJECT_REF }}", project),
148 "dst": fmt.Sprintf("quay.io/vexxhost/%s:${{ matrix.release }}", project),
149 },
150 },
151 },
152 },
153 },
154 }
155}