@@ -87,19 +87,23 @@ func (c *OCIClient) Login(ctx context.Context, registry, user, pass string) erro
8787// Push uploads the local file at path as an OCI artifact to the given reference.
8888// It tags the artifact with the reference identifier and pushes it to the remote repository.
8989func (c * OCIClient ) Push (ctx context.Context , reference , path string ) error {
90+ // Validate and parse reference
9091 if strings .Contains (reference , "://" ) && ! strings .HasPrefix (reference , "oci://" ) {
9192 return fmt .Errorf ("invalid OCI reference: %s" , reference )
9293 }
93- raw := strings .TrimPrefix (reference , "oci://" )
94+ raw := strings .ToLower ( strings . TrimPrefix (reference , "oci://" ) )
9495 ref , err := name .ParseReference (raw , name .WithDefaultRegistry (c .cfg .DefaultRegistry ))
9596 if err != nil {
9697 return err
9798 }
9899 repoRef := ref .Context ()
100+
99101 repo , err := newRepository (repoRef .RegistryStr () + "/" + repoRef .RepositoryStr ())
100102 if err != nil {
101103 return err
102104 }
105+
106+ // Authenticate if credentials present
103107 key := config .NormalizeKey (repoRef .RegistryStr ())
104108 user := viper .GetString ("registries." + key + ".username" )
105109 pass := viper .GetString ("registries." + key + ".password" )
@@ -111,19 +115,28 @@ func (c *OCIClient) Push(ctx context.Context, reference, path string) error {
111115 }
112116 }
113117
114- dir := filepath .Dir (path )
118+ // Resolve absolute path and split directory
119+ absPath , err := filepath .Abs (path )
120+ if err != nil {
121+ return fmt .Errorf ("failed to resolve absolute path %s: %w" , path , err )
122+ }
123+ dir := filepath .Dir (absPath )
124+
125+ // Prepare a file store rooted at the file's directory
115126 fs , err := newFileStore (dir )
116127 if err != nil {
117- return err
128+ return fmt . Errorf ( "creating file store: %w" , err )
118129 }
119130 defer func () { _ = fs .Close () }()
120131
132+ // Add the file using its absolute path to ensure tests find it
121133 mediaType := "application/vnd.remake.file"
122- fileDesc , err := fs .Add (ctx , path , mediaType , "" )
134+ fileDesc , err := fs .Add (ctx , absPath , mediaType , "" )
123135 if err != nil {
124136 return fmt .Errorf ("adding file to store: %w" , err )
125137 }
126138
139+ // Pack manifest using injected function
127140 artifactType := "application/vnd.remake.artifact"
128141 opts := oras.PackManifestOptions {Layers : []v1.Descriptor {fileDesc }}
129142 manifestDesc , err := packManifest (ctx , fs , oras .PackManifestVersion1_1 , artifactType , opts )
@@ -137,6 +150,7 @@ func (c *OCIClient) Push(ctx context.Context, reference, path string) error {
137150 tag := ref .Identifier ()
138151 _ = fs .Tag (ctx , manifestDesc , tag )
139152
153+ // Push to remote using injected function
140154 if _ , err := copyFunc (ctx , fs , tag , repo , tag , oras .DefaultCopyOptions ); err != nil {
141155 return fmt .Errorf ("pushing to remote: %w" , err )
142156 }
@@ -149,7 +163,7 @@ func (c *OCIClient) Pull(ctx context.Context, reference string) ([]byte, error)
149163 if strings .Contains (reference , "://" ) && ! strings .HasPrefix (reference , "oci://" ) {
150164 return nil , fmt .Errorf ("invalid OCI reference: %s" , reference )
151165 }
152- raw := strings .TrimPrefix (reference , "oci://" )
166+ raw := strings .ToLower ( strings . TrimPrefix (reference , "oci://" ) )
153167 ref , err := name .ParseReference (raw , name .WithDefaultRegistry (c .cfg .DefaultRegistry ))
154168 if err != nil {
155169 return nil , err
0 commit comments