mirror of
https://github.com/apricote/hcloud-upload-image.git
synced 2026-01-13 21:31:03 +00:00
feat: initial library code
This commit is contained in:
parent
b331ddba81
commit
4f57df5b66
10 changed files with 575 additions and 0 deletions
55
interface.go
Normal file
55
interface.go
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
package hcloud_upload_image
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/url"
|
||||
|
||||
"github.com/hetznercloud/hcloud-go/v2/hcloud"
|
||||
)
|
||||
|
||||
type SnapshotClient interface {
|
||||
// Upload the specified image into a snapshot on Hetzner Cloud.
|
||||
//
|
||||
// As the Hetzner Cloud API has no direct way to upload images, we create a temporary server,
|
||||
// overwrite the root disk and take a snapshot of that disk instead.
|
||||
Upload(ctx context.Context, options UploadOptions) (*hcloud.Image, error)
|
||||
|
||||
// Possible future additions:
|
||||
// List(ctx context.Context) []*hcloud.Image
|
||||
// Delete(ctx context.Context, image *hcloud.Image) error
|
||||
// CleanupTempResources(ctx context.Context) error
|
||||
}
|
||||
|
||||
type UploadOptions struct {
|
||||
// ImageURL must be publicly available. The instance will download the image from this endpoint.
|
||||
ImageURL *url.URL
|
||||
ImageCompression Compression
|
||||
// ImageSignatureVerification
|
||||
|
||||
// Architecture should match the architecture of the Image. This decides if the Snapshot can later be
|
||||
// used with [hcloud.ArchitectureX86] or [hcloud.ArchitectureARM] servers.
|
||||
//
|
||||
// Internally this decides what server type is used for the temporary server.
|
||||
Architecture hcloud.Architecture
|
||||
|
||||
// Description is an optional description that the resulting image (snapshot) will have. There is no way to
|
||||
// select images by its description, you should use Labels if you need to identify your image later.
|
||||
Description *string
|
||||
|
||||
// Labels will be added to the resulting image (snapshot). Use these to filter the image list if you
|
||||
// need to identify the image later on.
|
||||
//
|
||||
// We also always add a label `apricote.de/created-by=hcloud-image-upload` ([CreatedByLabel], [CreatedByValue]).
|
||||
Labels map[string]string
|
||||
|
||||
// DebugSkipResourceCleanup will skip the cleanup of the temporary SSH Key and Server.
|
||||
DebugSkipResourceCleanup bool
|
||||
}
|
||||
|
||||
type Compression int
|
||||
|
||||
const (
|
||||
CompressionNone Compression = iota
|
||||
CompressionBZ2
|
||||
// zip,xz,zstd
|
||||
)
|
||||
Loading…
Add table
Add a link
Reference in a new issue