cmd: delete unused osbuild-upload-* tools
These tools were usually introduced when we added new upload target implementation to osbuild-composer. Their main purpose was manual testing of the upload library. They don't have any real use beyond that. With the upload code being moved to `osbuild/images` and these tools having their duplicates in that repository, there is very little sense in keeping them in osbuild-composer. Signed-off-by: Tomáš Hozza <thozza@redhat.com>
This commit is contained in:
parent
01faa858d4
commit
dc4ae989e6
85 changed files with 0 additions and 14033 deletions
|
|
@ -24,6 +24,5 @@ osbuild-composer-dbjobqueue-tests
|
|||
osbuild-dnf-json-tests
|
||||
osbuild-koji-tests
|
||||
osbuild-mock-openid-provider
|
||||
osbuild-upload-*
|
||||
|
||||
osbuild-store-dump: the output from this is used in Test_upgrade in internal/store/json_test.go
|
||||
|
|
|
|||
|
|
@ -1,86 +0,0 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
|
||||
ec2types "github.com/aws/aws-sdk-go-v2/service/ec2/types"
|
||||
"github.com/osbuild/images/pkg/arch"
|
||||
"github.com/osbuild/images/pkg/platform"
|
||||
"github.com/osbuild/osbuild-composer/internal/cloud/awscloud"
|
||||
"github.com/osbuild/osbuild-composer/internal/common"
|
||||
)
|
||||
|
||||
func main() {
|
||||
var accessKeyID string
|
||||
var secretAccessKey string
|
||||
var sessionToken string
|
||||
var region string
|
||||
var bucketName string
|
||||
var keyName string
|
||||
var filename string
|
||||
var imageName string
|
||||
var shareWith string
|
||||
var archOpt string
|
||||
var bootModeOpt string
|
||||
flag.StringVar(&accessKeyID, "access-key-id", "", "access key ID")
|
||||
flag.StringVar(&secretAccessKey, "secret-access-key", "", "secret access key")
|
||||
flag.StringVar(&sessionToken, "session-token", "", "session token")
|
||||
flag.StringVar(®ion, "region", "", "target region")
|
||||
flag.StringVar(&bucketName, "bucket", "", "target S3 bucket name")
|
||||
flag.StringVar(&keyName, "key", "", "target S3 key name")
|
||||
flag.StringVar(&filename, "image", "", "image file to upload")
|
||||
flag.StringVar(&imageName, "name", "", "AMI name")
|
||||
flag.StringVar(&shareWith, "account-id", "", "account id to share image with")
|
||||
flag.StringVar(&archOpt, "arch", "", "arch (x86_64 or aarch64)")
|
||||
flag.StringVar(&bootModeOpt, "boot-mode", "", "boot mode (legacy-bios, uefi, uefi-preferred)")
|
||||
flag.Parse()
|
||||
|
||||
a, err := awscloud.New(region, accessKeyID, secretAccessKey, sessionToken)
|
||||
if err != nil {
|
||||
println(err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
uploadOutput, err := a.Upload(filename, bucketName, keyName)
|
||||
if err != nil {
|
||||
println(err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Printf("file uploaded to %s\n", uploadOutput.Location)
|
||||
|
||||
var share []string
|
||||
if shareWith != "" {
|
||||
share = append(share, shareWith)
|
||||
}
|
||||
|
||||
imgArch, err := arch.FromString(archOpt)
|
||||
if err != nil {
|
||||
println(err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
var bootMode *platform.BootMode
|
||||
switch bootModeOpt {
|
||||
case string(ec2types.BootModeValuesLegacyBios):
|
||||
bootMode = common.ToPtr(platform.BOOT_LEGACY)
|
||||
case string(ec2types.BootModeValuesUefi):
|
||||
bootMode = common.ToPtr(platform.BOOT_UEFI)
|
||||
case string(ec2types.BootModeValuesUefiPreferred):
|
||||
bootMode = common.ToPtr(platform.BOOT_HYBRID)
|
||||
case "":
|
||||
// do nothing
|
||||
default:
|
||||
println("Unknown boot mode %q, must be one of: legacy-bios, uefi, uefi-preferred", bootModeOpt)
|
||||
return
|
||||
}
|
||||
|
||||
ami, _, err := a.Register(imageName, bucketName, keyName, share, imgArch, bootMode, nil)
|
||||
if err != nil {
|
||||
println(err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Printf("AMI registered: %s\n", ami)
|
||||
}
|
||||
|
|
@ -1,89 +0,0 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
"fmt"
|
||||
"os"
|
||||
"path"
|
||||
"strings"
|
||||
|
||||
"github.com/osbuild/images/pkg/cloud/azure"
|
||||
)
|
||||
|
||||
func checkStringNotEmpty(variable string, errorMessage string) {
|
||||
if variable == "" {
|
||||
fmt.Fprintln(os.Stderr, errorMessage)
|
||||
flag.Usage()
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
type tags map[string]string
|
||||
|
||||
func (t *tags) String() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func (t *tags) Set(value string) error {
|
||||
splitValue := strings.SplitN(value, ":", 2)
|
||||
if len(splitValue) < 2 {
|
||||
return fmt.Errorf(`-tag must be in format key:value, "%s" is not valid`, value)
|
||||
}
|
||||
key := splitValue[0]
|
||||
val := splitValue[1]
|
||||
(*t)[key] = val
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func main() {
|
||||
var storageAccount string
|
||||
var storageAccessKey string
|
||||
var fileName string
|
||||
var containerName string
|
||||
var threads int
|
||||
tagsArg := tags(make(map[string]string))
|
||||
flag.StringVar(&storageAccount, "storage-account", "", "Azure storage account (mandatory)")
|
||||
flag.StringVar(&storageAccessKey, "storage-access-key", "", "Azure storage access key (mandatory)")
|
||||
flag.StringVar(&fileName, "image", "", "image to upload (mandatory)")
|
||||
flag.StringVar(&containerName, "container", "", "name of storage container (see Azure docs for explanation, mandatory)")
|
||||
flag.IntVar(&threads, "threads", 16, "number of threads for parallel upload")
|
||||
flag.Var(&tagsArg, "tag", "blob tag formatted as key:value (first colon found is considered to be the delimiter), can be specified multiple times")
|
||||
flag.Parse()
|
||||
|
||||
checkStringNotEmpty(storageAccount, "You need to specify storage account")
|
||||
checkStringNotEmpty(storageAccessKey, "You need to specify storage access key")
|
||||
checkStringNotEmpty(fileName, "You need to specify image file")
|
||||
checkStringNotEmpty(containerName, "You need to specify container name")
|
||||
|
||||
fmt.Println("Image to upload is:", fileName)
|
||||
|
||||
c, err := azure.NewStorageClient(storageAccount, storageAccessKey)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
blobName := azure.EnsureVHDExtension(path.Base(fileName))
|
||||
blobMetadata := azure.BlobMetadata{
|
||||
StorageAccount: storageAccount,
|
||||
BlobName: blobName,
|
||||
ContainerName: containerName,
|
||||
}
|
||||
err = c.UploadPageBlob(
|
||||
blobMetadata,
|
||||
fileName,
|
||||
threads,
|
||||
)
|
||||
if err != nil {
|
||||
fmt.Println("Uploading error: ", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
err = c.TagBlob(context.Background(), blobMetadata, tagsArg)
|
||||
if err != nil {
|
||||
fmt.Println("Tagging error: ", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
|
@ -1,78 +0,0 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
"fmt"
|
||||
"os"
|
||||
"os/user"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/osbuild/images/pkg/container"
|
||||
)
|
||||
|
||||
func main() {
|
||||
var filename string
|
||||
var destination string
|
||||
var username string
|
||||
var password string
|
||||
var tag string
|
||||
var ignoreTLS bool
|
||||
|
||||
flag.StringVar(&filename, "container", "", "path to the oci-archive to upload (required)")
|
||||
flag.StringVar(&destination, "destination", "", "destination to upload to (required)")
|
||||
flag.StringVar(&tag, "tag", "", "destination tag to use for the container")
|
||||
flag.StringVar(&username, "username", "", "username to use for registry")
|
||||
flag.StringVar(&password, "password", "", "password to use for registry")
|
||||
flag.BoolVar(&ignoreTLS, "ignore-tls", false, "ignore tls verification for destination")
|
||||
flag.Parse()
|
||||
|
||||
if filename == "" || destination == "" {
|
||||
flag.Usage()
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
absPath, err := filepath.Abs(filename)
|
||||
if err != nil {
|
||||
fmt.Fprintln(os.Stderr, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println("Container to upload is:", filename)
|
||||
|
||||
client, err := container.NewClient(destination)
|
||||
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "error creating the upload client: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
if password != "" {
|
||||
if username == "" {
|
||||
u, err := user.Current()
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "error looking up current user: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
username = u.Username
|
||||
}
|
||||
client.SetCredentials(username, password)
|
||||
}
|
||||
|
||||
if ignoreTLS {
|
||||
client.SkipTLSVerify()
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
|
||||
from := fmt.Sprintf("oci-archive://%s", absPath)
|
||||
|
||||
digest, err := client.UploadImage(ctx, from, tag)
|
||||
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "error uploading: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
fmt.Printf("upload done; destination manifest: %s\n", digest.String())
|
||||
}
|
||||
|
|
@ -1,114 +0,0 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
|
||||
"cloud.google.com/go/compute/apiv1/computepb"
|
||||
"github.com/osbuild/images/pkg/cloud/gcp"
|
||||
)
|
||||
|
||||
type strArrayFlag []string
|
||||
|
||||
func (a *strArrayFlag) String() string {
|
||||
return fmt.Sprintf("%+v", []string(*a))
|
||||
}
|
||||
|
||||
func (a *strArrayFlag) Set(value string) error {
|
||||
*a = append(*a, value)
|
||||
return nil
|
||||
}
|
||||
|
||||
func main() {
|
||||
|
||||
var credentialsPath string
|
||||
var bucketName string
|
||||
var objectName string
|
||||
var regions strArrayFlag
|
||||
var osFamily string
|
||||
var imageName string
|
||||
var imageFile string
|
||||
var shareWith strArrayFlag
|
||||
|
||||
var skipUpload bool
|
||||
var skipImport bool
|
||||
|
||||
flag.StringVar(&credentialsPath, "cred-path", "", "Path to a file with service account credentials")
|
||||
flag.StringVar(&bucketName, "bucket", "", "Target Storage Bucket name")
|
||||
flag.StringVar(&objectName, "object", "", "Target Storage Object name")
|
||||
flag.Var(®ions, "regions", "Target regions for the uploaded image")
|
||||
flag.StringVar(&osFamily, "os-family", "rhel-8", "OS family to determine Guest OS features when importing the image.")
|
||||
flag.StringVar(&imageName, "image-name", "", "Image name after import to Compute Engine")
|
||||
flag.StringVar(&imageFile, "image", "", "Image file to upload")
|
||||
flag.Var(&shareWith, "share-with", "Accounts to share the image with. Can be set multiple times. Allowed values are 'user:{emailid}' / 'serviceAccount:{emailid}' / 'group:{emailid}' / 'domain:{domain}'.")
|
||||
flag.BoolVar(&skipUpload, "skip-upload", false, "Use to skip Image Upload step")
|
||||
flag.BoolVar(&skipImport, "skip-import", false, "Use to skip Image Import step")
|
||||
flag.Parse()
|
||||
|
||||
var guestOSFeatures []*computepb.GuestOsFeature
|
||||
|
||||
switch osFamily {
|
||||
case "rhel-8":
|
||||
guestOSFeatures = gcp.GuestOsFeaturesRHEL8
|
||||
case "rhel-9":
|
||||
guestOSFeatures = gcp.GuestOsFeaturesRHEL9
|
||||
default:
|
||||
log.Fatalf("[GCP] Unknown OS Family %q. Use one of: 'rhel-8', 'rhel-9'.", osFamily)
|
||||
}
|
||||
|
||||
var credentials []byte
|
||||
if credentialsPath != "" {
|
||||
var err error
|
||||
credentials, err = os.ReadFile(credentialsPath)
|
||||
if err != nil {
|
||||
log.Fatalf("[GCP] Error while reading credentials: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
g, err := gcp.New(credentials)
|
||||
if err != nil {
|
||||
log.Fatalf("[GCP] Failed to create new GCP object: %v", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
|
||||
// Upload image to the Storage
|
||||
if !skipUpload {
|
||||
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 {
|
||||
log.Fatalf("[GCP] Uploading image failed: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
// Import Image to Compute Engine
|
||||
if !skipImport {
|
||||
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
|
||||
log.Printf("[GCP] 🧹 Deleting uploaded image file: %s/%s", bucketName, objectName)
|
||||
if err = g.StorageObjectDelete(ctx, bucketName, objectName); err != nil {
|
||||
log.Printf("[GCP] Encountered error while deleting object: %v", err)
|
||||
}
|
||||
|
||||
// check error from ComputeImageImport()
|
||||
if importErr != nil {
|
||||
log.Fatalf("[GCP] Importing image failed: %v", importErr)
|
||||
}
|
||||
log.Printf("[GCP] 💿 Image URL: %s", g.ComputeImageURL(imageName))
|
||||
}
|
||||
|
||||
// Share the imported Image with specified accounts using IAM policy
|
||||
if len(shareWith) > 0 {
|
||||
log.Printf("[GCP] 🔗 Sharing the image with: %+v", shareWith)
|
||||
err = g.ComputeImageShare(ctx, imageName, []string(shareWith))
|
||||
if err != nil {
|
||||
log.Fatalf("[GCP] Sharing image failed: %s", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,57 +0,0 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/osbuild/osbuild-composer/internal/cloud/awscloud"
|
||||
)
|
||||
|
||||
func main() {
|
||||
var accessKeyID string
|
||||
var secretAccessKey string
|
||||
var sessionToken string
|
||||
var region string
|
||||
var endpoint string
|
||||
var caBundle string
|
||||
var skipSSLVerification bool
|
||||
var bucketName string
|
||||
var keyName string
|
||||
var filename string
|
||||
var public bool
|
||||
flag.StringVar(&accessKeyID, "access-key-id", "", "access key ID")
|
||||
flag.StringVar(&secretAccessKey, "secret-access-key", "", "secret access key")
|
||||
flag.StringVar(&sessionToken, "session-token", "", "session token")
|
||||
flag.StringVar(®ion, "region", "", "target region")
|
||||
flag.StringVar(&endpoint, "endpoint", "", "target endpoint")
|
||||
flag.StringVar(&caBundle, "ca-bundle", "", "path to CA bundle for the S3 server")
|
||||
flag.BoolVar(&skipSSLVerification, "skip-ssl-verification", false, "Skip the verification of the server SSL certificate")
|
||||
flag.StringVar(&bucketName, "bucket", "", "target S3 bucket name")
|
||||
flag.StringVar(&keyName, "key", "", "target S3 key name")
|
||||
flag.StringVar(&filename, "image", "", "image file to upload")
|
||||
flag.BoolVar(&public, "public", false, "if set, the S3 object is marked as public (default: false)")
|
||||
flag.Parse()
|
||||
|
||||
a, err := awscloud.NewForEndpoint(endpoint, region, accessKeyID, secretAccessKey, sessionToken, caBundle, skipSSLVerification)
|
||||
if err != nil {
|
||||
fmt.Println(err.Error())
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
uploadOutput, err := a.Upload(filename, bucketName, keyName)
|
||||
if err != nil {
|
||||
fmt.Println(err.Error())
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
if public {
|
||||
err := a.MarkS3ObjectAsPublic(bucketName, keyName)
|
||||
if err != nil {
|
||||
fmt.Println(err.Error())
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
fmt.Printf("file uploaded to %s\n", uploadOutput.Location)
|
||||
}
|
||||
|
|
@ -1,109 +0,0 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"crypto/rand"
|
||||
"fmt"
|
||||
"math"
|
||||
"math/big"
|
||||
"os"
|
||||
|
||||
"github.com/osbuild/images/pkg/upload/oci"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var (
|
||||
tenancy string
|
||||
region string
|
||||
userID string
|
||||
privateKeyFile string
|
||||
fingerprint string
|
||||
bucketName string
|
||||
bucketNamespace string
|
||||
fileName string
|
||||
objectName string
|
||||
compartment string
|
||||
)
|
||||
|
||||
var uploadCmd = &cobra.Command{
|
||||
Example: "This tool uses the $HOME/.oci/config file to create the OCI client and can be\noverridden using CLI flags.",
|
||||
SilenceUsage: true,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
uploader, err := uploaderFromConfig()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
file, err := os.Open(fileName)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
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
|
||||
},
|
||||
}
|
||||
|
||||
func main() {
|
||||
i, _ := rand.Int(rand.Reader, big.NewInt(math.MaxInt64))
|
||||
uploadCmd.Flags().StringVarP(&tenancy, "tenancy", "t", "", "target tenancy")
|
||||
uploadCmd.Flags().StringVarP(®ion, "region", "r", "", "target region")
|
||||
uploadCmd.Flags().StringVarP(&userID, "user-id", "u", "", "user OCI ID")
|
||||
uploadCmd.Flags().StringVarP(&bucketName, "bucket-name", "b", "", "target OCI bucket name")
|
||||
uploadCmd.Flags().StringVarP(&bucketNamespace, "bucket-namespace", "", "", "target OCI bucket namespace")
|
||||
uploadCmd.Flags().StringVarP(&fileName, "filename", "f", "", "image file to upload")
|
||||
uploadCmd.Flags().StringVarP(&objectName, "object-name", "o", fmt.Sprintf("osbuild-upload-%v", i), "the target name of the uploaded object in the bucket")
|
||||
uploadCmd.Flags().StringVarP(&privateKeyFile, "private-key", "p", "", "private key for authenticating OCI API requests")
|
||||
uploadCmd.Flags().StringVarP(&fingerprint, "fingerprint", "", "", "the private key's fingerprint")
|
||||
uploadCmd.Flags().StringVarP(&compartment, "compartment-id", "c", "", "the compartment ID of the target image")
|
||||
_ = uploadCmd.MarkFlagRequired("bucket-name")
|
||||
_ = uploadCmd.MarkFlagRequired("bucket-namespace")
|
||||
_ = uploadCmd.MarkFlagRequired("compartment-id")
|
||||
_ = uploadCmd.MarkFlagRequired("filename")
|
||||
if err := uploadCmd.Execute(); err != nil {
|
||||
fmt.Fprintln(os.Stderr, err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
func uploaderFromConfig() (oci.Uploader, error) {
|
||||
if privateKeyFile != "" {
|
||||
if tenancy == "" || region == "" || userID == "" || fingerprint == "" {
|
||||
return nil, fmt.Errorf("when suppling a private key the following args are mandatory as well:" +
|
||||
" fingerprint, tenancy, region, and user-id")
|
||||
}
|
||||
pk, err := os.ReadFile(privateKeyFile)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to read private key file %w", err)
|
||||
}
|
||||
uploader, err := oci.NewClient(
|
||||
&oci.ClientParams{
|
||||
Tenancy: tenancy,
|
||||
User: userID,
|
||||
Region: region,
|
||||
PrivateKey: string(pk),
|
||||
Fingerprint: fingerprint,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to create an OCI client %w", err)
|
||||
}
|
||||
return uploader, nil
|
||||
}
|
||||
|
||||
fmt.Printf("Creating an uploader from default config\n")
|
||||
uploader, err := oci.NewClient(nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return uploader, nil
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue