@@ -30,6 +30,7 @@ import (
30
30
"strings"
31
31
32
32
"github.com/compose-spec/compose-go/v2/consts"
33
+ "github.com/compose-spec/compose-go/v2/errdefs"
33
34
interp "github.com/compose-spec/compose-go/v2/interpolation"
34
35
"github.com/compose-spec/compose-go/v2/override"
35
36
"github.com/compose-spec/compose-go/v2/paths"
@@ -139,9 +140,9 @@ func (l localResourceLoader) abs(p string) string {
139
140
return filepath .Join (l .WorkingDir , p )
140
141
}
141
142
142
- func (l localResourceLoader ) Accept (p string ) bool {
143
- _ , err := os . Stat ( l . abs ( p ))
144
- return err == nil
143
+ func (l localResourceLoader ) Accept (_ string ) bool {
144
+ // LocalResourceLoader is the last loader tested so it always should accept the config and try to get the content.
145
+ return true
145
146
}
146
147
147
148
func (l localResourceLoader ) Load (_ context.Context , p string ) (string , error ) {
@@ -301,9 +302,9 @@ func parseYAML(decoder *yaml.Decoder) (map[string]interface{}, PostProcessor, er
301
302
}
302
303
303
304
// LoadConfigFiles ingests config files with ResourceLoader and returns config details with paths to local copies
304
- func LoadConfigFiles (ctx context.Context , configFiles []string , options ... func (* Options )) (* types.ConfigDetails , error ) {
305
+ func LoadConfigFiles (ctx context.Context , configFiles []string , workingDir string , options ... func (* Options )) (* types.ConfigDetails , error ) {
305
306
if len (configFiles ) < 1 {
306
- return & types.ConfigDetails {}, errors . New ("no files specified" )
307
+ return & types.ConfigDetails {}, fmt . Errorf ("no configuration file provided: %w" , errdefs . ErrNotFound )
307
308
}
308
309
309
310
opts := & Options {}
@@ -318,16 +319,16 @@ func LoadConfigFiles(ctx context.Context, configFiles []string, options ...func(
318
319
319
320
for i , p := range configFiles {
320
321
for _ , loader := range opts .ResourceLoaders {
322
+ _ , isLocalResourceLoader := loader .(localResourceLoader )
321
323
if ! loader .Accept (p ) {
322
324
continue
323
325
}
324
326
local , err := loader .Load (ctx , p )
325
327
if err != nil {
326
- continue
328
+ return nil , err
327
329
}
328
- if config .WorkingDir == "" {
330
+ if config .WorkingDir == "" && ! isLocalResourceLoader {
329
331
config .WorkingDir = filepath .Dir (local )
330
-
331
332
}
332
333
abs , err := filepath .Abs (local )
333
334
if err != nil {
@@ -339,6 +340,9 @@ func LoadConfigFiles(ctx context.Context, configFiles []string, options ...func(
339
340
break
340
341
}
341
342
}
343
+ if config .WorkingDir == "" {
344
+ config .WorkingDir = workingDir
345
+ }
342
346
return config , nil
343
347
}
344
348
0 commit comments