MCPcopy Create free account
hub / github.com/linuxkit/linuxkit / pushAWSCmd

Function pushAWSCmd

src/cmd/linuxkit/push_aws.go:21–193  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

19const timeoutVar = "LINUXKIT_UPLOAD_TIMEOUT"
20
21func pushAWSCmd() *cobra.Command {
22 var (
23 timeoutFlag int
24 bucketFlag string
25 nameFlag string
26 ena bool
27 sriovNet string
28 uefi bool
29 tpm bool
30 )
31 cmd := &cobra.Command{
32 Use: "aws",
33 Short: "push image to AWS",
34 Long: `Push image to AWS.
35 Single argument specifies the full path of an AWS image. It will be uploaded to S3 and an AMI will be created from it.
36 `,
37 Args: cobra.ExactArgs(1),
38 RunE: func(cmd *cobra.Command, args []string) error {
39 path := args[0]
40
41 timeout := getIntValue(timeoutVar, timeoutFlag, 600)
42 bucket := getStringValue(bucketVar, bucketFlag, "")
43 name := getStringValue(nameVar, nameFlag, "")
44
45 var sriovNetFlag *string
46 if sriovNet != "" {
47 *sriovNetFlag = sriovNet
48 }
49
50 if !uefi && tpm {
51 return fmt.Errorf("cannot use tpm without uefi mode")
52 }
53
54 sess := session.Must(session.NewSession())
55 storage := s3.New(sess)
56
57 ctx, cancelFn := context.WithTimeout(context.Background(), time.Duration(timeout)*time.Second)
58 defer cancelFn()
59
60 if bucket == "" {
61 return fmt.Errorf("please provide the bucket to use")
62 }
63
64 f, err := os.Open(path)
65 if err != nil {
66 return fmt.Errorf("error opening file: %v", err)
67 }
68 defer func() { _ = f.Close() }()
69
70 if name == "" {
71 name = strings.TrimSuffix(path, filepath.Ext(path))
72 name = filepath.Base(name)
73 }
74
75 fi, err := f.Stat()
76 if err != nil {
77 return fmt.Errorf("error reading file information: %v", err)
78 }

Callers 1

pushCmdFunction · 0.85

Calls 5

getIntValueFunction · 0.85
getStringValueFunction · 0.85
OpenMethod · 0.65
StringMethod · 0.65
CloseMethod · 0.45

Tested by

no test coverage detected