cmd: use log in upload-gcp
This commit is contained in:
parent
b87d3d78ec
commit
650e7b64c2
1 changed files with 13 additions and 13 deletions
|
|
@ -4,11 +4,11 @@ import (
|
|||
"context"
|
||||
"flag"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
|
||||
"cloud.google.com/go/compute/apiv1/computepb"
|
||||
"github.com/osbuild/osbuild-composer/internal/cloud/gcp"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
type strArrayFlag []string
|
||||
|
|
@ -56,7 +56,7 @@ func main() {
|
|||
case "rhel-9":
|
||||
guestOSFeatures = gcp.GuestOsFeaturesRHEL9
|
||||
default:
|
||||
logrus.Fatalf("[GCP] Unknown OS Family %q. Use one of: 'rhel-8', 'rhel-9'.", osFamily)
|
||||
log.Fatalf("[GCP] Unknown OS Family %q. Use one of: 'rhel-8', 'rhel-9'.", osFamily)
|
||||
}
|
||||
|
||||
var credentials []byte
|
||||
|
|
@ -64,51 +64,51 @@ func main() {
|
|||
var err error
|
||||
credentials, err = os.ReadFile(credentialsPath)
|
||||
if err != nil {
|
||||
logrus.Fatalf("[GCP] Error while reading credentials: %v", err)
|
||||
log.Fatalf("[GCP] Error while reading credentials: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
g, err := gcp.New(credentials)
|
||||
if err != nil {
|
||||
logrus.Fatalf("[GCP] Failed to create new GCP object: %v", err)
|
||||
log.Fatalf("[GCP] Failed to create new GCP object: %v", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
|
||||
// Upload image to the Storage
|
||||
if !skipUpload {
|
||||
logrus.Infof("[GCP] 🚀 Uploading image to: %s/%s", bucketName, objectName)
|
||||
log.Printf("[GCP] 🚀 Uploading image to: %s/%s", bucketName, objectName)
|
||||
_, err := g.StorageObjectUpload(ctx, imageFile, bucketName, objectName,
|
||||
map[string]string{gcp.MetadataKeyImageName: imageName})
|
||||
if err != nil {
|
||||
logrus.Fatalf("[GCP] Uploading image failed: %v", err)
|
||||
log.Fatalf("[GCP] Uploading image failed: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
// Import Image to Compute Engine
|
||||
if !skipImport {
|
||||
logrus.Infof("[GCP] 📥 Importing image into Compute Engine as '%s'", imageName)
|
||||
log.Printf("[GCP] 📥 Importing image into Compute Engine as '%s'", imageName)
|
||||
_, importErr := g.ComputeImageInsert(ctx, bucketName, objectName, imageName, regions, guestOSFeatures)
|
||||
|
||||
// Cleanup storage before checking for errors
|
||||
logrus.Infof("[GCP] 🧹 Deleting uploaded image file: %s/%s", bucketName, objectName)
|
||||
log.Printf("[GCP] 🧹 Deleting uploaded image file: %s/%s", bucketName, objectName)
|
||||
if err = g.StorageObjectDelete(ctx, bucketName, objectName); err != nil {
|
||||
logrus.Warnf("[GCP] Encountered error while deleting object: %v", err)
|
||||
log.Printf("[GCP] Encountered error while deleting object: %v", err)
|
||||
}
|
||||
|
||||
// check error from ComputeImageImport()
|
||||
if importErr != nil {
|
||||
logrus.Fatalf("[GCP] Importing image failed: %v", importErr)
|
||||
log.Fatalf("[GCP] Importing image failed: %v", importErr)
|
||||
}
|
||||
logrus.Infof("[GCP] 💿 Image URL: %s", g.ComputeImageURL(imageName))
|
||||
log.Printf("[GCP] 💿 Image URL: %s", g.ComputeImageURL(imageName))
|
||||
}
|
||||
|
||||
// Share the imported Image with specified accounts using IAM policy
|
||||
if len(shareWith) > 0 {
|
||||
logrus.Infof("[GCP] 🔗 Sharing the image with: %+v", shareWith)
|
||||
log.Printf("[GCP] 🔗 Sharing the image with: %+v", shareWith)
|
||||
err = g.ComputeImageShare(ctx, imageName, []string(shareWith))
|
||||
if err != nil {
|
||||
logrus.Fatalf("[GCP] Sharing image failed: %s", err)
|
||||
log.Fatalf("[GCP] Sharing image failed: %s", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue