Skip to content

Commit

Permalink
store commit tar in pulp
Browse files Browse the repository at this point in the history
Signed-off-by: Jonathan Holloway <[email protected]>
  • Loading branch information
loadtheaccumulator committed Sep 19, 2024
1 parent 7bd962a commit 2a1cd26
Show file tree
Hide file tree
Showing 10 changed files with 316 additions and 43 deletions.
3 changes: 1 addition & 2 deletions cmd/pulpcli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,7 @@ func fixtureCreate(ctx context.Context, c *pulp.PulpService, orgID, _ string) {
fmt.Println("Repository imported", *repoImported.PulpHref)
fmt.Println("--------------------------------")

err = c.FileRepositoriesVersionDelete(ctx, pulp.ScanUUID(&version), pulp.ScanRepoFileVersion(&version))
if err != nil {
if err = c.FileRepositoriesVersionDelete(ctx, pulp.ScanUUID(&version), pulp.ScanRepoFileVersion(&version)); err != nil {
panic(err)
}
fmt.Println("Artifact version deleted", version)
Expand Down
1 change: 1 addition & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,7 @@ func LogConfigAtStartup(cfg *EdgeConfig) {
"RepoFileUploadAttempts": cfg.RepoFileUploadAttempts,
"RepoFileUploadDelay": cfg.RepoFileUploadDelay,
"UploadWorkers": cfg.UploadWorkers,
"PulpURL": cfg.PulpURL,
}

// loop through the key/value pairs
Expand Down
23 changes: 22 additions & 1 deletion pkg/clients/imagebuilder/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -439,12 +439,25 @@ func (c *Client) GetComposeStatus(jobID string) (*ComposeStatus, error) {
"statusCode": res.StatusCode,
"responseBody": string(body),
"error": err,
}).Debug("Image Builder ComposeStatus Response")
}).Trace("Image Builder ComposeStatus Response")

if err != nil {
c.log.WithFields(log.Fields{
"statusCode": res.StatusCode,
"responseBody": string(body),
"error": err,
}).Error("Error reading compose status response")

return nil, err
}
defer res.Body.Close()
if res.StatusCode != http.StatusOK {
c.log.WithFields(log.Fields{
"statusCode": res.StatusCode,
"responseBody": string(body),
"error": err,
}).Error("Error compose status HTTP response not StatusOK")

return nil, fmt.Errorf("request for status was not successful")
}

Expand All @@ -456,6 +469,14 @@ func (c *Client) GetComposeStatus(jobID string) (*ComposeStatus, error) {
return nil, err
}

if cs.ImageStatus.Status == imageStatusSuccess {
c.log.WithFields(log.Fields{
"statusCode": res.StatusCode,
"responseBody": string(body),
"error": err,
}).Info("Image Builder ComposeStatus Response")
}

return cs, nil
}

Expand Down
4 changes: 3 additions & 1 deletion pkg/services/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -881,8 +881,10 @@ func (s *ImageService) CreateRepoForImage(ctx context.Context, img *models.Image
var repository *models.Repo
var err error
if feature.PulpIntegration.IsEnabled() {
repository, err = s.RepoBuilder.StoreRepo(repo)
s.log.Debug("Running Pulp repo process")
repository, err = s.RepoBuilder.StoreRepo(ctx, repo)
} else {
s.log.Debug("Running AWS repo process")
repository, err = s.RepoBuilder.ImportRepo(repo)
}
if err != nil {
Expand Down
9 changes: 5 additions & 4 deletions pkg/services/mock_services/repobuilder.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

47 changes: 42 additions & 5 deletions pkg/services/repobuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"context"
"errors"
"fmt"
"net/url"

"os"
"os/exec"
"path/filepath"
Expand All @@ -14,6 +16,7 @@ import (
"github.com/redhatinsights/edge-api/config"
"github.com/redhatinsights/edge-api/pkg/db"
"github.com/redhatinsights/edge-api/pkg/models"
"github.com/redhatinsights/edge-api/pkg/services/repostore"
feature "github.com/redhatinsights/edge-api/unleash/features"

"github.com/cavaliercoder/grab"
Expand All @@ -27,7 +30,7 @@ var BuildCommand = exec.Command
// RepoBuilderInterface defines the interface of a repository builder
type RepoBuilderInterface interface {
BuildUpdateRepo(id uint) (*models.UpdateTransaction, error)
StoreRepo(r *models.Repo) (*models.Repo, error)
StoreRepo(context.Context, *models.Repo) (*models.Repo, error)
ImportRepo(r *models.Repo) (*models.Repo, error)
CommitTarDownload(c *models.Commit, dest string) (string, error)
CommitTarExtract(c *models.Commit, tarFileName string, dest string) error
Expand Down Expand Up @@ -364,11 +367,45 @@ func (rb *RepoBuilder) BuildUpdateRepo(id uint) (*models.UpdateTransaction, erro
}

// StoreRepo requests Pulp to create/update an ostree repo from an IB commit
func (rb *RepoBuilder) StoreRepo(repo *models.Repo) (*models.Repo, error) {
// FIXME: add the Pulp repo create here
// this allows both to happen until code that updates the DB is added
func (rb *RepoBuilder) StoreRepo(ctx context.Context, repo *models.Repo) (*models.Repo, error) {
var cmt models.Commit
cmtDB := db.DB.Where("repo_id = ?", repo.ID).First(&cmt)
if cmtDB.Error != nil {
return nil, cmtDB.Error
}

var err error
if feature.PulpIntegration.IsEnabled() {
log.WithContext(ctx).Debug("Running Pulp repo process")

repoURL, err := repostore.PulpRepoStore(ctx, cmt.OrgID, *cmt.RepoID, cmt.ImageBuildTarURL)
if err != nil {
log.WithContext(ctx).WithField("error", err.Error()).Error("Error storing Image Builder commit in Pulp OSTree repo")

return nil, err
}

repo.URL = repoURL
repo.Status = models.RepoStatusSuccess
} else {
// run the legacy AWS repo storage and return
log.WithContext(ctx).Debug("Running AWS repo process")
repo, err = rb.ImportRepo(repo)
}
if err != nil {
return nil, err
}

result := db.DB.Save(&repo)
if result.Error != nil {
rb.log.WithField("error", result.Error.Error()).Error("Error saving repo")
return nil, fmt.Errorf("error saving status :: %s", result.Error.Error())
}

redactedURL, _ := url.Parse(repo.URL)
log.WithContext(ctx).WithField("repo_url", redactedURL.Redacted()).Info("Commit stored in Pulp OSTree repo")

return rb.ImportRepo(repo)
return repo, nil
}

// ImportRepo (unpack and upload) a single repo
Expand Down
Loading

0 comments on commit 2a1cd26

Please sign in to comment.