Skip to content

Commit 84337ab

Browse files
committed
Fix bug
1 parent c646b70 commit 84337ab

File tree

3 files changed

+21
-8
lines changed

3 files changed

+21
-8
lines changed

cmd/run.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ downloads; use --no-cache to force re-download. Any flags provided via
5757
5858
# Execute target from remote Makefile artifact, bypassing cache
5959
remake run -f ghcr.io/myorg/myrepo:latest --no-cache deploy`,
60-
Args: cobra.MinimumNArgs(1),
6160
RunE: func(cmd *cobra.Command, args []string) error {
6261
app.Cfg.NoCache = noCache
6362
return app.Run(context.Background(), file, makeFlags, args)

internal/cache/oci_cache.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ func (c *OCIRepository) Push(ctx context.Context, reference string, data []byte)
5454
if strings.Contains(reference, "://") && !strings.HasPrefix(reference, "oci://") {
5555
return fmt.Errorf("invalid OCI reference: %s", reference)
5656
}
57-
raw := strings.TrimPrefix(reference, "oci://")
57+
raw := strings.ToLower(strings.TrimPrefix(reference, "oci://"))
5858
ref, err := parseRef(raw, name.WithDefaultRegistry(c.cfg.DefaultRegistry))
5959
if err != nil {
6060
return err
@@ -115,7 +115,7 @@ func (c *OCIRepository) Pull(ctx context.Context, reference string) (string, err
115115
if strings.Contains(reference, "://") && !strings.HasPrefix(reference, "oci://") {
116116
return "", fmt.Errorf("invalid OCI reference: %s", reference)
117117
}
118-
raw := strings.TrimPrefix(reference, "oci://")
118+
raw := strings.ToLower(strings.TrimPrefix(reference, "oci://"))
119119

120120
ref, err := name.ParseReference(raw, name.WithDefaultRegistry(c.cfg.DefaultRegistry))
121121
if err != nil {

internal/client/oci_client.go

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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.
8989
func (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

Comments
 (0)