internal/target: add OCI object storage target
Uploads an OCI image to OCI object storage, and generates a pre-authenticated request for the object, which can be used to import it into custom images.
This commit is contained in:
parent
7259deea3a
commit
067366ed6a
7 changed files with 144 additions and 9 deletions
|
|
@ -39,11 +39,16 @@ var uploadCmd = &cobra.Command{
|
|||
}
|
||||
defer file.Close()
|
||||
|
||||
imageID, err := uploader.Upload(objectName, bucketName, bucketNamespace, file, compartment, fileName)
|
||||
err = uploader.Upload(objectName, bucketName, bucketNamespace, file)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to upload the image: %v", err)
|
||||
}
|
||||
|
||||
imageID, err := uploader.CreateImage(objectName, bucketName, bucketNamespace, compartment, fileName)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to create the image from storage object: %v", err)
|
||||
}
|
||||
|
||||
fmt.Printf("Image %s was uploaded and created successfully\n", imageID)
|
||||
return nil
|
||||
},
|
||||
|
|
|
|||
|
|
@ -868,21 +868,73 @@ func (impl *OSBuildJobImpl) Run(job worker.Job) error {
|
|||
}
|
||||
defer file.Close()
|
||||
i, _ := rand.Int(rand.Reader, big.NewInt(math.MaxInt64))
|
||||
imageID, err := ociClient.Upload(
|
||||
err = ociClient.Upload(
|
||||
fmt.Sprintf("osbuild-upload-%d", i),
|
||||
targetOptions.Bucket,
|
||||
targetOptions.Namespace,
|
||||
file,
|
||||
)
|
||||
if err != nil {
|
||||
targetResult.TargetError = clienterrors.WorkerClientError(clienterrors.ErrorUploadingImage, err.Error(), nil)
|
||||
break
|
||||
}
|
||||
|
||||
imageID, err := ociClient.CreateImage(
|
||||
fmt.Sprintf("osbuild-upload-%d", i),
|
||||
targetOptions.Bucket,
|
||||
targetOptions.Namespace,
|
||||
targetOptions.Compartment,
|
||||
jobTarget.ImageName,
|
||||
)
|
||||
if err != nil {
|
||||
targetResult.TargetError = clienterrors.WorkerClientError(clienterrors.ErrorUploadingImage, err.Error(), nil)
|
||||
break
|
||||
}
|
||||
|
||||
logWithId.Info("[OCI] 🎉 Image uploaded and registered!")
|
||||
targetResult.Options = &target.OCITargetResultOptions{ImageID: imageID}
|
||||
case *target.OCIObjectStorageTargetOptions:
|
||||
targetResult = target.NewOCIObjectStorageTargetResult(nil)
|
||||
// create an ociClient uploader with a valid storage client
|
||||
var ociClient oci.Client
|
||||
ociClient, err = oci.NewClient(&oci.ClientParams{
|
||||
User: targetOptions.User,
|
||||
Region: targetOptions.Region,
|
||||
Tenancy: targetOptions.Tenancy,
|
||||
Fingerprint: targetOptions.Fingerprint,
|
||||
PrivateKey: targetOptions.PrivateKey,
|
||||
})
|
||||
if err != nil {
|
||||
targetResult.TargetError = clienterrors.WorkerClientError(clienterrors.ErrorInvalidConfig, err.Error(), nil)
|
||||
break
|
||||
}
|
||||
logWithId.Info("[OCI] 🎉 Image uploaded and registered!")
|
||||
targetResult.Options = &target.OCITargetResultOptions{ImageID: imageID}
|
||||
logWithId.Info("[OCI] 🔑 Logged in OCI")
|
||||
logWithId.Info("[OCI] ⬆ Uploading the image")
|
||||
file, err := os.Open(path.Join(outputDirectory, jobTarget.OsbuildArtifact.ExportName, jobTarget.OsbuildArtifact.ExportFilename))
|
||||
if err != nil {
|
||||
targetResult.TargetError = clienterrors.WorkerClientError(clienterrors.ErrorInvalidConfig, err.Error(), nil)
|
||||
break
|
||||
}
|
||||
defer file.Close()
|
||||
i, _ := rand.Int(rand.Reader, big.NewInt(math.MaxInt64))
|
||||
err = ociClient.Upload(
|
||||
fmt.Sprintf("osbuild-upload-%d", i),
|
||||
targetOptions.Bucket,
|
||||
targetOptions.Namespace,
|
||||
file,
|
||||
)
|
||||
if err != nil {
|
||||
targetResult.TargetError = clienterrors.WorkerClientError(clienterrors.ErrorUploadingImage, err.Error(), nil)
|
||||
break
|
||||
}
|
||||
|
||||
uri, err := ociClient.PreAuthenticatedRequest(fmt.Sprintf("osbuild-upload-%d", i), targetOptions.Bucket, targetOptions.Namespace)
|
||||
if err != nil {
|
||||
targetResult.TargetError = clienterrors.WorkerClientError(clienterrors.ErrorGeneratingSignedURL, err.Error(), nil)
|
||||
break
|
||||
}
|
||||
logWithId.Info("[OCI] 🎉 Image uploaded and registered!")
|
||||
targetResult.Options = &target.OCIObjectStorageTargetResultOptions{URL: uri}
|
||||
case *target.ContainerTargetOptions:
|
||||
targetResult = target.NewContainerTargetResult(nil)
|
||||
destination := jobTarget.ImageName
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue