-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmain.go
68 lines (55 loc) · 1.48 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
package main
import (
"context"
"fmt"
"os"
"github.com/CloudSnorkel/standalone-soci-indexer/utils/log"
parser "github.com/novln/docker-parser"
"github.com/spf13/cobra"
)
var (
version = "dev"
commit = "none"
date = "unknown"
builtBy = "unknown"
versionString = fmt.Sprintf("%s, commit %s, built at %s by %s", version, commit, date, builtBy)
)
var (
auth string
)
func parseImageDesc(desc string) (repo, tag, registry string, err error) {
ref, err := parser.Parse(desc)
if err != nil {
return
}
repo = ref.ShortName()
tag = ref.Tag()
registry = ref.Registry()
return
}
func main() {
var rootCmd = &cobra.Command{
Use: "soci-indexer [REGISTRY/]REPO[:TAG]",
Short: "Standalone SOCI indexer for a container image that both indexes and pushes the index",
Version: versionString,
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
var ctx = context.Background()
repo, tag, registry, err := parseImageDesc(args[0])
if err != nil {
log.Error(ctx, "Error parsing image reference: %s", err)
os.Exit(1)
}
log.Info(ctx, fmt.Sprintf("Indexing and pushing %s:%s to %s", repo, tag, registry))
_, err = indexAndPush(ctx, repo, tag, registry, auth)
if err != nil {
os.Exit(1)
}
},
}
rootCmd.Flags().StringVarP(&auth, "auth", "a", "", "Registry authentication token (usually USER:PASSWORD)")
if err := rootCmd.Execute(); err != nil {
_, _ = fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
}