fix(docker): fetch file content

resolves #3549
This commit is contained in:
Jan De Dobbeleer 2023-03-13 08:22:58 +01:00 committed by Jan De Dobbeleer
parent c03ee35107
commit 9f70320525
2 changed files with 8 additions and 2 deletions

View file

@ -416,6 +416,7 @@ func (env *Shell) HasFiles(pattern string) bool {
matches, err := fs.Glob(fileSystem, pattern)
if err != nil {
env.Error(err)
env.Debug("false")
return false
}
for _, match := range matches {
@ -423,8 +424,10 @@ func (env *Shell) HasFiles(pattern string) bool {
if err != nil || file.IsDir() {
continue
}
env.Debug("true")
return true
}
env.Debug("false")
return false
}
@ -434,6 +437,7 @@ func (env *Shell) HasFilesInDir(dir, pattern string) bool {
matches, err := fs.Glob(fileSystem, pattern)
if err != nil {
env.Error(err)
env.Debug("false")
return false
}
hasFilesInDir := len(matches) > 0

View file

@ -60,14 +60,16 @@ func (d *Docker) Enabled() bool {
// Check if there is a file named `$HOME/.docker/config.json` or `$DOCKER_CONFIG/config.json`
// Return the current context if it is not empty and not `default`
for _, f := range d.configFiles() {
if !d.env.HasFiles(f) {
data := d.env.FileContent(f)
if len(data) == 0 {
continue
}
data := d.env.FileContent(f)
var cfg DockerConfig
if err := json.Unmarshal([]byte(data), &cfg); err != nil {
continue
}
if len(cfg.CurrentContext) > 0 && cfg.CurrentContext != "default" {
d.Context = cfg.CurrentContext
return true