feat: upload xz compressed images (#16)

Required for Talos images:
https://www.talos.dev/v1.7/talos-guides/install/cloud-platforms/hetzner/#rescue-mode
This commit is contained in:
Julian Tölle 2024-05-09 19:15:54 +02:00 committed by GitHub
parent fcea3e3c6e
commit 1c943e4480
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 6 additions and 3 deletions

View File

@ -86,10 +86,10 @@ func init() {
uploadCmd.MarkFlagsMutuallyExclusive(uploadFlagImageURL, uploadFlagImagePath)
uploadCmd.MarkFlagsOneRequired(uploadFlagImageURL, uploadFlagImagePath)
uploadCmd.Flags().String(uploadFlagCompression, "", "Type of compression that was used on the disk image [choices: bz2]")
uploadCmd.Flags().String(uploadFlagCompression, "", "Type of compression that was used on the disk image [choices: bz2, xz]")
_ = uploadCmd.RegisterFlagCompletionFunc(
uploadFlagCompression,
cobra.FixedCompletions([]string{string(hcloudimages.CompressionBZ2)}, cobra.ShellCompDirectiveNoFileComp),
cobra.FixedCompletions([]string{string(hcloudimages.CompressionBZ2), string(hcloudimages.CompressionXZ)}, cobra.ShellCompDirectiveNoFileComp),
)
uploadCmd.Flags().String(uploadFlagArchitecture, "", "CPU architecture of the disk image [choices: x86, arm]")

View File

@ -86,9 +86,10 @@ type Compression string
const (
CompressionNone Compression = ""
CompressionBZ2 Compression = "bz2"
CompressionXZ Compression = "xz"
// Possible future additions:
// zip,xz,zstd
// zip,zstd
)
// NewClient instantiates a new client. It requires a working [*hcloud.Client] to interact with the Hetzner Cloud API.
@ -290,6 +291,8 @@ func (s *Client) Upload(ctx context.Context, options UploadOptions) (*hcloud.Ima
switch options.ImageCompression {
case CompressionBZ2:
cmd += "bzip2 -cd | "
case CompressionXZ:
cmd += "xz -cd | "
default:
return nil, fmt.Errorf("unknown compression: %q", options.ImageCompression)
}