allow peridot project to specify a build pool type in additional to build pool architecture

Signed-off-by: mystic knight <techguru@byiq.com>
This commit is contained in:
mystic knight 2023-02-17 12:17:00 -10:00
parent 69669dfb44
commit 816125a4c8
2 changed files with 211 additions and 203 deletions

View File

@ -31,30 +31,30 @@
package serverpsql package serverpsql
import ( import (
"fmt" "fmt"
"github.com/jmoiron/sqlx/types" "github.com/jmoiron/sqlx/types"
"github.com/lib/pq" "github.com/lib/pq"
"google.golang.org/protobuf/encoding/protojson" "google.golang.org/protobuf/encoding/protojson"
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
"google.golang.org/protobuf/types/known/anypb" "google.golang.org/protobuf/types/known/anypb"
"peridot.resf.org/peridot/db/models" "peridot.resf.org/peridot/db/models"
peridotpb "peridot.resf.org/peridot/pb" peridotpb "peridot.resf.org/peridot/pb"
"peridot.resf.org/utils" "peridot.resf.org/utils"
) )
func (a *Access) ListProjects(filters *peridotpb.ProjectFilters) (ret models.Projects, err error) { func (a *Access) ListProjects(filters *peridotpb.ProjectFilters) (ret models.Projects, err error) {
if filters == nil { if filters == nil {
filters = &peridotpb.ProjectFilters{} filters = &peridotpb.ProjectFilters{}
} }
var ids pq.StringArray = nil var ids pq.StringArray = nil
if filters.Ids != nil { if filters.Ids != nil {
ids = filters.Ids ids = filters.Ids
} }
err = a.query.Select( err = a.query.Select(
&ret, &ret,
` `
select select
id, id,
created_at, created_at,
@ -88,19 +88,19 @@ func (a *Access) ListProjects(filters *peridotpb.ProjectFilters) (ret models.Pro
and ($3 :: uuid[] is null or id = any($3 :: uuid[])) and ($3 :: uuid[] is null or id = any($3 :: uuid[]))
order by created_at desc order by created_at desc
`, `,
utils.StringValueP(filters.Id), utils.StringValueP(filters.Id),
utils.StringValueP(filters.Name), utils.StringValueP(filters.Name),
ids, ids,
) )
return ret, err return ret, err
} }
func (a *Access) GetProjectKeys(projectId string) (*models.ProjectKey, error) { func (a *Access) GetProjectKeys(projectId string) (*models.ProjectKey, error) {
var ret models.ProjectKey var ret models.ProjectKey
err := a.query.Get( err := a.query.Get(
&ret, &ret,
` `
select select
id, id,
created_at, created_at,
@ -110,21 +110,21 @@ func (a *Access) GetProjectKeys(projectId string) (*models.ProjectKey, error) {
from project_keys from project_keys
where project_id = $1 where project_id = $1
`, `,
projectId, projectId,
) )
if err != nil { if err != nil {
return nil, err return nil, err
} }
return &ret, nil return &ret, nil
} }
// GetProjectModuleConfiguration returns the module configurations for the given project. // GetProjectModuleConfiguration returns the module configurations for the given project.
func (a *Access) GetProjectModuleConfiguration(projectId string) (*peridotpb.ModuleConfiguration, error) { func (a *Access) GetProjectModuleConfiguration(projectId string) (*peridotpb.ModuleConfiguration, error) {
var ret types.JSONText var ret types.JSONText
err := a.query.Get( err := a.query.Get(
&ret, &ret,
` `
select select
proto proto
from project_module_configuration from project_module_configuration
@ -132,150 +132,153 @@ func (a *Access) GetProjectModuleConfiguration(projectId string) (*peridotpb.Mod
project_id = $1 project_id = $1
and active = true and active = true
`, `,
projectId, projectId,
) )
if err != nil { if err != nil {
return nil, err return nil, err
} }
anyPb := &anypb.Any{} anyPb := &anypb.Any{}
err = protojson.Unmarshal(ret, anyPb) err = protojson.Unmarshal(ret, anyPb)
if err != nil { if err != nil {
return nil, fmt.Errorf("failed to unmarshal module configuration (protojson): %v", err) return nil, fmt.Errorf("failed to unmarshal module configuration (protojson): %v", err)
} }
pb := &peridotpb.ModuleConfiguration{} pb := &peridotpb.ModuleConfiguration{}
err = anypb.UnmarshalTo(anyPb, pb, proto.UnmarshalOptions{}) err = anypb.UnmarshalTo(anyPb, pb, proto.UnmarshalOptions{})
if err != nil { if err != nil {
return nil, fmt.Errorf("failed to unmarshal module configuration: %v", err) return nil, fmt.Errorf("failed to unmarshal module configuration: %v", err)
} }
return pb, nil return pb, nil
} }
func (a *Access) CreateProjectModuleConfiguration(projectId string, config *peridotpb.ModuleConfiguration) error { func (a *Access) CreateProjectModuleConfiguration(projectId string, config *peridotpb.ModuleConfiguration) error {
anyPb, err := anypb.New(config) anyPb, err := anypb.New(config)
if err != nil { if err != nil {
return fmt.Errorf("failed to marshal module configuration: %v", err) return fmt.Errorf("failed to marshal module configuration: %v", err)
} }
protoJson, err := protojson.Marshal(anyPb) protoJson, err := protojson.Marshal(anyPb)
if err != nil { if err != nil {
return fmt.Errorf("failed to marshal module configuration (protojson): %v", err) return fmt.Errorf("failed to marshal module configuration (protojson): %v", err)
} }
_, err = a.query.Exec( _, err = a.query.Exec(
` `
insert into project_module_configuration (project_id, proto, active) insert into project_module_configuration (project_id, proto, active)
values ($1, $2, true) values ($1, $2, true)
on conflict (project_id) do update on conflict (project_id) do update
set proto = $2, active = true set proto = $2, active = true
`, `,
projectId, projectId,
protoJson, protoJson,
) )
if err != nil { if err != nil {
return err return err
} }
return nil return nil
} }
func (a *Access) CreateProject(project *peridotpb.Project) (*models.Project, error) { func (a *Access) CreateProject(project *peridotpb.Project) (*models.Project, error) {
if err := project.ValidateAll(); err != nil { if err := project.ValidateAll(); err != nil {
return nil, err return nil, err
} }
ret := models.Project{ ret := models.Project{
Name: project.Name.Value, Name: project.Name.Value,
MajorVersion: int(project.MajorVersion.Value), MajorVersion: int(project.MajorVersion.Value),
DistTagOverride: utils.StringValueToNullString(project.DistTag), DistTagOverride: utils.StringValueToNullString(project.DistTag),
TargetGitlabHost: project.TargetGitlabHost.Value, TargetGitlabHost: project.TargetGitlabHost.Value,
TargetPrefix: project.TargetPrefix.Value, TargetPrefix: project.TargetPrefix.Value,
TargetBranchPrefix: project.TargetBranchPrefix.Value, TargetBranchPrefix: project.TargetBranchPrefix.Value,
SourceGitHost: utils.StringValueToNullString(project.SourceGitHost), SourceGitHost: utils.StringValueToNullString(project.SourceGitHost),
SourcePrefix: utils.StringValueToNullString(project.SourcePrefix), SourcePrefix: utils.StringValueToNullString(project.SourcePrefix),
SourceBranchPrefix: utils.StringValueToNullString(project.SourceBranchPrefix), SourceBranchPrefix: utils.StringValueToNullString(project.SourceBranchPrefix),
CdnUrl: utils.StringValueToNullString(project.CdnUrl), CdnUrl: utils.StringValueToNullString(project.CdnUrl),
StreamMode: project.StreamMode, StreamMode: project.StreamMode,
TargetVendor: project.TargetVendor, TargetVendor: project.TargetVendor,
AdditionalVendor: project.AdditionalVendor.Value, AdditionalVendor: project.AdditionalVendor.Value,
Archs: project.Archs, Archs: project.Archs,
BuildPoolType: project.BuildPoolType, BuildPoolType: project.BuildPoolType,
FollowImportDist: project.FollowImportDist, FollowImportDist: project.FollowImportDist,
BranchSuffix: utils.StringValueToNullString(project.BranchSuffix), BranchSuffix: utils.StringValueToNullString(project.BranchSuffix),
GitMakePublic: project.GitMakePublic, GitMakePublic: project.GitMakePublic,
VendorMacro: utils.StringValueToNullString(project.VendorMacro), VendorMacro: utils.StringValueToNullString(project.VendorMacro),
PackagerMacro: utils.StringValueToNullString(project.PackagerMacro), PackagerMacro: utils.StringValueToNullString(project.PackagerMacro),
} }
err := a.query.Get( err := a.query.Get(
&ret, &ret,
` `
insert into projects insert into projects
(name, major_version, dist_tag_override, target_gitlab_host, target_prefix, (name, major_version, dist_tag_override, target_gitlab_host, target_prefix,
target_branch_prefix, source_git_host, source_prefix, source_branch_prefix, cdn_url, target_branch_prefix, source_git_host, source_prefix, source_branch_prefix, cdn_url,
stream_mode, target_vendor, additional_vendor, archs, follow_import_dist, branch_suffix, git_make_public, vendor_macro, packager_macro) stream_mode, target_vendor, additional_vendor, archs, build_pool_type,
values ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19) follow_import_dist, branch_suffix, git_make_public, vendor_macro, packager_macro)
values ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20)
returning id, created_at, updated_at returning id, created_at, updated_at
`, `,
ret.Name, ret.Name,
ret.MajorVersion, ret.MajorVersion,
ret.DistTagOverride, ret.DistTagOverride,
ret.TargetGitlabHost, ret.TargetGitlabHost,
ret.TargetPrefix, ret.TargetPrefix,
ret.TargetBranchPrefix, ret.TargetBranchPrefix,
ret.SourceGitHost, ret.SourceGitHost,
ret.SourcePrefix, ret.SourcePrefix,
ret.SourceBranchPrefix, ret.SourceBranchPrefix,
ret.CdnUrl, ret.CdnUrl,
ret.StreamMode, ret.StreamMode,
ret.TargetVendor, ret.TargetVendor,
ret.AdditionalVendor, ret.AdditionalVendor,
ret.Archs, ret.Archs,
ret.FollowImportDist, ret.BuildPoolType,
ret.BranchSuffix, ret.FollowImportDist,
ret.GitMakePublic, ret.BranchSuffix,
ret.VendorMacro, ret.GitMakePublic,
ret.PackagerMacro, ret.VendorMacro,
) ret.PackagerMacro,
if err != nil { )
return nil, err if err != nil {
} return nil, err
}
return &ret, nil return &ret, nil
} }
func (a *Access) UpdateProject(id string, project *peridotpb.Project) (*models.Project, error) { func (a *Access) UpdateProject(id string, project *peridotpb.Project) (*models.Project, error) {
if err := project.ValidateAll(); err != nil { if err := project.ValidateAll(); err != nil {
return nil, err return nil, err
} }
ret := models.Project{ ret := models.Project{
Name: project.Name.Value, Name: project.Name.Value,
MajorVersion: int(project.MajorVersion.Value), MajorVersion: int(project.MajorVersion.Value),
DistTagOverride: utils.StringValueToNullString(project.DistTag), DistTagOverride: utils.StringValueToNullString(project.DistTag),
TargetGitlabHost: project.TargetGitlabHost.Value, TargetGitlabHost: project.TargetGitlabHost.Value,
TargetPrefix: project.TargetPrefix.Value, TargetPrefix: project.TargetPrefix.Value,
TargetBranchPrefix: project.TargetBranchPrefix.Value, TargetBranchPrefix: project.TargetBranchPrefix.Value,
SourceGitHost: utils.StringValueToNullString(project.SourceGitHost), SourceGitHost: utils.StringValueToNullString(project.SourceGitHost),
SourcePrefix: utils.StringValueToNullString(project.SourcePrefix), SourcePrefix: utils.StringValueToNullString(project.SourcePrefix),
SourceBranchPrefix: utils.StringValueToNullString(project.SourceBranchPrefix), SourceBranchPrefix: utils.StringValueToNullString(project.SourceBranchPrefix),
CdnUrl: utils.StringValueToNullString(project.CdnUrl), CdnUrl: utils.StringValueToNullString(project.CdnUrl),
StreamMode: project.StreamMode, StreamMode: project.StreamMode,
TargetVendor: project.TargetVendor, TargetVendor: project.TargetVendor,
AdditionalVendor: project.AdditionalVendor.Value, AdditionalVendor: project.AdditionalVendor.Value,
Archs: project.Archs, Archs: project.Archs,
FollowImportDist: project.FollowImportDist, BuildPoolType: project.BuildPoolType,
BranchSuffix: utils.StringValueToNullString(project.BranchSuffix), FollowImportDist: project.FollowImportDist,
GitMakePublic: project.GitMakePublic, BranchSuffix: utils.StringValueToNullString(project.BranchSuffix),
VendorMacro: utils.StringValueToNullString(project.VendorMacro), GitMakePublic: project.GitMakePublic,
PackagerMacro: utils.StringValueToNullString(project.PackagerMacro), VendorMacro: utils.StringValueToNullString(project.VendorMacro),
} PackagerMacro: utils.StringValueToNullString(project.PackagerMacro),
}
err := a.query.Get( err := a.query.Get(
&ret, &ret,
` `
update projects set update projects set
name = $1, name = $1,
major_version = $2, major_version = $2,
@ -291,73 +294,75 @@ func (a *Access) UpdateProject(id string, project *peridotpb.Project) (*models.P
target_vendor = $12, target_vendor = $12,
additional_vendor = $13, additional_vendor = $13,
archs = $14, archs = $14,
follow_import_dist = $15, build_pool_type = $15,
branch_suffix = $16, follow_import_dist = $16,
git_make_public = $17, branch_suffix = $17,
vendor_macro = $18, git_make_public = $18,
packager_macro = $19, vendor_macro = $19,
packager_macro = $20,
updated_at = now() updated_at = now()
where id = $20 where id = $21
returning id, created_at, updated_at returning id, created_at, updated_at
`, `,
ret.Name, ret.Name,
ret.MajorVersion, ret.MajorVersion,
ret.DistTagOverride, ret.DistTagOverride,
ret.TargetGitlabHost, ret.TargetGitlabHost,
ret.TargetPrefix, ret.TargetPrefix,
ret.TargetBranchPrefix, ret.TargetBranchPrefix,
ret.SourceGitHost, ret.SourceGitHost,
ret.SourcePrefix, ret.SourcePrefix,
ret.SourceBranchPrefix, ret.SourceBranchPrefix,
ret.CdnUrl, ret.CdnUrl,
ret.StreamMode, ret.StreamMode,
ret.TargetVendor, ret.TargetVendor,
ret.AdditionalVendor, ret.AdditionalVendor,
ret.Archs, ret.Archs,
ret.FollowImportDist, ret.BuildPoolType,
ret.BranchSuffix, ret.FollowImportDist,
ret.GitMakePublic, ret.BranchSuffix,
ret.VendorMacro, ret.GitMakePublic,
ret.PackagerMacro, ret.VendorMacro,
id, ret.PackagerMacro,
) id,
if err != nil { )
return nil, err if err != nil {
} return nil, err
}
return &ret, nil return &ret, nil
} }
func (a *Access) SetProjectKeys(projectId string, username string, password string) error { func (a *Access) SetProjectKeys(projectId string, username string, password string) error {
_, err := a.query.Exec( _, err := a.query.Exec(
` `
insert into project_keys (project_id, gitlab_username, gitlab_secret) insert into project_keys (project_id, gitlab_username, gitlab_secret)
values ($1, $2, $3) values ($1, $2, $3)
on conflict (project_id) do update on conflict (project_id) do update
set gitlab_username = $2, gitlab_secret = $3 set gitlab_username = $2, gitlab_secret = $3
`, `,
projectId, projectId,
username, username,
password, password,
) )
return err return err
} }
func (a *Access) SetBuildRootPackages(projectId string, srpmPackages pq.StringArray, buildPackages pq.StringArray) error { func (a *Access) SetBuildRootPackages(projectId string, srpmPackages pq.StringArray, buildPackages pq.StringArray) error {
if srpmPackages == nil { if srpmPackages == nil {
srpmPackages = pq.StringArray{} srpmPackages = pq.StringArray{}
} }
if buildPackages == nil { if buildPackages == nil {
buildPackages = pq.StringArray{} buildPackages = pq.StringArray{}
} }
_, err := a.query.Exec( _, err := a.query.Exec(
` `
update projects set srpm_stage_packages = $2, build_stage_packages = $3 where id = $1 update projects set srpm_stage_packages = $2, build_stage_packages = $3 where id = $1
`, `,
projectId, projectId,
srpmPackages, srpmPackages,
buildPackages, buildPackages,
) )
return err return err
} }

View File

@ -174,6 +174,9 @@ message Project {
// Packager macro is what gets inserted as the packager in the RPM // Packager macro is what gets inserted as the packager in the RPM
google.protobuf.StringValue packager_macro = 22; google.protobuf.StringValue packager_macro = 22;
// specify a build pool type in additional to build pool architecture
google.protobuf.StringValue build_pool_type = 23;
} }
// A repository is a yum repository that yumrepofs maintains // A repository is a yum repository that yumrepofs maintains