forked from oras-project/oras
-
Notifications
You must be signed in to change notification settings - Fork 0
/
push.go
58 lines (47 loc) · 1.31 KB
/
push.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package main
import (
"context"
"io/ioutil"
"github.com/shizhMSFT/oras/pkg/oras"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)
type pushOptions struct {
targetRef string
filenames []string
debug bool
username string
password string
}
func pushCmd() *cobra.Command {
var opts pushOptions
cmd := &cobra.Command{
Use: "push name[:tag|@digest] file [file...]",
Short: "Push files to remote registry",
Args: cobra.MinimumNArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
opts.targetRef = args[0]
opts.filenames = args[1:]
return runPush(opts)
},
}
cmd.Flags().BoolVarP(&opts.debug, "debug", "d", false, "debug mode")
cmd.Flags().StringVarP(&opts.username, "username", "u", "", "registry username")
cmd.Flags().StringVarP(&opts.password, "password", "p", "", "registry password")
return cmd
}
func runPush(opts pushOptions) error {
if opts.debug {
logrus.SetLevel(logrus.DebugLevel)
}
resolver := newResolver(opts.username, opts.password)
contents := make(map[string][]byte)
for _, filename := range opts.filenames {
content, err := ioutil.ReadFile(filename)
if err != nil {
return err
}
contents[filename] = content
}
return oras.Push(context.Background(), resolver, opts.targetRef, contents)
}