-
Notifications
You must be signed in to change notification settings - Fork 50
/
main.go
78 lines (62 loc) · 1.73 KB
/
main.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package main
import (
"context"
"flag"
"fmt"
"os"
"os/user"
"path/filepath"
"github.com/osbuild/images/pkg/container"
)
func main() {
var filename string
var destination string
var username string
var password string
var tag string
var ignoreTLS bool
flag.StringVar(&filename, "container", "", "path to the oci-archive to upload (required)")
flag.StringVar(&destination, "destination", "", "destination to upload to (required)")
flag.StringVar(&tag, "tag", "", "destination tag to use for the container")
flag.StringVar(&username, "username", "", "username to use for registry")
flag.StringVar(&password, "password", "", "password to use for registry")
flag.BoolVar(&ignoreTLS, "ignore-tls", false, "ignore tls verification for destination")
flag.Parse()
if filename == "" || destination == "" {
flag.Usage()
os.Exit(1)
}
absPath, err := filepath.Abs(filename)
if err != nil {
fmt.Fprintln(os.Stderr, err.Error())
return
}
fmt.Println("Container to upload is:", filename)
client, err := container.NewClient(destination)
if err != nil {
fmt.Fprintf(os.Stderr, "error creating the upload client: %v\n", err)
os.Exit(1)
}
if password != "" {
if username == "" {
u, err := user.Current()
if err != nil {
fmt.Fprintf(os.Stderr, "error looking up current user: %v\n", err)
os.Exit(1)
}
username = u.Username
}
client.SetCredentials(username, password)
}
if ignoreTLS {
client.SkipTLSVerify()
}
ctx := context.Background()
from := fmt.Sprintf("oci-archive://%s", absPath)
digest, err := client.UploadImage(ctx, from, tag)
if err != nil {
fmt.Fprintf(os.Stderr, "error uploading: %v\n", err)
os.Exit(1)
}
fmt.Printf("upload done; destination manifest: %s\n", digest.String())
}