...
1 package build
2
3 import (
4 "context"
5
6 "edge-infra.dev/pkg/f8n/warehouse/release/cmd/internal"
7 "edge-infra.dev/pkg/lib/cli/rags"
8 "edge-infra.dev/pkg/lib/cli/sink"
9 )
10
11 func New() *sink.Command {
12 var (
13 releaser = &internal.Releaser{}
14 destinationRegistry string
15 destinationRepo string
16 configPath string
17 pushFlag bool
18 outputJSON bool
19 )
20 cmd := &sink.Command{
21 Use: "build [flags]",
22 Short: "build a Release OCI artifact",
23 Extensions: []sink.Extension{releaser},
24 Flags: []*rags.Rag{
25 {
26 Name: "dest-registry",
27 Usage: "destination registry to push Release artifact",
28 Value: &rags.String{Var: &destinationRegistry},
29 },
30 {
31 Name: "dest-repo",
32 Usage: "destination repo to push Release artifact",
33 Value: &rags.String{Var: &destinationRepo},
34 },
35 {
36 Name: "push",
37 Short: "p",
38 Usage: "flag to push artifact to destination registry",
39 Value: &rags.Bool{Var: &pushFlag},
40 },
41 {
42 Name: "ojson",
43 Usage: "output Release artifact JSON",
44 Value: &rags.Bool{Var: &outputJSON},
45 },
46
47 internal.ConfigFlag(configPath),
48 },
49 Exec: func(ctx context.Context, r sink.Run) error {
50 rel, err := releaser.BuildRelease(ctx)
51 if err != nil {
52 return err
53 }
54 relDigest, err := rel.Digest()
55 if err != nil {
56 return err
57 }
58
59 r.Log.Info("built release", "digest", relDigest.Hex[:9])
60
61 if pushFlag {
62 r.Log.Info("push is set", "destination repo", releaser.DestinationRepository)
63 err = releaser.Push(ctx, rel)
64 if err != nil {
65 return err
66 }
67 r.Log.Info("push successful")
68 }
69
70 if outputJSON {
71 relBytes, err := rel.RawManifest()
72 if err != nil {
73 return err
74 }
75 if _, err = r.Out().Write(relBytes); err != nil {
76 return err
77 }
78 }
79
80 return nil
81 },
82 }
83 return cmd
84 }
85
View as plain text