worker/gcp: allow setting Bucket in worker configuration
Extend the worker's configuration to allow setting GCP Bucket to use when uploading images to GCP. The value from the configuration is used only if not provided in the TargetOptions of the job. In GCP, the region of the bucket does not limit importing of the image to a particular region. So it is completely possible to use a single Bucket to import images to any and all regions. Return an error in case no bucket name was set in the job nor in the worker configuration.
This commit is contained in:
parent
cc53f5423e
commit
b54b8fa3ab
3 changed files with 18 additions and 6 deletions
|
|
@ -23,6 +23,7 @@ type kojiServerConfig struct {
|
|||
|
||||
type gcpConfig struct {
|
||||
Credentials string `toml:"credentials"`
|
||||
Bucket string `toml:"bucket"`
|
||||
}
|
||||
|
||||
type azureConfig struct {
|
||||
|
|
|
|||
|
|
@ -32,7 +32,8 @@ import (
|
|||
)
|
||||
|
||||
type GCPConfiguration struct {
|
||||
Creds string
|
||||
Creds string
|
||||
Bucket string
|
||||
}
|
||||
|
||||
type S3Configuration struct {
|
||||
|
|
@ -579,9 +580,18 @@ func (impl *OSBuildJobImpl) Run(job worker.Job) error {
|
|||
break
|
||||
}
|
||||
|
||||
logWithId.Infof("[GCP] 🚀 Uploading image to: %s/%s", targetOptions.Bucket, targetOptions.Object)
|
||||
bucket := targetOptions.Bucket
|
||||
if bucket == "" {
|
||||
bucket = impl.GCPConfig.Bucket
|
||||
if bucket == "" {
|
||||
targetResult.TargetError = clienterrors.WorkerClientError(clienterrors.ErrorInvalidTargetConfig, "No GCP bucket provided", nil)
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
logWithId.Infof("[GCP] 🚀 Uploading image to: %s/%s", bucket, targetOptions.Object)
|
||||
_, err = g.StorageObjectUpload(ctx, path.Join(outputDirectory, jobTarget.OsbuildArtifact.ExportName, jobTarget.OsbuildArtifact.ExportFilename),
|
||||
targetOptions.Bucket, targetOptions.Object, map[string]string{gcp.MetadataKeyImageName: jobTarget.ImageName})
|
||||
bucket, targetOptions.Object, map[string]string{gcp.MetadataKeyImageName: jobTarget.ImageName})
|
||||
if err != nil {
|
||||
targetResult.TargetError = clienterrors.WorkerClientError(clienterrors.ErrorUploadingImage, err.Error(), nil)
|
||||
break
|
||||
|
|
@ -589,14 +599,14 @@ func (impl *OSBuildJobImpl) Run(job worker.Job) error {
|
|||
|
||||
logWithId.Infof("[GCP] 📥 Importing image into Compute Engine as '%s'", jobTarget.ImageName)
|
||||
|
||||
_, importErr := g.ComputeImageInsert(ctx, targetOptions.Bucket, targetOptions.Object, jobTarget.ImageName, []string{targetOptions.Region}, gcp.GuestOsFeaturesByDistro(targetOptions.Os))
|
||||
_, importErr := g.ComputeImageInsert(ctx, bucket, targetOptions.Object, jobTarget.ImageName, []string{targetOptions.Region}, gcp.GuestOsFeaturesByDistro(targetOptions.Os))
|
||||
if importErr == nil {
|
||||
logWithId.Infof("[GCP] 🎉 Image import finished successfully")
|
||||
}
|
||||
|
||||
// Cleanup storage before checking for errors
|
||||
logWithId.Infof("[GCP] 🧹 Deleting uploaded image file: %s/%s", targetOptions.Bucket, targetOptions.Object)
|
||||
if err = g.StorageObjectDelete(ctx, targetOptions.Bucket, targetOptions.Object); err != nil {
|
||||
logWithId.Infof("[GCP] 🧹 Deleting uploaded image file: %s/%s", bucket, targetOptions.Object)
|
||||
if err = g.StorageObjectDelete(ctx, bucket, targetOptions.Object); err != nil {
|
||||
logWithId.Errorf("[GCP] Encountered error while deleting object: %v", err)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -354,6 +354,7 @@ func main() {
|
|||
var gcpConfig GCPConfiguration
|
||||
if config.GCP != nil {
|
||||
gcpConfig.Creds = config.GCP.Credentials
|
||||
gcpConfig.Bucket = config.GCP.Bucket
|
||||
}
|
||||
|
||||
// If the credentials are not provided in the configuration, then the
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue