Merge pull request #78 from NeilHanlon/scoped-packages-modules

Support enabling/disabling modules during package builds
This commit is contained in:
resf-prow[bot] 2023-01-04 15:47:08 +00:00 committed by GitHub
commit fa26cb34df
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 83 additions and 24 deletions

View File

@ -535,6 +535,9 @@ config_opts['module_setup_commands'] = [{moduleSetupCommands}]
for _, module := range extra.Modules { for _, module := range extra.Modules {
moduleSetupCommands = append(moduleSetupCommands, fmt.Sprintf("('enable', '%s')", module)) moduleSetupCommands = append(moduleSetupCommands, fmt.Sprintf("('enable', '%s')", module))
} }
for _, module := range extra.DisabledModules {
moduleSetupCommands = append(moduleSetupCommands, fmt.Sprintf("('disable', '%s')", module))
}
mockConfig += "\n" mockConfig += "\n"
mockConfig += ` mockConfig += `
@ -671,14 +674,17 @@ func (c *Controller) BuildArchActivity(ctx context.Context, projectId string, pa
pkgGroup = project.BuildStagePackages pkgGroup = project.BuildStagePackages
} }
if pkgEo != nil { var enableModules []string
if len(pkgEo.DependsOn) != 0 { var disableModules []string
for _, pkg := range pkgEo.DependsOn { err = ParsePackageExtraOptions(pkgEo, &pkgGroup, &enableModules, &disableModules)
pkgGroup = append(pkgGroup, pkg)
} if err != nil {
} c.log.Infof("no extra options to process for package")
} }
extraOptions.DisabledModules = disableModules
extraOptions.Modules = enableModules
hostArch := os.Getenv("REAL_BUILD_ARCH") hostArch := os.Getenv("REAL_BUILD_ARCH")
err = c.writeMockConfig(&project, packageVersion, extraOptions, arch, hostArch, pkgGroup) err = c.writeMockConfig(&project, packageVersion, extraOptions, arch, hostArch, pkgGroup)
if err != nil { if err != nil {

View File

@ -421,14 +421,18 @@ func (c *Controller) BuildSRPMActivity(ctx context.Context, upstreamPrefix strin
if len(project.SrpmStagePackages) != 0 { if len(project.SrpmStagePackages) != 0 {
pkgGroup = project.SrpmStagePackages pkgGroup = project.SrpmStagePackages
} }
if pkgEo != nil {
if len(pkgEo.DependsOn) != 0 { var enableModules []string
for _, pkg := range pkgEo.DependsOn { var disableModules []string
pkgGroup = append(pkgGroup, pkg) err = ParsePackageExtraOptions(pkgEo, &pkgGroup, &enableModules, &disableModules)
}
} if err != nil {
c.log.Infof("no extra options to process for package")
} }
extraOptions.DisabledModules = disableModules
extraOptions.Modules = enableModules
hostArch := os.Getenv("REAL_BUILD_ARCH") hostArch := os.Getenv("REAL_BUILD_ARCH")
extraOptions.EnableNetworking = true extraOptions.EnableNetworking = true
err = c.writeMockConfig(&project, packageVersion, extraOptions, "noarch", hostArch, pkgGroup) err = c.writeMockConfig(&project, packageVersion, extraOptions, "noarch", hostArch, pkgGroup)
@ -474,6 +478,32 @@ func (c *Controller) BuildSRPMActivity(ctx context.Context, upstreamPrefix strin
return nil return nil
} }
func ParsePackageExtraOptions(pkgEo *models.ExtraOptions, pkgGroup *[]string, enableModules *[]string, disableModules *[]string) error {
if pkgEo == nil {
return fmt.Errorf("no extra options to parse for package")
}
if len(pkgEo.DependsOn) != 0 {
for _, pkg := range pkgEo.DependsOn {
*pkgGroup = append(*pkgGroup, pkg)
}
}
if len(pkgEo.EnableModule) != 0 {
for _, pkg := range pkgEo.EnableModule {
*enableModules = append(*enableModules, pkg)
}
}
if len(pkgEo.DisableModule) != 0 {
for _, pkg := range pkgEo.DisableModule {
*disableModules = append(*disableModules, pkg)
}
}
return nil
}
type UploadActivityResult struct { type UploadActivityResult struct {
ObjectName string `json:"objectName"` ObjectName string `json:"objectName"`
Subtask *models.Task `json:"subtask"` Subtask *models.Task `json:"subtask"`

View File

@ -526,7 +526,7 @@ func processGroupInstallScopedPackageOptions(tx peridotdb.Access, req *peridotpb
} }
for _, dbPkg := range dbPkgs { for _, dbPkg := range dbPkgs {
err = tx.SetGroupInstallOptionsForPackage(req.ProjectId.Value, dbPkg.Name, scopedPackage.DependsOn) err = tx.SetGroupInstallOptionsForPackage(req.ProjectId.Value, dbPkg.Name, scopedPackage.DependsOn, scopedPackage.EnableModule, scopedPackage.DisableModule)
if err != nil { if err != nil {
return nil, fmt.Errorf("failed to set scoped package options for package %s", scopedPackage.Name) return nil, fmt.Errorf("failed to set scoped package options for package %s", scopedPackage.Name)
} }

View File

@ -101,7 +101,7 @@ type Access interface {
GetPackageID(name string) (string, error) GetPackageID(name string) (string, error)
SetExtraOptionsForPackage(projectId string, packageName string, withFlags pq.StringArray, withoutFlags pq.StringArray) error SetExtraOptionsForPackage(projectId string, packageName string, withFlags pq.StringArray, withoutFlags pq.StringArray) error
GetExtraOptionsForPackage(projectId string, packageName string) (*models.ExtraOptions, error) GetExtraOptionsForPackage(projectId string, packageName string) (*models.ExtraOptions, error)
SetGroupInstallOptionsForPackage(projectId string, packageName string, dependsOn pq.StringArray) error SetGroupInstallOptionsForPackage(projectId string, packageName string, dependsOn pq.StringArray, enableModule pq.StringArray, disableModule pq.StringArray) error
SetPackageType(projectId string, packageName string, packageType peridotpb.PackageType) error SetPackageType(projectId string, packageName string, packageType peridotpb.PackageType) error
CreateTask(user *utils.ContextUser, arch string, taskType peridotpb.TaskType, projectId *string, parentTaskId *string) (*models.Task, error) CreateTask(user *utils.ContextUser, arch string, taskType peridotpb.TaskType, projectId *string, parentTaskId *string) (*models.Task, error)

View File

@ -73,11 +73,13 @@ type ExtraOptions struct {
CreatedAt time.Time `json:"createdAt" db:"created_at"` CreatedAt time.Time `json:"createdAt" db:"created_at"`
UpdatedAt sql.NullTime `json:"updatedAt" db:"updated_at"` UpdatedAt sql.NullTime `json:"updatedAt" db:"updated_at"`
ProjectId string `json:"projectId" db:"project_id"` ProjectId string `json:"projectId" db:"project_id"`
PackageName string `json:"packageName" db:"package_name"` PackageName string `json:"packageName" db:"package_name"`
WithFlags pq.StringArray `json:"withFlags" db:"with_flags"` WithFlags pq.StringArray `json:"withFlags" db:"with_flags"`
WithoutFlags pq.StringArray `json:"withoutFlags" db:"without_flags"` WithoutFlags pq.StringArray `json:"withoutFlags" db:"without_flags"`
DependsOn pq.StringArray `json:"dependsOn" db:"depends_on"` DependsOn pq.StringArray `json:"dependsOn" db:"depends_on"`
EnableModule pq.StringArray `json:"enableModule" db:"enable_module"`
DisableModule pq.StringArray `json:"disableModule" db:"disable_module"`
} }
func (p *Package) ToProto() *peridotpb.Package { func (p *Package) ToProto() *peridotpb.Package {

View File

@ -335,7 +335,7 @@ func (a *Access) GetExtraOptionsForPackage(projectId string, packageName string)
var ret models.ExtraOptions var ret models.ExtraOptions
err := a.query.Get( err := a.query.Get(
&ret, &ret,
"select id, created_at, updated_at, project_id, package_name, with_flags, without_flags, depends_on from extra_package_options where project_id = $1 and package_name = $2", "select id, created_at, updated_at, project_id, package_name, with_flags, without_flags, depends_on, enable_module, disable_module from extra_package_options where project_id = $1 and package_name = $2",
projectId, projectId,
packageName, packageName,
) )
@ -345,16 +345,24 @@ func (a *Access) GetExtraOptionsForPackage(projectId string, packageName string)
return &ret, nil return &ret, nil
} }
func (a *Access) SetGroupInstallOptionsForPackage(projectId string, packageName string, dependsOn pq.StringArray) error { func (a *Access) SetGroupInstallOptionsForPackage(projectId string, packageName string, dependsOn pq.StringArray, enableModule pq.StringArray, disableModule pq.StringArray) error {
//NOTE(nhanlon) - 2022-12-19 there is probably a better way to default these?
if dependsOn == nil { if dependsOn == nil {
dependsOn = pq.StringArray{} dependsOn = pq.StringArray{}
} }
if enableModule == nil {
enableModule = pq.StringArray{}
}
if disableModule == nil {
disableModule = pq.StringArray{}
}
_, err := a.query.Exec( _, err := a.query.Exec(
` `
insert into extra_package_options (project_id, package_name, depends_on) insert into extra_package_options (project_id, package_name, depends_on, enable_module, disable_module)
values ($1, $2, $3) values ($1, $2, $3, $4, $5)
on conflict on constraint extra_package_options_uniq do on conflict on constraint extra_package_options_uniq do
update set depends_on = $3, updated_at = now() update set depends_on = $3, enable_module = $4, disable_module = $5, updated_at = now()
`, `,
projectId, projectId,
packageName, packageName,

View File

@ -0,0 +1,3 @@
ALTER TABLE
IF EXISTS extra_package_options DROP COLUMN IF EXISTS enable_module,
IF EXISTS extra_package_options DROP COLUMN IF EXISTS disable_module;

View File

@ -0,0 +1,5 @@
ALTER TABLE
IF EXISTS extra_package_options
ADD
COLUMN IF NOT EXISTS enable_module text [] not null default array [] :: text [],
COLUMN IF NOT EXISTS disable_module text [] not null default array [] :: text [];

View File

@ -324,6 +324,9 @@ message ExtraBuildOptions {
// Modules to enable during build // Modules to enable during build
repeated string modules = 6; repeated string modules = 6;
// Modules to be disabled during build
repeated string disabled_modules = 10;
// Packages to exclude from all repositories not marked with ignore_exclude // Packages to exclude from all repositories not marked with ignore_exclude
repeated string exclude_packages = 7; repeated string exclude_packages = 7;

View File

@ -61,6 +61,8 @@ message CatalogExtraPackageOptions {
message CatalogGroupInstallScopedPackage { message CatalogGroupInstallScopedPackage {
string name = 1 [(validate.rules).string.min_bytes = 1]; string name = 1 [(validate.rules).string.min_bytes = 1];
repeated string depends_on = 2 [(validate.rules).repeated = {unique: true}]; repeated string depends_on = 2 [(validate.rules).repeated = {unique: true}];
repeated string enable_module = 3 [(validate.rules).repeated = {unique: true}];
repeated string disable_module = 4 [(validate.rules).repeated = {unique: true}];
} }
message CatalogGroupInstallOption { message CatalogGroupInstallOption {