rcm: use same function as weldr for pushing composes
Now that `Store.PushCompose()` takes a `Distro` as argument, the rcm API can use that function as well. This moves them both through the same code path, reducing duplication. Remove `PushComposeRequest()` and the corresponding struct. It was supposed to allow composes with multiple output types and architectures, but that was not yet implemented. Merging the two now simplifies moving the compose queue out of the store in a future commit, which will then tackle multi-image-type composes as well.
This commit is contained in:
parent
0f1a014aca
commit
baa055d6ee
2 changed files with 15 additions and 125 deletions
|
|
@ -84,18 +84,8 @@ func notFoundHandler(writer http.ResponseWriter, request *http.Request) {
|
|||
|
||||
// Depsolves packages and build packages for building an image for a given
|
||||
// distro, in the given architecture
|
||||
func depsolve(rpmmd rpmmd.RPMMD, distro distro.Distro, repos []rpmmd.RepoConfig, imageType common.ImageType, arch common.Architecture) ([]rpmmd.PackageSpec, []rpmmd.PackageSpec, error) {
|
||||
archString, ok := arch.ToString()
|
||||
if !ok {
|
||||
panic("architecture was validated before")
|
||||
}
|
||||
|
||||
imageTypeString, ok := imageType.ToString()
|
||||
if !ok {
|
||||
panic("image type was validated before")
|
||||
}
|
||||
|
||||
specs, excludeSpecs, err := distro.BasePackages(imageTypeString, archString)
|
||||
func depsolve(rpmmd rpmmd.RPMMD, distro distro.Distro, repos []rpmmd.RepoConfig, imageType, arch string) ([]rpmmd.PackageSpec, []rpmmd.PackageSpec, error) {
|
||||
specs, excludeSpecs, err := distro.BasePackages(imageType, arch)
|
||||
if err != nil {
|
||||
return nil, nil, fmt.Errorf("Distro.BasePackages: %v", err)
|
||||
}
|
||||
|
|
@ -105,7 +95,7 @@ func depsolve(rpmmd rpmmd.RPMMD, distro distro.Distro, repos []rpmmd.RepoConfig,
|
|||
return nil, nil, fmt.Errorf("RPMMD.Depsolve: %v", err)
|
||||
}
|
||||
|
||||
specs, err = distro.BuildPackages(archString)
|
||||
specs, err = distro.BuildPackages(arch)
|
||||
if err != nil {
|
||||
return nil, nil, fmt.Errorf("Distro.BuildPackages: %v", err)
|
||||
}
|
||||
|
|
@ -184,17 +174,6 @@ func (api *API) submit(writer http.ResponseWriter, request *http.Request, _ http
|
|||
})
|
||||
}
|
||||
|
||||
// Image requests are derived from requested image types. All of them are uploaded to Koji, because
|
||||
// this API is only for RCM.
|
||||
requestedImages := []common.ImageRequest{}
|
||||
for _, imgType := range composeRequest.ImageTypes {
|
||||
requestedImages = append(requestedImages, common.ImageRequest{
|
||||
ImgType: imgType,
|
||||
// TODO: use koji upload type as soon as it is available
|
||||
UpTarget: []common.UploadTarget{},
|
||||
})
|
||||
}
|
||||
|
||||
distro := api.distros.GetDistro(composeRequest.Distribution)
|
||||
if distro == nil {
|
||||
writer.WriteHeader(http.StatusBadRequest)
|
||||
|
|
@ -204,7 +183,17 @@ func (api *API) submit(writer http.ResponseWriter, request *http.Request, _ http
|
|||
}
|
||||
}
|
||||
|
||||
packages, buildPackages, err := depsolve(api.rpmMetadata, distro, repoConfigs, composeRequest.ImageTypes[0], composeRequest.Architectures[0])
|
||||
arch, ok := composeRequest.Architectures[0].ToString()
|
||||
if !ok {
|
||||
panic("architecture was validated before")
|
||||
}
|
||||
|
||||
imageType, ok := composeRequest.ImageTypes[0].ToString()
|
||||
if !ok {
|
||||
panic("image type was validated before")
|
||||
}
|
||||
|
||||
packages, buildPackages, err := depsolve(api.rpmMetadata, distro, repoConfigs, imageType, arch)
|
||||
if err != nil {
|
||||
writer.WriteHeader(http.StatusBadRequest)
|
||||
_, err := writer.Write([]byte(err.Error()))
|
||||
|
|
@ -216,16 +205,7 @@ func (api *API) submit(writer http.ResponseWriter, request *http.Request, _ http
|
|||
// Push the requested compose to the store
|
||||
composeUUID := uuid.New()
|
||||
// nil is used as an upload target, because LocalTarget is already used in the PushCompose function
|
||||
err = api.store.PushComposeRequest(store.ComposeRequest{
|
||||
Blueprint: blueprint.Blueprint{},
|
||||
ComposeID: composeUUID,
|
||||
Distro: distro,
|
||||
Arch: composeRequest.Architectures[0],
|
||||
Repositories: repoConfigs,
|
||||
Packages: packages,
|
||||
BuildPackages: buildPackages,
|
||||
RequestedImages: requestedImages,
|
||||
})
|
||||
err = api.store.PushCompose(distro, composeUUID, &blueprint.Blueprint{}, packages, buildPackages, arch, imageType, 0, nil)
|
||||
if err != nil {
|
||||
if api.logger != nil {
|
||||
api.logger.Println("RCM API failed to push compose:", err)
|
||||
|
|
|
|||
|
|
@ -68,18 +68,6 @@ type SourceConfig struct {
|
|||
System bool `json:"system"`
|
||||
}
|
||||
|
||||
// ComposeRequest is used to submit a new compose to the store
|
||||
type ComposeRequest struct {
|
||||
Blueprint blueprint.Blueprint
|
||||
ComposeID uuid.UUID
|
||||
Distro distro.Distro
|
||||
Arch common.Architecture
|
||||
Repositories []rpmmd.RepoConfig
|
||||
Packages []rpmmd.PackageSpec
|
||||
BuildPackages []rpmmd.PackageSpec
|
||||
RequestedImages []common.ImageRequest
|
||||
}
|
||||
|
||||
type NotFoundError struct {
|
||||
message string
|
||||
}
|
||||
|
|
@ -662,84 +650,6 @@ func (s *Store) PushCompose(distro distro.Distro, composeID uuid.UUID, bp *bluep
|
|||
return nil
|
||||
}
|
||||
|
||||
// PushComposeRequest is an alternative to PushCompose which does not assume a pre-defined distro, as such it is better
|
||||
// suited for RCM API and possible future API that would respect the fact that we can build any distro and any arch
|
||||
func (s *Store) PushComposeRequest(request ComposeRequest) error {
|
||||
// This should never happen and once distro.Manifest is refactored this check will go away
|
||||
arch, exists := request.Arch.ToString()
|
||||
if !exists {
|
||||
panic("fatal error, arch should exist but it does not")
|
||||
}
|
||||
|
||||
// This will be a list of imageBuilds that will be submitted to the state channel
|
||||
imageBuilds := []compose.ImageBuild{}
|
||||
newJobs := []Job{}
|
||||
|
||||
// TODO: remove this
|
||||
if len(request.RequestedImages) > 1 {
|
||||
panic("Multiple image requests are not yet properly implemented")
|
||||
}
|
||||
|
||||
for imageBuildID, imageRequest := range request.RequestedImages {
|
||||
// TODO: handle custom upload targets
|
||||
// TODO: this requires changes in the Compose Request struct
|
||||
// This should never happen and once distro.Manifest is refactored this check will go away
|
||||
imgTypeCompatStr, exists := imageRequest.ImgType.ToCompatString()
|
||||
if !exists {
|
||||
panic("fatal error, image type should exist but it does not")
|
||||
}
|
||||
manifestStruct, err := request.Distro.Manifest(request.Blueprint.Customizations, request.Repositories, request.Packages, request.BuildPackages, arch, imgTypeCompatStr, 0)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if s.stateDir != nil {
|
||||
err = os.MkdirAll(s.getImageBuildDirectory(request.ComposeID, imageBuildID), 0755)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
// This will make the job submission atomic: either all of them or none of them
|
||||
newJobs = append(newJobs, Job{
|
||||
ComposeID: request.ComposeID,
|
||||
ImageBuildID: imageBuildID,
|
||||
Distro: request.Distro.Name(),
|
||||
Manifest: manifestStruct,
|
||||
Targets: []*target.Target{},
|
||||
ImageType: imgTypeCompatStr,
|
||||
})
|
||||
|
||||
// this ought to exist, because we're creating it from an existing distro struct
|
||||
distroTag, _ := common.DistributionFromString(request.Distro.Name())
|
||||
|
||||
imageBuilds = append(imageBuilds, compose.ImageBuild{
|
||||
Distro: distroTag,
|
||||
QueueStatus: common.IBWaiting,
|
||||
ImageType: imageRequest.ImgType,
|
||||
Manifest: manifestStruct,
|
||||
Targets: []*target.Target{},
|
||||
JobCreated: time.Now(),
|
||||
})
|
||||
}
|
||||
|
||||
// submit all the jobs now
|
||||
for _, job := range newJobs {
|
||||
s.pendingJobs <- job
|
||||
}
|
||||
|
||||
// ignore error because the previous implementation does the same
|
||||
_ = s.change(func() error {
|
||||
s.Composes[request.ComposeID] = compose.Compose{
|
||||
Blueprint: &request.Blueprint,
|
||||
ImageBuilds: imageBuilds,
|
||||
}
|
||||
return nil
|
||||
})
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// DeleteCompose deletes the compose from the state file and also removes all files on disk that are
|
||||
// associated with this compose
|
||||
func (s *Store) DeleteCompose(id uuid.UUID) error {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue