@@ -27,8 +27,8 @@ import (
2727)
2828
2929type PushOptions struct {
30- // CTFPath is the path to the directory containing the ctf archive.
31- CTFPath string
30+ // CTFPaths is the path to the directory containing the ctf archive.
31+ CTFPaths [] string
3232 // BaseUrl is the repository context base url for all included component descriptors.
3333 BaseUrl string
3434 // AdditionalTags defines additional tags that the oci artifact should be tagged with.
@@ -42,8 +42,8 @@ type PushOptions struct {
4242func NewPushCommand (ctx context.Context ) * cobra.Command {
4343 opts := & PushOptions {}
4444 cmd := & cobra.Command {
45- Use : "push CTF_PATH" ,
46- Args : cobra .ExactArgs (1 ),
45+ Use : "push < CTF_PATH> ... " ,
46+ Args : cobra .MinimumNArgs (1 ),
4747 Short : "Pushes all archives of a ctf to a remote repository" ,
4848 Long : `
4949Push pushes all component archives and oci artifacts to the defined oci repository.
@@ -73,69 +73,74 @@ Note: Currently only component archives are supoprted. Generic OCI Artifacts wil
7373}
7474
7575func (o * PushOptions ) Run (ctx context.Context , log logr.Logger , fs vfs.FileSystem ) error {
76- info , err := fs .Stat (o .CTFPath )
77- if err != nil {
78- return fmt .Errorf ("unable to get info for %s: %w" , o .CTFPath , err )
79- }
80- if info .IsDir () {
81- return fmt .Errorf (`%q is a directory.
82- It is expected that the given path points to a CTF Archive` , o .CTFPath )
83- }
84-
85- ociClient , cache , err := o .OciOptions .Build (log , fs )
86- if err != nil {
87- return fmt .Errorf ("unable to build oci client: %s" , err .Error ())
88- }
89-
90- ctfArchive , err := ctf .NewCTF (fs , o .CTFPath )
91- if err != nil {
92- return fmt .Errorf ("unable to open ctf at %q: %s" , o .CTFPath , err .Error ())
93- }
94-
95- err = ctfArchive .Walk (func (ca * ctf.ComponentArchive ) error {
96- // update repository context
97- if len (o .BaseUrl ) != 0 {
98- if err := cdv2 .InjectRepositoryContext (ca .ComponentDescriptor , cdv2 .NewOCIRegistryRepository (o .BaseUrl , "" )); err != nil {
99- return fmt .Errorf ("unable to add repository context: %w" , err )
100- }
76+ for _ , path := range o .CTFPaths {
77+ info , err := fs .Stat (path )
78+ if err != nil {
79+ return fmt .Errorf ("unable to get info for %s: %w" , path , err )
80+ }
81+ if info .IsDir () {
82+ return fmt .Errorf (`%q is a directory.
83+ It is expected that the given path points to a CTF Archive` , path )
10184 }
10285
103- manifest , err := cdoci . NewManifestBuilder ( cache , ca ) .Build (ctx )
86+ ociClient , cache , err := o . OciOptions .Build (log , fs )
10487 if err != nil {
105- return fmt .Errorf ("unable to build oci artifact for component acrchive : %w " , err )
88+ return fmt .Errorf ("unable to build oci client : %s " , err . Error () )
10689 }
10790
108- ref , err := components . OCIRef ( ca . ComponentDescriptor . GetEffectiveRepositoryContext (), ca . ComponentDescriptor . GetName (), ca . ComponentDescriptor . GetVersion () )
91+ ctfArchive , err := ctf . NewCTF ( fs , path )
10992 if err != nil {
110- return fmt .Errorf ("unable to calculate oci ref for %q: %s" , ca .ComponentDescriptor .GetName (), err .Error ())
111- }
112- if err := ociClient .PushManifest (ctx , ref , manifest ); err != nil {
113- return fmt .Errorf ("unable to upload component archive to %q: %s" , ref , err .Error ())
93+ return fmt .Errorf ("unable to open ctf at %q: %s" , o .CTFPaths , err .Error ())
11494 }
115- log .Info (fmt .Sprintf ("Successfully uploaded component archive to %q" , ref ))
11695
117- for _ , tag := range o .AdditionalTags {
118- ref , err := components .OCIRef (ca .ComponentDescriptor .GetEffectiveRepositoryContext (), ca .ComponentDescriptor .GetName (), tag )
96+ err = ctfArchive .Walk (func (ca * ctf.ComponentArchive ) error {
97+ // update repository context
98+ if len (o .BaseUrl ) != 0 {
99+ if err := cdv2 .InjectRepositoryContext (ca .ComponentDescriptor , cdv2 .NewOCIRegistryRepository (o .BaseUrl , "" )); err != nil {
100+ return fmt .Errorf ("unable to add repository context: %w" , err )
101+ }
102+ }
103+
104+ manifest , err := cdoci .NewManifestBuilder (cache , ca ).Build (ctx )
105+ if err != nil {
106+ return fmt .Errorf ("unable to build oci artifact for component acrchive: %w" , err )
107+ }
108+
109+ ref , err := components .OCIRef (ca .ComponentDescriptor .GetEffectiveRepositoryContext (), ca .ComponentDescriptor .GetName (), ca .ComponentDescriptor .GetVersion ())
119110 if err != nil {
120111 return fmt .Errorf ("unable to calculate oci ref for %q: %s" , ca .ComponentDescriptor .GetName (), err .Error ())
121112 }
122113 if err := ociClient .PushManifest (ctx , ref , manifest ); err != nil {
123114 return fmt .Errorf ("unable to upload component archive to %q: %s" , ref , err .Error ())
124115 }
125- log .Info (fmt .Sprintf ("Successfully tagged component archive with %q" , ref ))
126- }
116+ log .Info (fmt .Sprintf ("Successfully uploaded component archive to %q" , ref ))
117+
118+ for _ , tag := range o .AdditionalTags {
119+ ref , err := components .OCIRef (ca .ComponentDescriptor .GetEffectiveRepositoryContext (), ca .ComponentDescriptor .GetName (), tag )
120+ if err != nil {
121+ return fmt .Errorf ("unable to calculate oci ref for %q: %s" , ca .ComponentDescriptor .GetName (), err .Error ())
122+ }
123+ if err := ociClient .PushManifest (ctx , ref , manifest ); err != nil {
124+ return fmt .Errorf ("unable to upload component archive to %q: %s" , ref , err .Error ())
125+ }
126+ log .Info (fmt .Sprintf ("Successfully tagged component archive with %q" , ref ))
127+ }
127128
128- return nil
129- })
130- if err != nil {
131- return fmt .Errorf ("error while reading component archives in ctf: %w" , err )
129+ return nil
130+ })
131+ if err != nil {
132+ return fmt .Errorf ("error while reading component archives in ctf: %w" , err )
133+ }
134+ err = ctfArchive .Close ()
135+ if err != nil {
136+ return fmt .Errorf ("error while closing component archives in ctf: %w" , err )
137+ }
132138 }
133-
134- return ctfArchive .Close ()
139+ return nil
135140}
136141
137142func (o * PushOptions ) Complete (args []string ) error {
138- o .CTFPath = args [ 0 ]
143+ o .CTFPaths = args
139144
140145 var err error
141146 o .OciOptions .CacheDir , err = utils .CacheDir ()
@@ -152,7 +157,7 @@ func (o *PushOptions) Complete(args []string) error {
152157
153158// Validate validates push options
154159func (o * PushOptions ) Validate () error {
155- if len (o .CTFPath ) == 0 {
160+ if len (o .CTFPaths ) == 0 {
156161 return errors .New ("a path to the component descriptor must be defined" )
157162 }
158163 return nil
0 commit comments