Skip to content

Commit 71237ef

Browse files
committed
do not resolve cache dir until remote resource is in use
Signed-off-by: Nicolas De Loof <[email protected]>
1 parent 0d905a8 commit 71237ef

File tree

3 files changed

+18
-28
lines changed

3 files changed

+18
-28
lines changed

cmd/compose/compose.go

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -256,15 +256,8 @@ func (o *ProjectOptions) ToProject(dockerCli command.Cli, services []string, po
256256
}
257257

258258
func (o *ProjectOptions) configureRemoteLoaders(dockerCli command.Cli, po []cli.ProjectOptionsFn) ([]cli.ProjectOptionsFn, error) {
259-
git, err := remote.NewGitRemoteLoader(o.Offline)
260-
if err != nil {
261-
return nil, err
262-
}
263-
264-
oci, err := remote.NewOCIRemoteLoader(dockerCli, o.Offline)
265-
if err != nil {
266-
return nil, err
267-
}
259+
git := remote.NewGitRemoteLoader(o.Offline)
260+
oci := remote.NewOCIRemoteLoader(dockerCli, o.Offline)
268261

269262
po = append(po, cli.WithResourceLoader(git), cli.WithResourceLoader(oci))
270263
return po, nil

pkg/remote/git.go

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,19 +45,13 @@ func gitRemoteLoaderEnabled() (bool, error) {
4545
return false, nil
4646
}
4747

48-
func NewGitRemoteLoader(offline bool) (loader.ResourceLoader, error) {
49-
cache, err := cacheDir()
50-
if err != nil {
51-
return nil, fmt.Errorf("initializing remote resource cache: %w", err)
52-
}
48+
func NewGitRemoteLoader(offline bool) loader.ResourceLoader {
5349
return gitRemoteLoader{
54-
cache: cache,
5550
offline: offline,
56-
}, err
51+
}
5752
}
5853

5954
type gitRemoteLoader struct {
60-
cache string
6155
offline bool
6256
}
6357

@@ -106,7 +100,12 @@ func (g gitRemoteLoader) Load(ctx context.Context, path string) (string, error)
106100
ref.Commit = sha
107101
}
108102

109-
local := filepath.Join(g.cache, ref.Commit)
103+
cache, err := cacheDir()
104+
if err != nil {
105+
return "", fmt.Errorf("initializing remote resource cache: %w", err)
106+
}
107+
108+
local := filepath.Join(cache, ref.Commit)
110109
if _, err := os.Stat(local); os.IsNotExist(err) {
111110
if g.offline {
112111
return "", nil

pkg/remote/oci.go

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,21 +46,14 @@ func ociRemoteLoaderEnabled() (bool, error) {
4646
return false, nil
4747
}
4848

49-
func NewOCIRemoteLoader(dockerCli command.Cli, offline bool) (loader.ResourceLoader, error) {
50-
cache, err := cacheDir()
51-
if err != nil {
52-
return nil, fmt.Errorf("initializing remote resource cache: %w", err)
53-
}
54-
49+
func NewOCIRemoteLoader(dockerCli command.Cli, offline bool) loader.ResourceLoader {
5550
return ociRemoteLoader{
56-
cache: cache,
5751
dockerCli: dockerCli,
5852
offline: offline,
59-
}, err
53+
}
6054
}
6155

6256
type ociRemoteLoader struct {
63-
cache string
6457
dockerCli command.Cli
6558
offline bool
6659
}
@@ -100,7 +93,12 @@ func (g ociRemoteLoader) Load(ctx context.Context, path string) (string, error)
10093
return "", err
10194
}
10295

103-
local := filepath.Join(g.cache, descriptor.Digest.Hex())
96+
cache, err := cacheDir()
97+
if err != nil {
98+
return "", fmt.Errorf("initializing remote resource cache: %w", err)
99+
}
100+
101+
local := filepath.Join(cache, descriptor.Digest.Hex())
104102
composeFile := filepath.Join(local, "compose.yaml")
105103
if _, err = os.Stat(local); os.IsNotExist(err) {
106104
var manifest v1.Manifest

0 commit comments

Comments
 (0)