@@ -30,6 +30,7 @@ import (
3030 "strings"
3131
3232 "github.com/compose-spec/compose-go/v2/consts"
33+ "github.com/compose-spec/compose-go/v2/errdefs"
3334 interp "github.com/compose-spec/compose-go/v2/interpolation"
3435 "github.com/compose-spec/compose-go/v2/override"
3536 "github.com/compose-spec/compose-go/v2/paths"
@@ -139,9 +140,9 @@ func (l localResourceLoader) abs(p string) string {
139140 return filepath .Join (l .WorkingDir , p )
140141}
141142
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
145146}
146147
147148func (l localResourceLoader ) Load (_ context.Context , p string ) (string , error ) {
@@ -301,9 +302,9 @@ func parseYAML(decoder *yaml.Decoder) (map[string]interface{}, PostProcessor, er
301302}
302303
303304// 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 ) {
305306 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 )
307308 }
308309
309310 opts := & Options {}
@@ -318,16 +319,16 @@ func LoadConfigFiles(ctx context.Context, configFiles []string, options ...func(
318319
319320 for i , p := range configFiles {
320321 for _ , loader := range opts .ResourceLoaders {
322+ _ , isLocalResourceLoader := loader .(localResourceLoader )
321323 if ! loader .Accept (p ) {
322324 continue
323325 }
324326 local , err := loader .Load (ctx , p )
325327 if err != nil {
326- continue
328+ return nil , err
327329 }
328- if config .WorkingDir == "" {
330+ if config .WorkingDir == "" && ! isLocalResourceLoader {
329331 config .WorkingDir = filepath .Dir (local )
330-
331332 }
332333 abs , err := filepath .Abs (local )
333334 if err != nil {
@@ -339,6 +340,9 @@ func LoadConfigFiles(ctx context.Context, configFiles []string, options ...func(
339340 break
340341 }
341342 }
343+ if config .WorkingDir == "" {
344+ config .WorkingDir = workingDir
345+ }
342346 return config , nil
343347}
344348
0 commit comments