Skip to content

Commit aabfa4b

Browse files
committed
use oci cache for skeleton packages
Signed-off-by: Austin Abro <[email protected]>
1 parent 77aad70 commit aabfa4b

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

src/internal/packager2/layout/import.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"time"
1515

1616
"github.com/zarf-dev/zarf/src/pkg/logger"
17+
"github.com/zarf-dev/zarf/src/pkg/utils"
1718

1819
"github.com/defenseunicorns/pkg/helpers/v2"
1920
"github.com/defenseunicorns/pkg/oci"
@@ -206,7 +207,7 @@ func compatibleComponent(c v1alpha1.ZarfComponent, arch, flavor string) bool {
206207
}
207208

208209
// TODO (phillebaba): Refactor package structure so that pullOCI can be used instead.
209-
func fetchOCISkeleton(ctx context.Context, component v1alpha1.ZarfComponent, packagePath string) (string, error) {
210+
func fetchOCISkeleton(ctx context.Context, component v1alpha1.ZarfComponent, packagePath string) (_ string, err error) {
210211
if component.Import.URL == "" {
211212
return component.Import.Path, nil
212213
}
@@ -216,14 +217,13 @@ func fetchOCISkeleton(ctx context.Context, component v1alpha1.ZarfComponent, pac
216217
name = component.Import.Name
217218
}
218219

219-
absCachePath, err := config.GetAbsCachePath()
220+
skeletonDataDir, err := utils.MakeTempDir(config.CommonOptions.CachePath)
220221
if err != nil {
221222
return "", err
222223
}
223-
cache := filepath.Join(absCachePath, "oci")
224-
if err := helpers.CreateDirectory(cache, helpers.ReadWriteExecuteUser); err != nil {
225-
return "", err
226-
}
224+
defer func() {
225+
err = errors.Join(err, os.RemoveAll(skeletonDataDir))
226+
}()
227227

228228
// Get the descriptor for the component.
229229
remote, err := zoci.NewRemote(ctx, component.Import.URL, zoci.PlatformForSkeleton())
@@ -247,11 +247,11 @@ func fetchOCISkeleton(ctx context.Context, component v1alpha1.ZarfComponent, pac
247247
h.Write([]byte(component.Import.URL + name))
248248
id := fmt.Sprintf("%x", h.Sum(nil))
249249

250-
dir = filepath.Join(cache, "dirs", id)
250+
dir = filepath.Join(skeletonDataDir, "dirs", id)
251251
} else {
252-
tarball = filepath.Join(cache, "blobs", "sha256", componentDesc.Digest.Encoded())
253-
dir = filepath.Join(cache, "dirs", componentDesc.Digest.Encoded())
254-
store, err := ocistore.New(cache)
252+
tarball = filepath.Join(skeletonDataDir, "blobs", "sha256", componentDesc.Digest.Encoded())
253+
dir = filepath.Join(skeletonDataDir, "dirs", componentDesc.Digest.Encoded())
254+
store, err := ocistore.New(skeletonDataDir)
255255
if err != nil {
256256
return "", err
257257
}

src/pkg/packager/pull.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package packager
66

77
import (
88
"context"
9+
910
"github.com/zarf-dev/zarf/src/internal/packager2"
1011
"github.com/zarf-dev/zarf/src/pkg/packager/filters"
1112
)

0 commit comments

Comments
 (0)