image: add intermediate "image" verb to upload tool

This commit is contained in:
Malte Poll 2023-05-23 12:12:58 +02:00 committed by Malte Poll
parent 0a7349ca41
commit b8751f35f9
10 changed files with 63 additions and 37 deletions

1
image/.gitignore vendored
View file

@ -2,6 +2,7 @@ mkosi.cache
mkosi.extra mkosi.extra
pki pki
image.* image.*
!image.go
mkosi.output.* mkosi.output.*
pki_*/*.key pki_*/*.key
pki_*/*.vmgs pki_*/*.vmgs

View file

@ -8,6 +8,7 @@ go_library(
"azure.go", "azure.go",
"flags.go", "flags.go",
"gcp.go", "gcp.go",
"image.go",
"must.go", "must.go",
"nop.go", "nop.go",
"openstack.go", "openstack.go",

View file

@ -18,8 +18,8 @@ import (
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
// NewAWSCmd returns the command that uploads an OS image to AWS. // newAWSCmd returns the command that uploads an OS image to AWS.
func NewAWSCmd() *cobra.Command { func newAWSCmd() *cobra.Command {
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "aws", Use: "aws",
Short: "Upload OS image to AWS", Short: "Upload OS image to AWS",

View file

@ -18,8 +18,8 @@ import (
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
// NewAzureCmd returns the command that uploads an OS image to Azure. // newAzureCmd returns the command that uploads an OS image to Azure.
func NewAzureCmd() *cobra.Command { func newAzureCmd() *cobra.Command {
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "azure", Use: "azure",
Short: "Upload OS image to Azure", Short: "Upload OS image to Azure",

View file

@ -18,8 +18,8 @@ import (
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
// NewGCPCommand returns the command that uploads an OS image to GCP. // newGCPCommand returns the command that uploads an OS image to GCP.
func NewGCPCommand() *cobra.Command { func newGCPCommand() *cobra.Command {
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "gcp", Use: "gcp",
Short: "Upload OS image to GCP", Short: "Upload OS image to GCP",

View file

@ -0,0 +1,47 @@
/*
Copyright (c) Edgeless Systems GmbH
SPDX-License-Identifier: AGPL-3.0-only
*/
package cmd
import (
"os"
"github.com/spf13/cobra"
)
// NewImageCmd creates a new image parent command. Image needs another
// verb, and does nothing on its own.
func NewImageCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "image",
Short: "Uploads OS images to supported CSPs",
Long: "Uploads OS images to supported CSPs.",
Args: cobra.ExactArgs(0),
}
cmd.SetOut(os.Stdout)
cmd.PersistentFlags().String("raw-image", "", "Path to os image in CSP specific format that should be uploaded.")
cmd.PersistentFlags().String("pki", "", "Base path to the PKI (secure boot signing) files.")
cmd.PersistentFlags().String("attestation-variant", "", "Attestation variant of the image being uploaded.")
cmd.PersistentFlags().String("version", "", "Shortname of the os image version.")
cmd.PersistentFlags().String("timestamp", "", "Optional timestamp to use for resource names. Uses format 2006-01-02T15:04:05Z07:00.")
cmd.PersistentFlags().String("region", "eu-central-1", "AWS region of the archive S3 bucket")
cmd.PersistentFlags().String("bucket", "cdn-constellation-backend", "S3 bucket name of the archive")
cmd.PersistentFlags().String("out", "", "Optional path to write the upload result to. If not set, the result is written to stdout.")
cmd.PersistentFlags().Bool("verbose", false, "Enable verbose output")
must(cmd.MarkPersistentFlagRequired("raw-image"))
must(cmd.MarkPersistentFlagRequired("attestation-variant"))
must(cmd.MarkPersistentFlagRequired("version"))
cmd.AddCommand(newAWSCmd())
cmd.AddCommand(newAzureCmd())
cmd.AddCommand(newGCPCommand())
cmd.AddCommand(newOpenStackCmd())
cmd.AddCommand(newQEMUCmd())
return cmd
}

View file

@ -11,8 +11,8 @@ import (
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
// NewOpenStackCmd returns the command that uploads an OS image to OpenStack. // newOpenStackCmd returns the command that uploads an OS image to OpenStack.
func NewOpenStackCmd() *cobra.Command { func newOpenStackCmd() *cobra.Command {
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "openstack", Use: "openstack",
Short: "Upload OS image to OpenStack", Short: "Upload OS image to OpenStack",

View file

@ -11,8 +11,8 @@ import (
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
// NewQEMUCmd returns the command that uploads an OS image to QEMU. // newQEMUCmd returns the command that uploads an OS image to QEMU.
func NewQEMUCmd() *cobra.Command { func newQEMUCmd() *cobra.Command {
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "qemu", Use: "qemu",
Short: "Upload OS image to QEMU", Short: "Upload OS image to QEMU",

View file

@ -33,31 +33,14 @@ func execute() error {
func newRootCmd() *cobra.Command { func newRootCmd() *cobra.Command {
rootCmd := &cobra.Command{ rootCmd := &cobra.Command{
Use: "upload", Use: "upload",
Short: "Uploads OS images to supported CSPs", Short: "Uploads OS image related artifacts",
Long: "Uploads OS images to supported CSPs.", Long: "Uploads OS image related artifacts.",
PersistentPreRun: preRunRoot, PersistentPreRun: preRunRoot,
} }
rootCmd.SetOut(os.Stdout) rootCmd.SetOut(os.Stdout)
rootCmd.PersistentFlags().String("raw-image", "", "Path to os image in CSP specific format that should be uploaded.") rootCmd.AddCommand(cmd.NewImageCmd())
rootCmd.PersistentFlags().String("pki", "", "Base path to the PKI (secure boot signing) files.")
rootCmd.PersistentFlags().String("attestation-variant", "", "Attestation variant of the image being uploaded.")
rootCmd.PersistentFlags().String("version", "", "Shortname of the os image version.")
rootCmd.PersistentFlags().String("timestamp", "", "Optional timestamp to use for resource names. Uses format 2006-01-02T15:04:05Z07:00.")
rootCmd.PersistentFlags().String("region", "eu-central-1", "AWS region of the archive S3 bucket")
rootCmd.PersistentFlags().String("bucket", "cdn-constellation-backend", "S3 bucket name of the archive")
rootCmd.PersistentFlags().String("out", "", "Optional path to write the upload result to. If not set, the result is written to stdout.")
rootCmd.PersistentFlags().Bool("verbose", false, "Enable verbose output")
must(rootCmd.MarkPersistentFlagRequired("raw-image"))
must(rootCmd.MarkPersistentFlagRequired("attestation-variant"))
must(rootCmd.MarkPersistentFlagRequired("version"))
rootCmd.AddCommand(cmd.NewAWSCmd())
rootCmd.AddCommand(cmd.NewAzureCmd())
rootCmd.AddCommand(cmd.NewGCPCommand())
rootCmd.AddCommand(cmd.NewOpenStackCmd())
rootCmd.AddCommand(cmd.NewQEMUCmd())
return rootCmd return rootCmd
} }
@ -92,9 +75,3 @@ func signalContext(ctx context.Context, sig os.Signal) (context.Context, context
func preRunRoot(cmd *cobra.Command, _ []string) { func preRunRoot(cmd *cobra.Command, _ []string) {
cmd.SilenceUsage = true cmd.SilenceUsage = true
} }
func must(err error) {
if err != nil {
panic(err)
}
}

View file

@ -4,7 +4,7 @@ load("//bazel/go:go_test.bzl", "go_test")
go_library( go_library(
name = "imagefetcher", name = "imagefetcher",
srcs = [ srcs = [
"imagegfetcher.go", "imagefetcher.go",
"raw.go", "raw.go",
], ],
importpath = "github.com/edgelesssys/constellation/v2/internal/imagefetcher", importpath = "github.com/edgelesssys/constellation/v2/internal/imagefetcher",