Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow rpm import to skip upload OR import step #194

Merged
merged 2 commits into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions peridot/cmd/v1/peridot/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ pkg_rpm(
srcs = [":peridot-files"],
license = "MIT",
summary = "Peridot Command Line Interface",
version = "0.2.0",
release = "0",
version = "0.2.1",
release = "1",
architecture = "x86_64",
description = "A command line interface to interact with the Peridot build system",
source_date_epoch = 0,
Expand Down
52 changes: 41 additions & 11 deletions peridot/cmd/v1/peridot/build_rpm_import.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,16 @@
package main

import (
"crypto/sha256"
"encoding/base64"
"github.com/spf13/cobra"
"io/ioutil"
"encoding/hex"
"log"
"openapi.peridot.resf.org/peridotopenapi"
"os"
"strings"
"time"

"github.com/spf13/cobra"
"openapi.peridot.resf.org/peridotopenapi"
)

type LookasideUploadTask struct {
Expand All @@ -57,9 +60,11 @@ var buildRpmImport = &cobra.Command{
}

var buildRpmImportForceOverride bool
var skipStep string

func init() {
buildRpmImport.Flags().BoolVar(&buildRpmImportForceOverride, "force-override", true, "Force override even if version exists (default: true)")
buildRpmImport.Flags().StringVarP(&skipStep, "skip", "s", "", "which step to skip")
}

func isFile(path string) bool {
Expand All @@ -74,6 +79,20 @@ func buildRpmImportMn(_ *cobra.Command, args []string) {
// Ensure project id exists
projectId := mustGetProjectID()

var skipUpload = false
var skipImport = false

if skipStep != "" {
switch strings.ToLower(skipStep) {
case "upload":
skipUpload = true
case "import":
skipImport = true
default:
log.Fatalf("invalid skip step: %s", skipStep)
}
}

// Ensure all args are valid files
for _, arg := range args {
if !isFile(arg) {
Expand All @@ -85,16 +104,27 @@ func buildRpmImportMn(_ *cobra.Command, args []string) {
var blobs []string
projectCl := getClient(serviceProject).(peridotopenapi.ProjectServiceApi)
for _, arg := range args {
bts, err := ioutil.ReadFile(arg)
errFatal(err)
base64EncodedBytes := base64.StdEncoding.EncodeToString(bts)

res, _, err := projectCl.LookasideFileUpload(getContext()).Body(peridotopenapi.V1LookasideFileUploadRequest{
File: &base64EncodedBytes,
}).Execute()
bts, err := os.ReadFile(arg)
errFatal(err)
log.Printf("Uploaded %s to lookaside", arg)
blobs = append(blobs, res.GetDigest())

hash := sha256.Sum256(bts)
shasum := hex.EncodeToString(hash[:])

if !skipUpload {
base64EncodedBytes := base64.StdEncoding.EncodeToString(bts)
_, _, err := projectCl.LookasideFileUpload(getContext()).Body(peridotopenapi.V1LookasideFileUploadRequest{
File: &base64EncodedBytes,
}).Execute()
errFatal(err)
log.Printf("Uploaded %s to lookaside", arg)
}
log.Printf("Will upload %s to lookaside for %s", shasum, arg)
blobs = append(blobs, shasum)
}

if skipImport {
return
}

taskCl := getClient(serviceTask).(peridotopenapi.TaskServiceApi)
Expand Down